    PROGRAM f11jqfe

!      F11JQF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

!      Read algorithmic parameters

       READ (nin,*) n
       READ (nin,*) nnz
       la = 3*nnz
       liwork = 2*la + 7*n + 1
       lwork = 7*n + 120
       ALLOCATE (a(la),b(n),work(lwork),x(n),icol(la),ipiv(n),irow(la), &
          istr(n+1),iwork(liwork))
       READ (nin,*) method
       READ (nin,*) lfill, dtol
       READ (nin,*) mic, dscale
       READ (nin,*) pstrat
       READ (nin,*) tol, maxitn

!      Read the matrix A

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

!      Read rhs vector b and initial approximate solution x

       READ (nin,*) b(1:n)
       READ (nin,*) x(1:n)

!      Calculate incomplete Cholesky factorization

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

!      Solve Ax = b using F11JQF

       CALL f11jqf(method,n,nnz,a,la,irow,icol,ipiv,istr,b,tol,maxitn,x,rnorm, &
          itn,work,lwork,ifail)

       WRITE (nout,99999) 'Converged in', itn, ' iterations'
       WRITE (nout,99998) 'Final residual norm =', rnorm

!      Output x

       WRITE (nout,99997) x(1:n)

99999  FORMAT (1X,A,I10,A)
99998  FORMAT (1X,A,1P,E16.3)
99997  FORMAT (1X,'(',E16.4,',',E16.4,')')
    END PROGRAM f11jqfe
