    PROGRAM nag_sparse_mat_ex02

      ! 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_csc, &
       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, n, nnz
      TYPE (nag_sparse_mat_cmplx_wp) :: a
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: col_begin(:), row_indx(:)
      COMPLEX (wp), ALLOCATABLE :: value(:), x(:), y(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sparse_mat_ex02'

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

      ! allocate required arrays
      ALLOCATE (row_indx(nnz),col_begin(n),value(nnz),x(n),y(n))

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

      ! Read columns begin
      READ (nag_std_in,*) col_begin(1:n)

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

      CALL nag_sparse_mat_init_csc(a,value,row_indx,col_begin,mat_type='h')

      CALL nag_sparse_matvec(a,x,y)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) ' The output of:'
      WRITE (nag_std_out,*) &
       '   a- creating a Hermitian sparse matrix from data in CSC 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_indx,col_begin)

    END PROGRAM nag_sparse_mat_ex02
