NAG Library Manual, Mark 30.1
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program g05rdfe

!     G05RDF Example Program Text

!     Mark 30.1 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: g05kff, g05rdf, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: lseed = 1, nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: genid, i, ifail, ldc, ldx, lr,       &
                                          lstate, m, mode, n, subid
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: c(:,:), r(:), x(:,:)
      Integer                          :: seed(lseed)
      Integer, Allocatable             :: state(:)
!     .. Executable Statements ..
      Write (nout,*) 'G05RDF Example Program Results'
      Write (nout,*)
      Flush (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 dimensions
      Read (nin,*) n, m

      ldc = m
      ldx = n
      lr = m*(m+1) + 1
      Allocate (c(ldc,m),x(ldx,m),r(lr))

!     Read in upper triangle portion of the covariance matrix
      Do i = 1, m
        Read (nin,*) c(i,i:m)
      End Do

!     Using a single call to G05RDF, so set up reference vector
!     and generate values in one go
      mode = 2

!     Generate variates
      ifail = 0
      Call g05rdf(mode,n,m,c,ldc,r,lr,state,x,ldx,ifail)

!     Display variates
      ifail = 0
      Call x04caf('General',' ',n,m,x,ldx,'Variates',ifail)

    End Program g05rdfe