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

NAG FL Interface Introduction
Example description
    Program g05ryfe

!     G05RYF Example Program Text

!     Mark 29.3 Release. NAG Copyright 2023.

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

!     Read in degrees of freedom
      Read (nin,*) df

!     Read in vector of means
      Read (nin,*) xmu(1:m)

!     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 G05RYF, so set up reference vector
!     and generate values in one go
      mode = 2

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

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

    End Program g05ryfe