    PROGRAM f01mcfe

!      F01MCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01mcf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, k1, k2, lal, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:), al(:), d(:)
       INTEGER, ALLOCATABLE            :: nrow(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F01MCF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       ALLOCATE (d(n),nrow(n))
       READ (nin,*) nrow(1:n)
       lal = 0
       DO i = 1, n
          lal = lal + nrow(i)
       END DO
       ALLOCATE (a(lal),al(lal))
       k2 = 0
       DO i = 1, n
          k1 = k2 + 1
          k2 = k2 + nrow(i)
          READ (nin,*) a(k1:k2)
       END DO

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01mcf(n,a,lal,nrow,al,d,ifail)

       WRITE (nout,*)
       WRITE (nout,*) '  I    D(I)   Row I of unit lower triangle'
       WRITE (nout,*)
       k2 = 0
       DO i = 1, n
          k1 = k2 + 1
          k2 = k2 + nrow(i)
          WRITE (nout,99999) i, d(i), al(k1:k2)
       END DO

99999  FORMAT (1X,I3,7F8.3)
    END PROGRAM f01mcfe
