    PROGRAM f01brfe

!      F01BRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01brf, nag_wp, x04abf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: iset = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: pivot
       INTEGER                         :: i, ifail, licn, lirn, n, nz, outchn
       LOGICAL                         :: grow, lblock
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:), w(:)
       INTEGER, ALLOCATABLE            :: icn(:), ikeep(:,:), irn(:), iw(:,:)
       INTEGER                         :: idisp(10)
       LOGICAL                         :: abort(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'F01BRF Example Program Results'
       outchn = nout
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, nz
       licn = 3*nz
       lirn = 3*nz/2
       ALLOCATE (a(licn),w(n),icn(licn),ikeep(n,5),irn(lirn),iw(n,8))
       CALL x04abf(iset,outchn)
       READ (nin,*) (a(i),irn(i),icn(i),i=1,nz)
       pivot = 0.1E0_nag_wp
       lblock = .TRUE.
       grow = .TRUE.
       abort(1) = .TRUE.
       abort(2) = .TRUE.
       abort(3) = .FALSE.
       abort(4) = .TRUE.

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01brf(n,nz,a,licn,irn,lirn,icn,pivot,ikeep,iw,w,lblock,grow, &
          abort,idisp,ifail)

       WRITE (nout,*)
       WRITE (nout,99999) 'Number of non-zeros in decomposition         =', &
          idisp(2)
       WRITE (nout,99999) 'Minimum size of array IRN                    =', &
          idisp(6)
       WRITE (nout,99999) 'Minimum size of arrays A and ICN             =', &
          idisp(7)
       WRITE (nout,99999) 'Number of compresses on IRN (IDISP(3))       =', &
          idisp(3)
       WRITE (nout,99999) 'Number of compresses on A and ICN (IDISP(4)) =', &
          idisp(4)
       IF (grow) THEN
          WRITE (nout,*)
          WRITE (nout,99998) 'Value of W(1) =', w(1)
       END IF
       IF (lblock) THEN
          WRITE (nout,*)
          WRITE (nout,99999) 'Structural rank                =', idisp(8)
          WRITE (nout,99999) 'Number of diagonal blocks      =', idisp(9)
          WRITE (nout,99999) 'Size of largest diagonal block =', idisp(10)
       END IF

99999  FORMAT (1X,A,I5,A,I5)
99998  FORMAT (1X,A,F8.4)
    END PROGRAM f01brfe
