    Program f01mcfe

!     F01MCF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
