    PROGRAM g05kjfe

!      G05KJF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kff, g05kjf, g05saf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: lseed = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: genid, ifail, lstate, n, nv, subid
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: x(:)
       INTEGER                         :: seed(lseed)
       INTEGER, ALLOCATABLE            :: state(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05KJF 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)

!      Query G05KFF to get the require length 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 the skip ahead and sample size
       READ (nin,*) n, nv

       ALLOCATE (x(nv))

!      Advance the sequence N places
       ifail = 0
       CALL g05kjf(n,state,ifail)

!      Generate a NV variates from a uniform distribution
       ifail = 0
       CALL g05saf(nv,state,x,ifail)

!      Display the variates
       WRITE (nout,99999) x(1:nv)

99999  FORMAT (1X,F10.4)
    END PROGRAM g05kjfe
