    PROGRAM f01qkfe

!      F01QKF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01qjf, f01qkf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, lda, ldpt, m, n, nrowp
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), pt(:,:), work(:), zeta(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F01QKF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       lda = m
       ldpt = n
       ALLOCATE (a(lda,n),pt(ldpt,n),work(n),zeta(n))
       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 f01qjf(m,n,a,lda,zeta,ifail)

!      Copy array A into PT and form the n by n matrix conjg(P')
       pt(1:m,1:n) = a(1:m,1:n)
       nrowp = n

       ifail = 0
       CALL f01qkf('Separate',m,n,nrowp,pt,ldpt,zeta,work,ifail)

       WRITE (nout,*) 'Matrix  P'
       WRITE (nout,99999) pt(1:nrowp,1:n)


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