    PROGRAM f01rkfe

!      F01RKF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01rjf, f01rkf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, lda, ldph, m, n, nrowp
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), ph(:,:), theta(:), work(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          conjg
!      .. Executable Statements ..
       WRITE (nout,*) 'F01RKF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       lda = m
       ldph = n
       ALLOCATE (a(lda,n),ph(ldph,n),theta(n),work(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 f01rjf(m,n,a,lda,theta,ifail)

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

       ifail = 0
       CALL f01rkf('Separate',m,n,nrowp,ph,ldph,theta,work,ifail)

       WRITE (nout,*) 'Matrix  P'
       WRITE (nout,99999) (conjg(ph(1:nrowp,i)),i=1,n)

99999  FORMAT (5(' (',F6.3,',',F6.3,')':))
    END PROGRAM f01rkfe
