Example description
    Program f11dqfe

!     F11DQF Example Program Text

!     Mark 26.2 Release. NAG Copyright 2017.

!     .. Use Statements ..
      Use nag_library, Only: f11dnf, f11dqf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: dtol, rnorm, tol
      Integer                          :: i, ifail, itn, la, lfill, liwork,    &
                                          lwork, m, maxitn, n, nnz, nnzc,      &
                                          npivm
      Character (8)                    :: method
      Character (1)                    :: milu, pstrat
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: a(:), b(:), work(:), x(:)
      Integer, Allocatable             :: icol(:), idiag(:), ipivp(:),         &
                                          ipivq(:), irow(:), istr(:), iwork(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max
!     .. Executable Statements ..
      Write (nout,*) 'F11DQF Example Program Results'
      Write (nout,*)
!     Skip heading in data file
      Read (nin,*)

!     Read algorithmic parameters

      Read (nin,*) n, m
      Read (nin,*) nnz
      la = 2*nnz
      liwork = 7*n + 2
      lwork = max(4*n+m*(m+n+5)+121,8*n+120,2*n*(m+3)+m*(m+2)+120,11*n+120)

      Allocate (a(la),b(n),work(lwork),x(n),icol(la),idiag(n),ipivp(n),        &
        ipivq(n),irow(la),istr(n+1),iwork(liwork))
      Read (nin,*) method
      Read (nin,*) lfill, dtol
      Read (nin,*) pstrat
      Read (nin,*) milu
      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 LU factorization

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call f11dnf(n,nnz,a,la,irow,icol,lfill,dtol,pstrat,milu,ipivp,ipivq,     &
        istr,idiag,nnzc,npivm,iwork,liwork,ifail)

!     Solve Ax = b using F11DQF

      ifail = 0
      Call f11dqf(method,n,nnz,a,la,irow,icol,ipivp,ipivq,istr,idiag,b,m,tol,  &
        maxitn,x,rnorm,itn,work,lwork,ifail)

      Write (nout,99999) itn
      Write (nout,99998) rnorm
      Write (nout,*)

!     Output x

      Write (nout,*) '                   X'
      Write (nout,99997) x(1:n)

99999 Format (1X,'Converged in',I10,' iterations')
99998 Format (1X,'Final residual norm =',1P,E16.3)
99997 Format (1X,'(',1P,E16.4,',',1P,E16.4,')')
    End Program f11dqfe