    PROGRAM g05lzfe

!      G05LZF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kbf, g05lzf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: n = 2, nout = 6
       INTEGER, PARAMETER              :: nr = ((n+1)*(n+2))/2
       INTEGER, PARAMETER              :: ldc = n
!      .. Local Scalars ..
       INTEGER                         :: ifail, igen, mode
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: c(ldc,n), r(nr), x(n), xmu(n)
       INTEGER                         :: iseed(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05LZF Example Program Results'
       WRITE (nout,*)
!      Initialize the seed to a repeatable sequence
       iseed(1) = 1762543
       iseed(2) = 9324783
       iseed(3) = 42344
       iseed(4) = 742355
!      IGEN identifies the stream.
       igen = 1
       CALL g05kbf(igen,iseed)

       c(1,1) = 2.0E0_nag_wp
       c(2,1) = 1.0E0_nag_wp
       c(1,2) = 1.0E0_nag_wp
       c(2,2) = 3.0E0_nag_wp

       xmu(1) = 1.0E0_nag_wp
       xmu(2) = 2.0E0_nag_wp

       mode = 0
       ifail = 1

!      Set up reference vector and generate numbers
       CALL g05lzf(mode,n,xmu,c,ldc,x,igen,iseed,r,nr,ifail)

       IF (ifail==0) THEN
          WRITE (nout,99999) x

          mode = 2

!         Generate numbers
          ifail = 0
          CALL g05lzf(mode,n,xmu,c,ldc,x,igen,iseed,r,nr,ifail)
          WRITE (nout,99999) x
       ELSE
          WRITE (nout,99998) ifail
       END IF

99999  FORMAT (1X,F10.4)
99998  FORMAT (1X,' ** G05LZF returned with IFAIL = ',I5)
    END PROGRAM g05lzfe
