    PROGRAM f01bsfe

!      F01BSF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01brf, f01bsf, nag_wp, x04abf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: iset = 1, nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: eta, rpmin, u
       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(:),          &
                                          ivect(:), iw(:,:), jvect(:)
       INTEGER                         :: idisp(10)
       LOGICAL                         :: abort(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'F01BSF 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),ivect(nz), &
          iw(n,8),jvect(nz))
       CALL x04abf(iset,outchn)
       WRITE (nout,*)
       READ (nin,*) (a(i),irn(i),icn(i),i=1,nz)
       u = 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,u,ikeep,iw,w,lblock,grow,abort, &
          idisp,ifail)

       IF (grow) THEN
          WRITE (nout,*) 'On exit from F01BRF'
          WRITE (nout,99999) 'Value of W(1)  = ', w(1)
       END IF
       READ (nin,*) (a(i),ivect(i),jvect(i),i=1,nz)
       eta = 0.1E0_nag_wp

       ifail = 0
       CALL f01bsf(n,nz,a,licn,ivect,jvect,icn,ikeep,iw,w,grow,eta,rpmin, &
          abort(4),idisp,ifail)

       IF (grow) THEN
          WRITE (nout,*)
          WRITE (nout,*) 'On exit from F01BSF'
          WRITE (nout,99999) 'Value of W(1)  = ', w(1)
       END IF
       IF (eta<1.0E0_nag_wp) THEN
          WRITE (nout,*)
          WRITE (nout,99999) 'Value of RPMIN = ', rpmin
       END IF

99999  FORMAT (1X,A,F7.4)
    END PROGRAM f01bsfe
