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

Last change on this file since 4176 was 4144, checked in by raasch, 5 years ago

relational operators .EQ., .NE., etc. replaced by ==, /=, etc.

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