source: palm/trunk/SOURCE/random_function.f90 @ 1682

Last change on this file since 1682 was 1682, checked in by knoop, 9 years ago

Code annotations made doxygen readable

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