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

Last change on this file since 4507 was 4360, checked in by suehring, 5 years ago

Bugfix in output of time-averaged plant-canopy quanities; Output of plant-canopy data only where tall canopy is defined; land-surface model: fix wrong location strings; tests: update urban test case; all source code files: copyright update

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