Program f11dsfe

!     F11DSF Example Program Text

!     Mark 26.1 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: f11dsf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: omega, rnorm, tol
      Integer                          :: i, ifail, itn, l, lwork, m, maxitn,  &
                                          n, nnz
      Character (8)                    :: method
      Character (1)                    :: precon
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: a(:), b(:), work(:), x(:)
      Integer, Allocatable             :: icol(:), irow(:), iwork(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max
!     .. Executable Statements ..
      Write (nout,*) 'F11DSF Example Program Results'
      Write (nout,*)
!     Skip heading in data file
      Read (nin,*)

!     Read algorithmic parameters

      Read (nin,*) n
      Read (nin,*) nnz
      Read (nin,*) method, precon
      Read (nin,*) omega
      Read (nin,*) m, tol, maxitn
      l = n
      If (precon=='N' .Or. precon=='n') Then
        l = 0
      End If
      lwork = max(4*n+m*(m+n+5)+l+121,8*n+l+120,2*n*(m+3)+m*(m+2)+l+120,       &
        11*n+l+120)

      Allocate (a(nnz),b(n),work(lwork),x(n),icol(nnz),irow(nnz),iwork(2*n+1))

!     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)

!     Solve Ax = b using F11DSF

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call f11dsf(method,precon,n,nnz,a,irow,icol,omega,b,m,tol,maxitn,x,      &
        rnorm,itn,work,lwork,iwork,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 f11dsfe