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

Last change on this file since 1850 was 1850, checked in by maronga, 6 years ago

added _mod string to several filenames to meet the naming convection for modules

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1!> @file random_function_mod.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-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21! Module renamed
22!
23!
24! Former revisions:
25! -----------------
26! $Id: random_function_mod.f90 1850 2016-04-08 13:29:27Z maronga $
27!
28! 1682 2015-10-07 23:56:08Z knoop
29! Code annotations made doxygen readable
30!
31! 1342 2014-03-26 17:04:47Z kanani
32! REAL constants defined as wp-kind
33!
34! 1320 2014-03-20 08:40:49Z raasch
35! ONLY-attribute added to USE-statements,
36! kind-parameters added to all INTEGER and REAL declaration statements,
37! kinds are defined in new module kinds,
38! old module precision_kind is removed,
39! revision history before 2012 removed,
40! comment fields (!:) to be used for variable explanations added to
41! all variable declaration statements
42!
43! 1092 2013-02-02 11:24:22Z raasch
44! unused variables removed
45!
46! 1036 2012-10-22 13:43:42Z raasch
47! code put under GPL (PALM 3.9)
48!
49! RCS Log replace by Id keyword, revision history cleaned up
50!
51! Revision 1.1  1998/02/04 16:09:45  raasch
52! Initial revision
53!
54!
55! Description:
56! ------------
57!> Random number generator, produces numbers equally distributed in interval [0,1]
58!> This routine is taken from the "numerical recipies"
59!------------------------------------------------------------------------------!
60 MODULE random_function_mod
61 
62
63    USE kinds
64
65    IMPLICIT NONE
66
67    PRIVATE
68
69    PUBLIC random_function, random_function_ini
70
71    INTEGER(iwp), PUBLIC, SAVE ::  random_iv(32)  !<
72    INTEGER(iwp), PUBLIC, SAVE ::  random_iy      !<
73
74    INTERFACE random_function_ini
75       MODULE PROCEDURE random_function_ini
76    END INTERFACE random_function_ini
77
78    INTERFACE random_function
79       MODULE PROCEDURE random_function
80    END INTERFACE random_function
81
82 CONTAINS
83
84!------------------------------------------------------------------------------!
85! Description:
86! ------------
87!> @todo Missing subroutine description.
88!------------------------------------------------------------------------------!
89    SUBROUTINE random_function_ini
90
91       IMPLICIT NONE
92
93       random_iv = 0
94       random_iy = 0
95
96    END SUBROUTINE random_function_ini
97
98    FUNCTION random_function( idum )
99
100
101       IMPLICIT NONE
102
103       INTEGER(iwp) ::  ia               !<
104       INTEGER(iwp) ::  idum             !<
105       INTEGER(iwp) ::  im               !<
106       INTEGER(iwp) ::  iq               !<
107       INTEGER(iwp) ::  ir               !<
108       INTEGER(iwp) ::  ndiv             !<
109       INTEGER(iwp) ::  ntab             !<
110
111       INTEGER(iwp) ::  j                !<
112       INTEGER(iwp) ::  k                !<
113
114       REAL(wp)     ::  am               !<
115       REAL(wp)     ::  eps              !<
116       REAL(wp)     ::  random_function  !<
117       REAL(wp)     ::  rnmx             !<
118
119       PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836, &
120                   ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7_wp, rnmx=1.0_wp-eps )
121
122       IF ( idum .le. 0  .or.  random_iy .eq. 0 )  THEN
123          idum = max (-idum,1)
124          DO  j = ntab+8,1,-1
125             k    = idum / iq
126             idum = ia * ( idum - k * iq ) - ir * k
127             IF ( idum .lt. 0 )  idum = idum + im
128             IF ( j .le. ntab )  random_iv(j) = idum
129          ENDDO
130          random_iy = random_iv(1)
131       ENDIF
132
133       k    = idum / iq
134       idum = ia * ( idum - k * iq ) - ir * k
135       IF ( idum .lt. 0 )  idum = idum + im
136       j            = 1 + random_iy / ndiv
137       random_iy    = random_iv(j)
138       random_iv(j) = idum
139       random_function  = min ( am * random_iy , rnmx )
140
141    END FUNCTION random_function
142
143 END MODULE random_function_mod
Note: See TracBrowser for help on using the repository browser.