    PROGRAM f04jgfe

!      F04JGF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f04jgf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: sigma, tol
       INTEGER                         :: i, ifail, irank, lda, lwork, m, n
       LOGICAL                         :: svd
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:), work(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F04JGF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       tol = 5.0E-4_nag_wp
       lda = m
       lwork = 4*n
       ALLOCATE (a(lda,n),b(m),work(lwork))
       READ (nin,*) (a(i,1:n),i=1,m)
       READ (nin,*) b(1:m)

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f04jgf(m,n,a,lda,b,tol,svd,sigma,irank,work,lwork,ifail)

       WRITE (nout,*) 'Solution vector'
       WRITE (nout,99997) b(1:n)
       WRITE (nout,*)
       WRITE (nout,99999) 'Standard error = ', sigma, '    Rank = ', irank
       WRITE (nout,*)
       WRITE (nout,99998) 'SVD = ', svd

99999  FORMAT (1X,A,F6.3,A,I2)
99998  FORMAT (1X,A,L2)
99997  FORMAT (1X,8F9.3)
    END PROGRAM f04jgfe
