    PROGRAM f01blfe

!      F01BLF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01blf, f06raf, nag_wp, x02ajf, x04cbf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: indent = 0, ncols = 80, nin = 5,     &
                                          nout = 6
       CHARACTER (1), PARAMETER        :: diag =   'N',  matrix =   'G',       &
                                          nolabel =   'N'
       CHARACTER (8), PARAMETER        :: form = '1P,E12.4'
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: anorm, t
       INTEGER                         :: i, ifail, irank, lda, ldu, m, n
       CHARACTER (9)                   :: norm
       CHARACTER (27)                  :: title
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), aijmax(:), d(:), du(:), u(:,:)
       REAL (KIND=nag_wp)              :: work(1)
       INTEGER, ALLOCATABLE            :: inc(:)
       CHARACTER (1)                   :: dummy(1)
!      .. Intrinsic Functions ..
       INTRINSIC                          min
!      .. Executable Statements ..
       WRITE (nout,*) 'F01BLF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) m, n
       lda = m
       ldu = n
       ALLOCATE (a(lda,n),aijmax(n),d(m),du(n),u(ldu,n),inc(n))
       READ (nin,*) (a(i,1:n),i=1,m)
!      Set t = eps times norm of A.
       norm = 'Frobenius'
       anorm = f06raf(norm,m,n,a,lda,work)
       t = anorm*x02ajf()

!      ifail: behaviour on error exit   
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01blf(m,n,t,a,lda,aijmax,irank,inc,d,u,ldu,du,ifail)

       WRITE (nout,*) 'Maximum element in A(K) for I.GE.K and J.GE.K'
       WRITE (nout,*)
       WRITE (nout,*) '   K    Modulus'
       WRITE (nout,99999) (i,aijmax(i),i=1,min(n,irank+1))
       WRITE (nout,*)
       WRITE (nout,99998) 'Rank = ', irank
       WRITE (nout,*)
       WRITE (nout,99997) 'T = ', t, '  (machine dependent)'
       WRITE (nout,*)
       FLUSH (nout)
!      Print the result matrix A.
       title = 'Transpose of pseudo-inverse'
       ifail = 0
       CALL x04cbf(matrix,diag,m,n,a,lda,form,title,nolabel,dummy,nolabel, &
          dummy,ncols,indent,ifail)

99999  FORMAT (1X,I4,2X,1P,E12.4)
99998  FORMAT (1X,A,I5)
99997  FORMAT (1X,A,1P,E11.4,A)
    END PROGRAM f01blfe
