    PROGRAM nag_sparse_mat_ex03

      ! Example Program Text for nag_sparse_mat
      ! 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_csr, &
       nag_sparse_mat_cmplx_wp => nag_sparse_mat_cmplx_dp, nag_sparse_matvec, &
       nag_deallocate
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, m, n, nnz
      TYPE (nag_sparse_mat_cmplx_wp) :: a
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: col_indx(:), row_begin(:)
      COMPLEX (wp), ALLOCATABLE :: value(:), x(:), y(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sparse_mat_ex03'

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

      ! allocate required arrays
      ALLOCATE (col_indx(nnz),row_begin(m),value(nnz),x(m),y(n))

      ! Read values and column indices
      DO i = 1, nnz
        READ (nag_std_in,*) value(i), col_indx(i)
      END DO

      ! Read row begin
      READ (nag_std_in,*) row_begin(1:m)

      ! Read vector x
      READ (nag_std_in,*) x(1:m)

      CALL nag_sparse_mat_init_csr(a,value,col_indx,row_begin,n=n)

      CALL nag_sparse_matvec(a,x,y,trans='c')

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) ' The output of:'
      WRITE (nag_std_out,*) &
       '   a- creating a complex sparse matrix from data in CSR format'
      WRITE (nag_std_out,*) &
       '   b- multiplying the structure created in a by a vector'
      WRITE (nag_std_out,'(3X,''('',F5.1,'','',F5.1,'')'')') y(1:n)

      CALL nag_deallocate(a)
      DEALLOCATE (x,y,value,row_begin,col_indx)

    END PROGRAM nag_sparse_mat_ex03
