source: palm/trunk/SOURCE/random_function.f90 @ 1818

Last change on this file since 1818 was 1818, checked in by maronga, 5 years ago

last commit documented / copyright update

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1!> @file random_function.f90
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: random_function.f90 1818 2016-04-06 15:53:27Z maronga $
26!
27! 1682 2015-10-07 23:56:08Z knoop
28! Code annotations made doxygen readable
29!
30! 1342 2014-03-26 17:04:47Z kanani
31! REAL constants defined as wp-kind
32!
33! 1320 2014-03-20 08:40:49Z raasch
34! ONLY-attribute added to USE-statements,
35! kind-parameters added to all INTEGER and REAL declaration statements,
36! kinds are defined in new module kinds,
37! old module precision_kind is removed,
38! revision history before 2012 removed,
39! comment fields (!:) to be used for variable explanations added to
40! all variable declaration statements
41!
42! 1092 2013-02-02 11:24:22Z raasch
43! unused variables removed
44!
45! 1036 2012-10-22 13:43:42Z raasch
46! code put under GPL (PALM 3.9)
47!
48! RCS Log replace by Id keyword, revision history cleaned up
49!
50! Revision 1.1  1998/02/04 16:09:45  raasch
51! Initial revision
52!
53!
54! Description:
55! ------------
56!> Random number generator, produces numbers equally distributed in interval [0,1]
57!> This routine is taken from the "numerical recipies"
58!------------------------------------------------------------------------------!
59 MODULE random_function_mod
60 
61
62    USE kinds
63
64    IMPLICIT NONE
65
66    PRIVATE
67
68    PUBLIC random_function, random_function_ini
69
70    INTEGER(iwp), PUBLIC, SAVE ::  random_iv(32)  !<
71    INTEGER(iwp), PUBLIC, SAVE ::  random_iy      !<
72
73    INTERFACE random_function_ini
74       MODULE PROCEDURE random_function_ini
75    END INTERFACE random_function_ini
76
77    INTERFACE random_function
78       MODULE PROCEDURE random_function
79    END INTERFACE random_function
80
81 CONTAINS
82
83!------------------------------------------------------------------------------!
84! Description:
85! ------------
86!> @todo Missing subroutine description.
87!------------------------------------------------------------------------------!
88    SUBROUTINE random_function_ini
89
90       IMPLICIT NONE
91
92       random_iv = 0
93       random_iy = 0
94
95    END SUBROUTINE random_function_ini
96
97    FUNCTION random_function( idum )
98
99
100       IMPLICIT NONE
101
102       INTEGER(iwp) ::  ia               !<
103       INTEGER(iwp) ::  idum             !<
104       INTEGER(iwp) ::  im               !<
105       INTEGER(iwp) ::  iq               !<
106       INTEGER(iwp) ::  ir               !<
107       INTEGER(iwp) ::  ndiv             !<
108       INTEGER(iwp) ::  ntab             !<
109
110       INTEGER(iwp) ::  j                !<
111       INTEGER(iwp) ::  k                !<
112
113       REAL(wp)     ::  am               !<
114       REAL(wp)     ::  eps              !<
115       REAL(wp)     ::  random_function  !<
116       REAL(wp)     ::  rnmx             !<
117
118       PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836, &
119                   ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7_wp, rnmx=1.0_wp-eps )
120
121       IF ( idum .le. 0  .or.  random_iy .eq. 0 )  THEN
122          idum = max (-idum,1)
123          DO  j = ntab+8,1,-1
124             k    = idum / iq
125             idum = ia * ( idum - k * iq ) - ir * k
126             IF ( idum .lt. 0 )  idum = idum + im
127             IF ( j .le. ntab )  random_iv(j) = idum
128          ENDDO
129          random_iy = random_iv(1)
130       ENDIF
131
132       k    = idum / iq
133       idum = ia * ( idum - k * iq ) - ir * k
134       IF ( idum .lt. 0 )  idum = idum + im
135       j            = 1 + random_iy / ndiv
136       random_iy    = random_iv(j)
137       random_iv(j) = idum
138       random_function  = min ( am * random_iy , rnmx )
139
140    END FUNCTION random_function
141
142 END MODULE random_function_mod
Note: See TracBrowser for help on using the repository browser.