    PROGRAM f01rjfe

!      F01RJF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

       WRITE (nout,*) 'RQ factorization of A'
       WRITE (nout,*)
       WRITE (nout,*) 'Vector THETA'
       WRITE (nout,99999) theta(1:m)
       WRITE (nout,*)
       FLUSH (nout)

       CALL x04dbf('G',' ',m,n,a,lda,'B','F6.3', &
          'Matrix A after factorization (R is in left-hand upper triangle)', &
          'N',dummy,'N',dummy,132,0,ifail)

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