*     F11DAF Example Program Text
*     Mark 18 Release. NAG Copyright 1997.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NMAX, LA, LIWORK
      PARAMETER        (NMAX=1000,LA=10000,LIWORK=7*NMAX+2)
*     .. Local Scalars ..
      DOUBLE PRECISION DTOL
      INTEGER          I, IFAIL, LFILL, N, NNZ, NNZC, NPIVM
      CHARACTER        MILU, PSTRAT
*     .. Local Arrays ..
      DOUBLE PRECISION A(LA)
      INTEGER          ICOL(LA), IDIAG(NMAX), IPIVP(NMAX), IPIVQ(NMAX),
     +                 IROW(LA), ISTR(NMAX+1), IWORK(LIWORK)
*     .. External Subroutines ..
      EXTERNAL         F11DAF
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F11DAF Example Program Results'
      WRITE (NOUT,*)
*
*     Skip heading in data file
*
      READ (NIN,*)
*
*     Read algorithmic parameters
*
      READ (NIN,*) N
      IF (N.LE.NMAX) THEN
         READ (NIN,*) NNZ
         READ (NIN,*) LFILL, DTOL
         READ (NIN,*) PSTRAT
         READ (NIN,*) MILU
*
*        Read the matrix A
*
         DO 20 I = 1, NNZ
            READ (NIN,*) A(I), IROW(I), ICOL(I)
   20    CONTINUE
*
*        Calculate incomplete LU factorization
*
         IFAIL = 0
         CALL F11DAF(N,NNZ,A,LA,IROW,ICOL,LFILL,DTOL,PSTRAT,MILU,IPIVP,
     +               IPIVQ,ISTR,IDIAG,NNZC,NPIVM,IWORK,LIWORK,IFAIL)
*
*        Output original matrix
*
         WRITE (NOUT,*) ' Original Matrix'
         WRITE (NOUT,'(A,I4)') ' N     =', N
         WRITE (NOUT,'(A,I4)') ' NNZ   =', NNZ
         DO 40 I = 1, NNZ
            WRITE (NOUT,'(I8,D16.4,2I8)') I, A(I), IROW(I), ICOL(I)
   40    CONTINUE
         WRITE (NOUT,*)
*
*        Output details of the factorization
*
         WRITE (NOUT,*) ' Factorization'
         WRITE (NOUT,'(A,I4)') ' N     =', N
         WRITE (NOUT,'(A,I4)') ' NNZ   =', NNZC
         WRITE (NOUT,'(A,I4)') ' NPIVM =', NPIVM
         DO 60 I = NNZ + 1, NNZ + NNZC
            WRITE (NOUT,'(I8,D16.4,2I8)') I, A(I), IROW(I), ICOL(I)
   60    CONTINUE
         WRITE (NOUT,*)
*
         WRITE (NOUT,*) '        I       IPIVP(I)  IPIVQ(I)'
         DO 80 I = 1, N
            WRITE (NOUT,'(3I10)') I, IPIVP(I), IPIVQ(I)
   80    CONTINUE
*
      END IF
      STOP
      END
