    Program f01rjfe

!     F01RJF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
