Program f01rgfe

!     F01RGF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. Use Statements ..
      Use nag_library, Only: f01rgf, 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,*) 'F01RGF 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 f01rgf(m,n,a,lda,theta,ifail)

      Write (nout,*)
      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','F7.4', &
        'Matrix A after factorization (R is in left-hand upper triangle)','N', &
        dummy,'N',dummy,80,0,ifail)

99999 Format (1X,4(' (',F7.4,',',F8.4,')':))
    End Program f01rgfe