Program g05sgfe
! G05SGF Example Program Text
! Mark 27.0 Release. NAG Copyright 2019.
! .. Use Statements ..
Use nag_library, Only: g05kff, g05sgf, nag_wp
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: lseed = 1, nin = 5, nout = 6
! .. Local Scalars ..
Integer :: genid, ifail, lstate, n, nmix, subid
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: a(:), wgt(:), x(:)
Integer :: seed(lseed)
Integer, Allocatable :: state(:)
! .. Executable Statements ..
Write (nout,*) 'G05SGF 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 and number of mixtures
Read (nin,*) n, nmix
Allocate (x(n),a(nmix),wgt(nmix))
! Read in the distribution parameters
Read (nin,*) a(1:nmix)
Read (nin,*) wgt(1:nmix)
! Generate the variates
ifail = 0
Call g05sgf(n,nmix,a,wgt,state,x,ifail)
! Display the variates
Write (nout,99999) x(1:n)
99999 Format (1X,F10.4)
End Program g05sgfe