    PROGRAM f11jrfe

!      F11JRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f11jrf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: omega
       INTEGER                         :: i, ifail, n, nnz
       CHARACTER (1)                   :: check
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:), x(:), y(:)
       REAL (KIND=nag_wp), ALLOCATABLE :: rdiag(:)
       INTEGER, ALLOCATABLE            :: icol(:), irow(:), iwork(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'F11JRF Example Program Results'
!      Skip heading in data file
       READ (nin,*)

!      Read algorithmic parameters

       READ (nin,*) n
       READ (nin,*) nnz

       ALLOCATE (a(nnz),x(n),y(n),rdiag(n),icol(nnz),irow(nnz),iwork(n+1))
       READ (nin,*) check
       READ (nin,*) omega

!      Read the matrix A

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

!      Read rhs vector y

       READ (nin,*) y(1:n)

!      Fill in the diagonal part

       DO i = 1, nnz
          IF (irow(i)==icol(i)) rdiag(irow(i)) = 1.E0_nag_wp/real(a(i))
       END DO

!      Solve Mx = b using F11JRF

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f11jrf(n,nnz,a,irow,icol,rdiag,omega,check,y,x,iwork,ifail)

!      Output x

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

99999  FORMAT (1X,'(',E16.4,',',E16.4,')')
    END PROGRAM f11jrfe
