    PROGRAM g05pxfe

!      G05PXF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kff, g05pxf, nag_wp, x04caf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: lseed = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: genid, i, ifail, lda, lstate, m, n,  &
                                          subid
       CHARACTER (1)                   :: init, side
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:)
       INTEGER                         :: seed(lseed)
       INTEGER, ALLOCATABLE            :: state(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05PXF 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 initialiser 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 the problem size
       READ (nin,*) n, m

!      Read in control parameters
       READ (nin,*) side, init

       lda = m
       ALLOCATE (a(lda,n))

!      Read in A if required
       IF (init=='N' .OR. init=='n') THEN
          READ (nin,*) (a(i,1:n),i=1,m)
       END IF

!      Generate the random orthogonal matrix
       ifail = 0
       CALL g05pxf(side,init,m,n,state,a,lda,ifail)

!      Display the results
       ifail = 0
       CALL x04caf('General',' ',m,n,a,lda,'Random Matrix',ifail)

    END PROGRAM g05pxfe
