Program g05tffe
! G05TFF Example Program Text
! Mark 30.3 Release. nAG Copyright 2024.
! .. Use Statements ..
Use nag_library, Only: g05kff, g05tff, nag_wp, x02amf
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: lseed = 1, maxlr = 5000, nin = 5, &
nout = 6
! .. Local Scalars ..
Real (Kind=nag_wp) :: a
Integer :: genid, ifail, lr, lstate, mode, n, &
subid
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: r(:)
Integer :: seed(lseed)
Integer, Allocatable :: state(:), x(:)
! .. Intrinsic Procedures ..
Intrinsic :: int
! .. Executable Statements ..
Write (nout,*) 'G05TFF Example Program Results'
Write (nout,*)
! Skip heading in data file
Read (nin,*)
! Read in the base generator information and seed
Read (nin,*) genid, subid, seed(1)
! Initial call to initializer to get size of STATE array
lstate = 0
Allocate (state(lstate))
ifail = 0
Call g05kff(genid,subid,seed,lseed,state,lstate,ifail)
! Reallocate STATE
Deallocate (state)
Allocate (state(lstate))
! Initialize the generator to a repeatable sequence
ifail = 0
Call g05kff(genid,subid,seed,lseed,state,lstate,ifail)
! Read in sample size
Read (nin,*) n
! Read in the distribution parameters
Read (nin,*) a
! Use suggested value for LR
If (1.0E0_nag_wp-a<x02amf()) Then
! A is too close to 1.0 to calculate LR, so
! set to MAXLR, which means we will use MODE = 3
lr = maxlr
Else
lr = int(1.8E1_nag_wp+4.0E1_nag_wp/(1.0E0_nag_wp-a))
End If
lr = maxlr
! If R is a reasonable size use MODE = 2
! else do not reference R and use MODE = 3
If (lr<maxlr) Then
mode = 2
Else
mode = 3
lr = 0
End If
Allocate (x(n),r(lr))
! Generate the variates
ifail = 0
Call g05tff(mode,n,a,r,lr,state,x,ifail)
! Display the variates
Write (nout,99999) x(1:n)
99999 Format (1X,I12)
End Program g05tffe