da_gaus_noise.inc
References to this file elsewhere.
1 real function da_gaus_noise(KDUM)
2
3 !---------------------------------------------------------------------
4 ! Purpose: return a normally(gaussian) distributed random variable ctions
5 ! with 0 mean and 1 standard deviation
6 !
7 ! method :
8 ! ------
9 !
10 ! input :
11 ! -----
12 ! argument
13 ! kdum : seed for random number generator
14 ! (set to a large negative number on entry)
15 ! common : none
16 !
17 ! output :
18 ! ------
19 ! argument
20 ! gauss_noise : gaussian random betwen
21 ! common : none
22 !
23 ! workspace : none
24 ! ---------
25 ! local :
26 !
27 ! external :
28 ! --------
29 ! unifva
30 !
31 ! reference :
32 ! ---------
33 ! numerical recipes in fortran. the art of scientific computing.
34 ! second edition. cambridge university press.
35 ! press et. al., 1986.
36 !
37 ! modifications:
38 ! --------------
39 ! original : 95-01(f. vandenberghe)
40 ! addition : 96-06(a. weaver)
41 !---------------------------------------------------------------------
42
43 implicit none
44
45 integer, intent(inout) :: kdum
46
47 integer :: niset
48 real :: gset
49 save niset,gset
50 data niset/0/
51
52 real zfac,zrsq,zv1,zv2
53
54 if (niset.eq.0) then
55
56 1000 continue
57 zv1 = 2.*da_unifva(kdum) - 1.
58 zv2 = 2.*da_unifva(kdum) - 1.
59 zrsq = zv1**2 + zv2**2
60
61 if ((zrsq.ge.1.).or.(zrsq.eq.0.)) goto 1000
62
63 zfac = sqrt(-2.*log(zrsq)/zrsq)
64 gset = zv1*zfac
65 da_gaus_noise = zv2*zfac
66 niset = 1
67 else
68 da_gaus_noise = gset
69 niset = 0
70 end if
71
72 return
73
74 end function da_gaus_noise
75
76