    PROGRAM nag_sparse_mat_ex01

      ! 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_coo, &
       nag_sparse_mat_real_wp => nag_sparse_mat_real_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_real_wp) :: a
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: col_indx(:), row_indx(:)
      REAL (wp), ALLOCATABLE :: value(:), x(:), y(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sparse_mat_ex01'

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

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

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

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

      CALL nag_sparse_mat_init_coo(a,m,value,row_indx,col_indx,n=n, &
       ordered='F',check_indx=.FALSE.,dupl_entry='n')

      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 real sparse matrix from data in COO format'
      WRITE (nag_std_out,*) &
       '   b- multiplying the structure created in a by a vector'
      WRITE (nag_std_out,'(8F6.1)') y(1:m)

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

    END PROGRAM nag_sparse_mat_ex01
