source: palm/trunk/SOURCE/random_gauss.f90 @ 2000

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1!> @file random_gauss.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
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.
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!
17! Copyright 1997-2016 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! Forced header and separation lines into 80 columns
23!
24! Former revisions:
25! -----------------
26! $Id: random_gauss.f90 2000 2016-08-20 18:09:15Z knoop $
27!
28! 1682 2015-10-07 23:56:08Z knoop
29! Code annotations made doxygen readable
30!
31! 1342 2014-03-26 17:04:47Z kanani
32! REAL constants defined as wp-kind
33!
34! 1320 2014-03-20 08:40:49Z raasch
35! ONLY-attribute added to USE-statements,
36! kind-parameters added to all INTEGER and REAL declaration statements,
37! kinds are defined in new module kinds,
38! old module precision_kind is removed,
39! revision history before 2012 removed,
40! comment fields (!:) to be used for variable explanations added to
41! all variable declaration statements
42!
43! 1036 2012-10-22 13:43:42Z raasch
44! code put under GPL (PALM 3.9)
45!
46! RCS Log replace by Id keyword, revision history cleaned up
47!
48! Revision 1.1  1998/03/25 20:09:47  raasch
49! Initial revision
50!
51!
52! Description:
53! ------------
54!> Generates a gaussian distributed random number (mean value 1, sigma = 1)
55!> This routine is taken from the "numerical recipies".
56!------------------------------------------------------------------------------!
57 FUNCTION random_gauss( idum, upper_limit )
58 
59
60    USE kinds
61
62    USE random_function_mod,                                                   &
63        ONLY:  random_function
64
65    IMPLICIT NONE
66
67    INTEGER(iwp) ::  idum          !<
68    INTEGER(iwp) ::  iset          !<
69
70    REAL(wp)     ::  fac           !<
71    REAL(wp)     ::  gset          !<
72    REAL(wp)     ::  random_gauss  !<
73    REAL(wp)     ::  rsq           !<
74    REAL(wp)     ::  upper_limit   !<
75    REAL(wp)     ::  v1            !<
76    REAL(wp)     ::  v2            !<
77
78    SAVE  iset, gset
79
80    DATA  iset /0/
81
82!
83!-- Random numbers are created as long as they do not fall below the given
84!-- upper limit
85    DO
86
87       IF ( iset == 0 )  THEN
88          rsq = 0.0_wp
89          DO  WHILE ( rsq >= 1.0_wp  .OR.  rsq == 0.0_wp )
90             v1  = 2.0_wp * random_function( idum ) - 1.0_wp
91             v2  = 2.0_wp * random_function( idum ) - 1.0_wp
92             rsq = v1**2 + v2**2
93          ENDDO
94          fac          = SQRT( -2.0_wp * LOG( rsq ) / rsq )
95          gset         = v1 * fac
96          random_gauss = v2 * fac + 1.0_wp
97          iset         = 1
98       ELSE
99          random_gauss = gset + 1.0_wp
100          iset         = 0
101       ENDIF
102
103       IF ( ABS( random_gauss - 1.0_wp ) <= upper_limit )  EXIT
104
105    ENDDO
106
107 END FUNCTION random_gauss
Note: See TracBrowser for help on using the repository browser.