*     F11MFF Example Program Text
*     Mark 21 Release. NAG Copyright 2004.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          LA, NMAX, MMAX
      PARAMETER        (LA=10000,NMAX=1000,MMAX=10)
      DOUBLE PRECISION ONE
      PARAMETER        (ONE=1.D0)
*     .. Local Scalars ..
      DOUBLE PRECISION FLOP, THRESH
      INTEGER          I, IFAIL, J, N, NNZ, NNZL, NNZU, NRHS, NZLMX,
     +                 NZLUMX, NZUMX
      CHARACTER        SPEC, TRANS
*     .. Local Arrays ..
      DOUBLE PRECISION A(LA), LVAL(8*LA), UVAL(8*LA), X(NMAX,MMAX)
      INTEGER          ICOLZP(NMAX+1), IL(7*NMAX+8*LA+4), IPRM(7*NMAX),
     +                 IROWIX(LA), IU(2*NMAX+8*LA+1)
*     .. External Subroutines ..
      EXTERNAL         F11MDF, F11MEF, F11MFF, X04CAF
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F11MFF Example Program Results'
*     Skip heading in data file
      READ (NIN,*)
*
*     Read order of matrix and number of right hand sides
*
      READ (NIN,*) N, NRHS
      IF (N.LE.NMAX .AND. NRHS.LE.MMAX) THEN
*
*        Read the matrix A
*
         DO 20 I = 1, N + 1
            READ (NIN,*) ICOLZP(I)
   20    CONTINUE

         NNZ = ICOLZP(N+1) - 1
         DO 40 I = 1, NNZ
            READ (NIN,*) A(I), IROWIX(I)
   40    CONTINUE
*
*        Read the right hand sides
*
         DO 60 J = 1, NRHS
            READ (NIN,*) (X(I,J),I=1,N)
   60    CONTINUE

*
*        Calculate COLAMD permutation
*
         SPEC = 'M'
         IFAIL = 0
         CALL F11MDF(SPEC,N,ICOLZP,IROWIX,IPRM,IFAIL)
*
*        Factorise
*
         THRESH = ONE
         IFAIL = 0
         NZLMX = 8*NNZ
         NZLUMX = 8*NNZ
         NZUMX = 8*NNZ
         CALL F11MEF(N,IROWIX,A,IPRM,THRESH,NZLMX,NZLUMX,NZUMX,IL,
     +               LVAL,IU,UVAL,NNZL,NNZU,FLOP,IFAIL)
*
*        Solve
*
         TRANS = 'N'
         IFAIL = 0
         CALL F11MFF(TRANS,N,IPRM,IL,LVAL,IU,UVAL,NRHS,X,NMAX,IFAIL)
*
*        Output results
*
         WRITE (NOUT,*)
         CALL X04CAF('G',' ',N,NRHS,X,NMAX,'Solutions',IFAIL)
*
      END IF
      END
