    PROGRAM nag_sparse_prec_ex04

      ! Example Program Text for nag_sparse_prec
      ! 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_dia, &
       nag_sparse_mat_cmplx_wp => nag_sparse_mat_cmplx_dp, nag_deallocate
      USE nag_sparse_prec, ONLY : nag_sparse_prec_init_jac
      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, j, n, num_diag
      TYPE (nag_sparse_mat_cmplx_wp) :: a, c_jac
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: diag_indx(:)
      COMPLEX (wp), ALLOCATABLE :: b(:), value(:,:), x(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sparse_prec_ex04'

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

      ALLOCATE (diag_indx(num_diag),value(n,num_diag),b(n),x(n))

      DO i = 1, n
        READ (nag_std_in,*) (value(i,j),j=1,num_diag)
      END DO
      READ (nag_std_in,*) diag_indx
      READ (nag_std_in,*) b

      CALL nag_sparse_mat_init_dia(a,n,value,diag_indx)

      CALL nag_sparse_prec_init_jac(a,c_jac)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Method: BiCGSTAB with Jacobi preconditioner'
      WRITE (nag_std_out,*)

      x = 0.0_wp

      CALL nag_sparse_gen_lin_sol(a,b,x,method='b',p=c_jac)

      ! Output results

      WRITE (nag_std_out,*) ' Solution of linear system'
      WRITE (nag_std_out,'(3X,''('',F4.1,'','',F4.1,'')'')') x

      CALL nag_deallocate(a)
      CALL nag_deallocate(c_jac)
      DEALLOCATE (diag_indx,value,b,x)

    END PROGRAM nag_sparse_prec_ex04
