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

Last change on this file since 4130 was 3802, checked in by raasch, 6 years ago

unused variables removed, unused subroutines commented out, type conversion added to avoid compiler warning about constant integer division truncation, script document_changes made bash compatible

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