    PROGRAM nag_sparse_lin_sys_ex01

      ! Example Program Text for nag_sparse_lin_sys
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_sparse_mat, ONLY : nag_sparse_mat_init_coo, &
       nag_sparse_mat_real_wp => nag_sparse_mat_real_dp, nag_deallocate
      USE nag_sparse_lin_sys, ONLY : nag_sparse_gen_lin_sol
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, n, nnz, num_iter
      REAL (wp) :: resid_norm
      TYPE (nag_sparse_mat_real_wp) :: a
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: col(:), row(:)
      REAL (wp), ALLOCATABLE :: b(:), value(:), x(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_sparse_lin_sys_ex01'

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) n, nnz

      ALLOCATE (row(nnz),col(nnz),value(nnz),b(n),x(n))

      DO i = 1, nnz
        READ (nag_std_in,*) value(i), row(i), col(i)
      END DO
      READ (nag_std_in,*) b

      CALL nag_sparse_mat_init_coo(a,n,value,row,col)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Method: GMRES'
      WRITE (nag_std_out,*)

      x = 0.0_wp

      CALL nag_sparse_gen_lin_sol(a,b,x,resid_norm=resid_norm, &
       num_iter=num_iter)

      WRITE (nag_std_out,*) ' Solution'
      WRITE (nag_std_out,'(10F7.1)') x
      WRITE (nag_std_out,'(2x,''residual norm . . .  ='',1PE9.1)') resid_norm
      WRITE (nag_std_out,'(2x,''number of iterations ='',I4)') num_iter

      CALL nag_deallocate(a)
      DEALLOCATE (row,col,value,b,x)

    END PROGRAM nag_sparse_lin_sys_ex01
