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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

  • Property svn:keywords set to Id
File size: 3.8 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-2019 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: random_function_mod.f90 4180 2019-08-21 14:37:54Z scharf $
27! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
28!
29! 3802 2019-03-17 13:33:42Z raasch
30! type conversion added to avoid compiler warning about constant integer
31! division truncation
32!
33! 3655 2019-01-07 16:51:22Z knoop
34! Corrected "Former revisions" section
35!
36!
37! Description:
38! ------------
39!> Random number generator, produces numbers equally distributed in interval [0,1]
40!> This routine is taken from the "numerical recipes"
41!------------------------------------------------------------------------------!
42 MODULE random_function_mod
43 
44
45    USE kinds
46
47    IMPLICIT NONE
48
49    PRIVATE
50
51    PUBLIC random_function, random_function_ini
52
53    INTEGER(iwp), PUBLIC, SAVE ::  random_iv(32)  !<
54    INTEGER(iwp), PUBLIC, SAVE ::  random_iy      !<
55
56    INTERFACE random_function_ini
57       MODULE PROCEDURE random_function_ini
58    END INTERFACE random_function_ini
59
60    INTERFACE random_function
61       MODULE PROCEDURE random_function
62    END INTERFACE random_function
63
64 CONTAINS
65
66!------------------------------------------------------------------------------!
67! Description:
68! ------------
69!> @todo Missing subroutine description.
70!------------------------------------------------------------------------------!
71    SUBROUTINE random_function_ini
72
73       IMPLICIT NONE
74
75       random_iv = 0
76       random_iy = 0
77
78    END SUBROUTINE random_function_ini
79
80    FUNCTION random_function( idum )
81
82
83       IMPLICIT NONE
84
85       INTEGER(iwp) ::  ia               !<
86       INTEGER(iwp) ::  idum             !<
87       INTEGER(iwp) ::  im               !<
88       INTEGER(iwp) ::  iq               !<
89       INTEGER(iwp) ::  ir               !<
90       INTEGER(iwp) ::  ndiv             !<
91       INTEGER(iwp) ::  ntab             !<
92
93       INTEGER(iwp) ::  j                !<
94       INTEGER(iwp) ::  k                !<
95
96       REAL(wp)     ::  am               !<
97       REAL(wp)     ::  eps              !<
98       REAL(wp)     ::  random_function  !<
99       REAL(wp)     ::  rnmx             !<
100
101       PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836, &
102                   ntab=32, ndiv=1+INT(REAL(im-1)/ntab), eps=1.2e-7_wp, rnmx=1.0_wp-eps )
103
104       IF ( idum <= 0  .OR.  random_iy == 0 )  THEN
105          idum = max (-idum,1)
106          DO  j = ntab+8,1,-1
107             k    = idum / iq
108             idum = ia * ( idum - k * iq ) - ir * k
109             IF ( idum < 0 )  idum = idum + im
110             IF ( j <= ntab )  random_iv(j) = idum
111          ENDDO
112          random_iy = random_iv(1)
113       ENDIF
114
115       k    = idum / iq
116       idum = ia * ( idum - k * iq ) - ir * k
117       IF ( idum < 0 )  idum = idum + im
118       j            = 1 + random_iy / ndiv
119       random_iy    = random_iv(j)
120       random_iv(j) = idum
121       random_function  = MIN( am * random_iy , rnmx )
122
123    END FUNCTION random_function
124
125 END MODULE random_function_mod
Note: See TracBrowser for help on using the repository browser.