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

Last change on this file since 3424 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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