PROGRAM f11jafe

!      F11JAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f11jaf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: dscale, dtol
       INTEGER                         :: i, ifail, la, lfill, liwork, n, nnz, &
                                          nnzc, npivm
       CHARACTER (1)                   :: mic, pstrat
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:)
       INTEGER, ALLOCATABLE            :: icol(:), ipiv(:), irow(:), istr(:),  &
                                          iwork(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F11JAF Example Program Results'
!      Skip heading in data file
       READ (nin,*)

!      Read algorithmic parameters

       READ (nin,*) n
       READ (nin,*) nnz
       la = 2*nnz
       liwork = 2*la + 7*n + 1
       ALLOCATE (a(la),icol(la),ipiv(n),irow(la),istr(n+1),iwork(liwork))
       READ (nin,*) lfill, dtol
       READ (nin,*) mic, dscale
       READ (nin,*) pstrat

!      Read the matrix A

       DO i = 1, nnz
          READ (nin,*) a(i), irow(i), icol(i)
       END DO

!      Calculate incomplete Cholesky factorization

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f11jaf(n,nnz,a,la,irow,icol,lfill,dtol,mic,dscale,pstrat,ipiv, &
          istr,nnzc,npivm,iwork,liwork,ifail)

!      Output original matrix

       WRITE (nout,*) ' Original Matrix'
       WRITE (nout,99997) 'N     =', n
       WRITE (nout,99997) 'NNZ   =', nnz
       DO i = 1, nnz
          WRITE (nout,99999) i, a(i), irow(i), icol(i)
       END DO
       WRITE (nout,*)

!      Output details of the factorization

       WRITE (nout,*) ' Factorization'
       WRITE (nout,99997) 'N     =', n
       WRITE (nout,99997) 'NNZ   =', nnzc
       WRITE (nout,99997) 'NPIVM =', npivm
       DO i = nnz + 1, nnz + nnzc
          WRITE (nout,99999) i, a(i), irow(i), icol(i)
       END DO
       WRITE (nout,*)

       WRITE (nout,*) '      I     IPIV(I)'
       DO i = 1, n
          WRITE (nout,99998) i, ipiv(i)
       END DO

99999  FORMAT (1X,I8,E16.4,2I8)
99998  FORMAT (1X,2I8)
99997  FORMAT (1X,A,I16)
    END PROGRAM f11jafe