32 INTEGER,
PARAMETER :: n_int = 4
33 INTEGER,
PARAMETER :: multiplier = 1
34 INTEGER,
PARAMETER :: array_size = multiplier*n_int
35 INTEGER,
PARAMETER :: array_size_m1 = array_size - 1
36 INTEGER,
PARAMETER :: n_gen = array_size
37 INTEGER,
PARAMETER :: n_gen_m1 = n_gen - 1
39 INTEGER,
PARAMETER :: dp=selected_real_kind( 12, 60 )
40 REAL(DP),
PARAMETER :: m1=2147483648.0_dp, m2=2147483648.0_dp, &
42 REAL(DP) :: dn=3.442619855899_dp, tn=3.442619855899_dp, &
43 vn=0.00991256303526217_dp, &
44 q, de=7.697117470131487_dp, &
45 te=7.697117470131487_dp, &
46 ve=0.003949659822581572_dp
47 INTEGER,
SAVE :: iz, jz, kn(0:127), &
49 REAL(DP),
SAVE :: wn(0:127), fn(0:127), we(0:255), fe(0:255)
50 LOGICAL,
SAVE :: initialized=.false.
52 INTEGER,
DIMENSION(0:ARRAY_SIZE_M1),
SAVE :: jz_vec, jsr_vec
53 INTEGER,
DIMENSION(0:ARRAY_SIZE_M1),
SAVE :: rand_ints
56 INTEGER,
SAVE :: index_shr3 = 0
66 INTEGER,
INTENT(IN) :: jsrseed
73 jsr_vec(i) = 1 + i + n_gen*jsrseed
77 q = vn*exp(half*dn*dn)
83 fn(127) = exp( -half*dn*dn )
85 dn = sqrt( -2.0_dp * log( vn/dn + exp( -half*dn*dn ) ) )
88 fn(i) = exp(-half*dn*dn)
101 de = -log( ve/de + exp( -de ) )
102 ke(i+1) = m2 * (de/te)
114 FUNCTION shr3_vec( ) RESULT( ival_vec )
115 INTEGER,
DIMENSION(0:ARRAY_SIZE_M1) :: ival_vec
118 IF( .NOT. initialized ) stop
'ERROR: shr3_vec has not been initialised (call zigset).'
121 jz_vec(i) = jsr_vec(i)
122 jsr_vec(i) = ieor( jsr_vec(i), ishft( jsr_vec(i), 13 ) )
123 jsr_vec(i) = ieor( jsr_vec(i), ishft( jsr_vec(i), -17 ) )
124 jsr_vec(i) = ieor( jsr_vec(i), ishft( jsr_vec(i), 5 ) )
125 ival_vec(i) = jz_vec(i) + jsr_vec(i)
128 END FUNCTION shr3_vec
133 FUNCTION shr3( ) RESULT( ival )
136 IF (index_shr3 == 0)
THEN
137 rand_ints = shr3_vec()
140 ival = rand_ints( index_shr3 )
142 index_shr3 = index_shr3 + 1
143 index_shr3 = iand( index_shr3, n_gen_m1 )
151 FUNCTION uni( ) RESULT( fn_val )
154 fn_val = half + 0.2328306e-9_dp *
shr3( )
161 FUNCTION rnor( ) RESULT( fn_val )
164 REAL(DP),
PARAMETER :: r = 3.442620_DP
169 IF( abs( hz ) < kn(iz) )
THEN
175 x = -0.2904764_dp* log(
uni( ) )
177 IF( y+y >= x*x )
EXIT
180 IF( hz <= 0 ) fn_val = -fn_val
184 IF( fn(iz) +
uni( )*(fn(iz-1)-fn(iz)) < exp(-half*x*x) )
THEN
190 IF( abs( hz ) < kn(iz) )
THEN
202 FUNCTION rexp( ) RESULT( fn_val )
209 IF( abs( jz ) < ke(iz) )
THEN
210 fn_val = abs(jz) * we(iz)
215 fn_val = 7.69711 - log(
uni( ) )
218 x = abs( jz ) * we(iz)
219 IF( fe(iz) +
uni( )*(fe(iz-1) - fe(iz)) < exp( -x ) )
THEN
225 IF( abs( jz ) < ke(iz) )
THEN
226 fn_val = abs( jz ) * we(iz)
integer function, public shr3()
real(dp) function, public uni()
real(dp) function, public rexp()
subroutine, public zigset(jsrseed)
real(dp) function, public rnor()
subroutine q(nrhs, x, Qx)
subroutine to take a full state vector x and return Qx in state space.