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
RevLine 
[1850]1!> @file random_function_mod.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]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!
[3655]17! Copyright 1997-2019 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 4180 2019-08-21 14:37:54Z scharf $
[4144]27! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
28!
29! 3802 2019-03-17 13:33:42Z raasch
[3802]30! type conversion added to avoid compiler warning about constant integer
31! division truncation
32!
33! 3655 2019-01-07 16:51:22Z knoop
[2716]34! Corrected "Former revisions" section
35!
[1321]36!
[1]37! Description:
38! ------------
[1682]39!> Random number generator, produces numbers equally distributed in interval [0,1]
[4144]40!> This routine is taken from the "numerical recipes"
[3]41!------------------------------------------------------------------------------!
[1682]42 MODULE random_function_mod
43 
[1]44
[1320]45    USE kinds
46
[1]47    IMPLICIT NONE
48
49    PRIVATE
50
51    PUBLIC random_function, random_function_ini
52
[1682]53    INTEGER(iwp), PUBLIC, SAVE ::  random_iv(32)  !<
54    INTEGER(iwp), PUBLIC, SAVE ::  random_iy      !<
[1]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
[1682]66!------------------------------------------------------------------------------!
67! Description:
68! ------------
69!> @todo Missing subroutine description.
70!------------------------------------------------------------------------------!
[1]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
[1682]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             !<
[1]92
[1682]93       INTEGER(iwp) ::  j                !<
94       INTEGER(iwp) ::  k                !<
[1320]95
[1682]96       REAL(wp)     ::  am               !<
97       REAL(wp)     ::  eps              !<
98       REAL(wp)     ::  random_function  !<
99       REAL(wp)     ::  rnmx             !<
[1320]100
[1342]101       PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836, &
[3802]102                   ntab=32, ndiv=1+INT(REAL(im-1)/ntab), eps=1.2e-7_wp, rnmx=1.0_wp-eps )
[1]103
[4144]104       IF ( idum <= 0  .OR.  random_iy == 0 )  THEN
[1]105          idum = max (-idum,1)
106          DO  j = ntab+8,1,-1
107             k    = idum / iq
108             idum = ia * ( idum - k * iq ) - ir * k
[4144]109             IF ( idum < 0 )  idum = idum + im
110             IF ( j <= ntab )  random_iv(j) = idum
[1]111          ENDDO
112          random_iy = random_iv(1)
113       ENDIF
114
115       k    = idum / iq
116       idum = ia * ( idum - k * iq ) - ir * k
[4144]117       IF ( idum < 0 )  idum = idum + im
[1]118       j            = 1 + random_iy / ndiv
119       random_iy    = random_iv(j)
120       random_iv(j) = idum
[4144]121       random_function  = MIN( am * random_iy , rnmx )
[1]122
123    END FUNCTION random_function
124
125 END MODULE random_function_mod
Note: See TracBrowser for help on using the repository browser.