NAG Library Manual, Mark 30
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program f11jsfe

!     F11JSF Example Program Text

!     Mark 30.0 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: f11jsf, 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, lwork, maxitn, n, nnz
      Character (6)                    :: method
      Character (1)                    :: precon
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: a(:), b(:), work(:), x(:)
      Real (Kind=nag_wp), Allocatable  :: rdiag(:)
      Integer, Allocatable             :: icol(:), irow(:), iwork(:)
!     .. Executable Statements ..
      Write (nout,*) 'F11JSF Example Program Results'
!     Skip heading in data file
      Read (nin,*)

!     Read algorithmic parameters

      Read (nin,*) n
      Read (nin,*) nnz
      lwork = 7*n + 120
      Allocate (a(nnz),b(n),work(lwork),x(n),rdiag(n),icol(nnz),irow(nnz),     &
        iwork(n+1))
      Read (nin,*) method, precon
      Read (nin,*) omega
      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)

!     Solve Ax = b using F11JSF

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