    PROGRAM f01qgfe

!      F01QGF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01qgf, nag_wp, x04cbf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: indent = 0, ncols = 80, nin = 5,     &
                                          nout = 6
       CHARACTER (1), PARAMETER        :: diag =   'N',  matrix =   'G',       &
                                          nolabel =   'N'
       CHARACTER (4), PARAMETER        :: form = 'F8.4'
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, lda, m, n
       CHARACTER (63)                  :: title
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), zeta(:)
       CHARACTER (1)                   :: dummy(1)
!      .. Executable Statements ..
       WRITE (nout,*) 'F01QGF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       lda = m
       ALLOCATE (a(lda,n),zeta(m))
       READ (nin,*) (a(i,1:n),i=1,m)

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
!      Find the RQ factorization of A
       CALL f01qgf(m,n,a,lda,zeta,ifail)

       WRITE (nout,*) 'RQ factorization of A'
       WRITE (nout,*)
       WRITE (nout,*) 'Vector ZETA'
       WRITE (nout,99999) zeta(1:m)
       WRITE (nout,*)
       FLUSH (nout)
       title = &
          'Matrix A after factorization (R is in left-hand upper triangle)'
       ifail = 0
       CALL x04cbf(matrix,diag,m,n,a,lda,form,title,nolabel,dummy,nolabel, &
          dummy,ncols,indent,ifail)

99999  FORMAT (5(1X,F8.4))
    END PROGRAM f01qgfe
