source: palm/trunk/SOURCE/random_function_mod.f90 @ 2550

Last change on this file since 2550 was 2101, checked in by suehring, 8 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 4.4 KB
RevLine 
[1850]1!> @file random_function_mod.f90
[2000]2!------------------------------------------------------------------------------!
[1036]3! This file is part of PALM.
4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2101]17! Copyright 1997-2017 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1]21! -----------------
[1343]22!
[2001]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: random_function_mod.f90 2101 2017-01-05 16:42:31Z boeske $
27!
[2001]28! 2000 2016-08-20 18:09:15Z knoop
29! Forced header and separation lines into 80 columns
30!
[1851]31! 1850 2016-04-08 13:29:27Z maronga
32! Module renamed
33!
34!
[1683]35! 1682 2015-10-07 23:56:08Z knoop
36! Code annotations made doxygen readable
37!
[1343]38! 1342 2014-03-26 17:04:47Z kanani
39! REAL constants defined as wp-kind
40!
[1321]41! 1320 2014-03-20 08:40:49Z raasch
[1320]42! ONLY-attribute added to USE-statements,
43! kind-parameters added to all INTEGER and REAL declaration statements,
44! kinds are defined in new module kinds,
45! old module precision_kind is removed,
46! revision history before 2012 removed,
47! comment fields (!:) to be used for variable explanations added to
48! all variable declaration statements
[1]49!
[1093]50! 1092 2013-02-02 11:24:22Z raasch
51! unused variables removed
52!
[1037]53! 1036 2012-10-22 13:43:42Z raasch
54! code put under GPL (PALM 3.9)
55!
[3]56! RCS Log replace by Id keyword, revision history cleaned up
57!
[1]58! Revision 1.1  1998/02/04 16:09:45  raasch
59! Initial revision
60!
61!
62! Description:
63! ------------
[1682]64!> Random number generator, produces numbers equally distributed in interval [0,1]
65!> This routine is taken from the "numerical recipies"
[3]66!------------------------------------------------------------------------------!
[1682]67 MODULE random_function_mod
68 
[1]69
[1320]70    USE kinds
71
[1]72    IMPLICIT NONE
73
74    PRIVATE
75
76    PUBLIC random_function, random_function_ini
77
[1682]78    INTEGER(iwp), PUBLIC, SAVE ::  random_iv(32)  !<
79    INTEGER(iwp), PUBLIC, SAVE ::  random_iy      !<
[1]80
81    INTERFACE random_function_ini
82       MODULE PROCEDURE random_function_ini
83    END INTERFACE random_function_ini
84
85    INTERFACE random_function
86       MODULE PROCEDURE random_function
87    END INTERFACE random_function
88
89 CONTAINS
90
[1682]91!------------------------------------------------------------------------------!
92! Description:
93! ------------
94!> @todo Missing subroutine description.
95!------------------------------------------------------------------------------!
[1]96    SUBROUTINE random_function_ini
97
98       IMPLICIT NONE
99
100       random_iv = 0
101       random_iy = 0
102
103    END SUBROUTINE random_function_ini
104
105    FUNCTION random_function( idum )
106
107
108       IMPLICIT NONE
109
[1682]110       INTEGER(iwp) ::  ia               !<
111       INTEGER(iwp) ::  idum             !<
112       INTEGER(iwp) ::  im               !<
113       INTEGER(iwp) ::  iq               !<
114       INTEGER(iwp) ::  ir               !<
115       INTEGER(iwp) ::  ndiv             !<
116       INTEGER(iwp) ::  ntab             !<
[1]117
[1682]118       INTEGER(iwp) ::  j                !<
119       INTEGER(iwp) ::  k                !<
[1320]120
[1682]121       REAL(wp)     ::  am               !<
122       REAL(wp)     ::  eps              !<
123       REAL(wp)     ::  random_function  !<
124       REAL(wp)     ::  rnmx             !<
[1320]125
[1342]126       PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836, &
127                   ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7_wp, rnmx=1.0_wp-eps )
[1]128
129       IF ( idum .le. 0  .or.  random_iy .eq. 0 )  THEN
130          idum = max (-idum,1)
131          DO  j = ntab+8,1,-1
132             k    = idum / iq
133             idum = ia * ( idum - k * iq ) - ir * k
134             IF ( idum .lt. 0 )  idum = idum + im
135             IF ( j .le. ntab )  random_iv(j) = idum
136          ENDDO
137          random_iy = random_iv(1)
138       ENDIF
139
140       k    = idum / iq
141       idum = ia * ( idum - k * iq ) - ir * k
142       IF ( idum .lt. 0 )  idum = idum + im
143       j            = 1 + random_iy / ndiv
144       random_iy    = random_iv(j)
145       random_iv(j) = idum
146       random_function  = min ( am * random_iy , rnmx )
147
148    END FUNCTION random_function
149
150 END MODULE random_function_mod
Note: See TracBrowser for help on using the repository browser.