73 INTEGER,
PARAMETER :: RAND_BUFFER_SIZE = 624
74 INTEGER,
PARAMETER :: RAND_MTI_INDEX = RAND_BUFFER_SIZE
75 INTEGER,
PARAMETER :: RAND_SEED_INDEX = RAND_BUFFER_SIZE + 1
76 INTEGER,
PARAMETER :: RAND_CALLS_INDEX = RAND_BUFFER_SIZE + 2
77 INTEGER,
PARAMETER :: RAND_EXTRA_INTS = 3
78 INTEGER,
PARAMETER :: RAND_TOTAL_SIZE = RAND_BUFFER_SIZE + RAND_EXTRA_INTS
81 INTEGER :: mt(0:RAND_TOTAL_SIZE-1)
95 INTEGER,
INTENT(IN) :: seed
102 INTEGER,
PARAMETER :: one = 1
103 INTEGER,
PARAMETER :: mult = 1812433253
107 mask32 = ishft(one,32) - one
109 rdata%mt(0) = iand(seed,mask32)
111 DO i=1,rand_buffer_size-1
117 rdata%mt(
i) = mult * (ieor(rdata%mt(
i-1), &
118 ishft(rdata%mt(
i-1),-30))) +
i
121 rdata%mt(
i) = iand(rdata%mt(
i),mask32)
125 rdata%mt(rand_mti_index) = rand_buffer_size
126 rdata%mt(rand_seed_index) = iand(seed,mask32)
127 rdata%mt(rand_calls_index) = 0
138 REAL(RFREAL),
INTENT(OUT) ::
a(:)
147 INTEGER,
PARAMETER :: one = 1
148 INTEGER,
PARAMETER ::
m = 397
149 INTEGER,
PARAMETER :: lmask = 2147483647
150 INTEGER,
PARAMETER :: pre_mata = -1727483681
151 INTEGER,
PARAMETER :: pre_tmaskb = -1658038656
152 INTEGER,
PARAMETER :: pre_tmaskc = -272236544
155 REAL(RFREAL),
PARAMETER :: two32 = 4294967296.0_rfreal
156 REAL(RFREAL),
PARAMETER :: nfac1 = 67108864.0_rfreal
159 INTEGER :: mask32, mata, umask, tmaskb, tmaskc, mag01(0:1)
160 REAL(RFREAL) :: nfac2
162 INTEGER ::
y,mti,iamin,iamax
163 REAL(RFREAL) :: yr(2)
167 umask = ishft(one,31)
168 mask32 = ishft(one,32) - one
169 mata = iand(pre_mata, mask32)
170 tmaskb = iand(pre_tmaskb,mask32)
171 tmaskc = iand(pre_tmaskc,mask32)
174 nfac2 = 1.0_rfreal/9007199254740992.0_rfreal
178 mti = rdata%mt(rand_mti_index)
187 IF (mti >= rand_buffer_size)
THEN
189 DO kk=0,rand_buffer_size-
m-1
190 y = ior(iand(rdata%mt(kk),umask),iand(rdata%mt(kk+1),lmask))
191 rdata%mt(kk) = ieor(ieor(rdata%mt(kk+
m),ishft(
y,-1)), &
195 DO kk=rand_buffer_size-
m,rand_buffer_size-2
196 y = ior(iand(rdata%mt(kk),umask),iand(rdata%mt(kk+1),lmask))
197 rdata%mt(kk) = ieor(ieor(rdata%mt(kk+(
m-rand_buffer_size)), &
198 ishft(
y,-1)), mag01(iand(
y,one)))
201 y = ior(iand(rdata%mt(rand_buffer_size-1),umask), &
202 iand(rdata%mt(0),lmask))
203 rdata%mt(rand_buffer_size-1) = &
204 ieor(ieor(rdata%mt(
m-1), ishft(
y,-1)), mag01(iand(
y,one)))
214 y = ieor(
y, ishft(
y,-11))
215 y = ieor(
y,iand(ishft(
y, 7),tmaskb))
216 y = ieor(
y,iand(ishft(
y, 15),tmaskc))
217 y = ieor(
y, ishft(
y,-18))
222 yr(
j) =
REAL(y,KIND=RFREAL) + two32
224 yr(
j) =
REAL(
y,kind=rfreal)
233 a(
i) = (yr(1)*nfac1 + yr(2)) * nfac2
237 rdata%mt(rand_mti_index) = mti
238 rdata%mt(rand_calls_index) = rdata%mt(rand_calls_index) + iamax - iamin + 1
250 REAL(RFREAL),
INTENT(OUT) ::
a(:)
251 REAL(RFREAL),
INTENT(IN) :: med,dev
254 INTEGER ::
i,iamin,iamax
256 REAL(RFREAL) :: twopi
260 twopi = 8.0_rfreal*atan(1.0_rfreal)
265 r = dev*
sqrt(-2.0_rfreal*log(1.0_rfreal-
a(
i+1)))
270 IF (modulo(iamax-iamin+1,2)==1)
THEN
273 r = dev*
sqrt(-2.0_rfreal*log(1.0_rfreal-
r))
274 a(iamax) =
r*
cos(th) + med
287 REAL(RFREAL),
INTENT(OUT) ::
a(:)
288 REAL(RFREAL),
INTENT(IN) :: logmed,gdev
302 REAL(RFREAL),
INTENT(IN) :: pdfvalues(:,:)
303 REAL(RFREAL),
INTENT(OUT) ::
a(:)
305 INTEGER,
INTENT(IN) :: locmax
306 REAL(RFREAL),
INTENT(IN) :: valmax
308 INTEGER ::
i,iamin,iamax,k1,k2
316 a(
i) = (
a(
i) - pdfvalues(k1,2))*(pdfvalues(k2,3)-pdfvalues(k1,3))&
317 /(pdfvalues(k2,2) - pdfvalues(k1,2)) + pdfvalues(k1,3)
324 REAL(RFREAL),
INTENT(IN) :: datum
325 REAL(RFREAL),
INTENT(IN) :: vec(:)
326 INTEGER,
INTENT(OUT) :: k1,k2
329 isgn =
sign(1.1_rfreal,datum-valmax)
332 do while (int(
sign(1.1_rfreal,datum-vec(k2)))*isgn > 0)
365 REAL(RFREAL),
INTENT(IN) :: med,dev
383 REAL(RFREAL),
INTENT(IN) :: logmed,gdev
402 REAL(RFREAL),
INTENT(IN) :: pdfvalues(:,:)
403 INTEGER,
INTENT(IN) :: locmax
404 REAL(RFREAL),
INTENT(IN) :: valmax
REAL(RFREAL) function rand1imposedpdf(rdata, pdfvalues, locMax, valmax)
subroutine randnormal(a, med, dev, rdata)
static SURF_BEGIN_NAMESPACE double sign(double x)
void int int REAL REAL * y
subroutine randomseed(seed, rdata)
REAL(RFREAL) function rand1uniform(rdata)
subroutine randlognormal(a, logmed, gdev, rdata)
subroutine randimposedpdf(a, pdfvalues, locMax, valmax, rdata)
subroutine findpdf(datum, vec, k1, k2)
subroutine randuniform(a, rdata)
REAL(RFREAL) function rand1normal(med, dev, rdata)
REAL(RFREAL) function rand1lognormal(logmed, gdev, rdata)