    PROGRAM f11xafe

!      F11XAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f11xaf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, n, nnz
       CHARACTER (1)                   :: check, trans
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:), x(:), y(:)
       INTEGER, ALLOCATABLE            :: icol(:), irow(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F11XAF Example Program Results'
!      Skip heading in data file
       READ (nin,*)

!      Read order of matrix and number of non-zero entries

       READ (nin,*) n
       READ (nin,*) nnz

       ALLOCATE (a(nnz),x(n),y(n),icol(nnz),irow(nnz))

!      Read the matrix A

       DO i = 1, nnz
          READ (nin,*) a(i), irow(i), icol(i)
       END DO

!      Read the vector x

       READ (nin,*) x(1:n)

!      Calculate matrix-vector product

       trans = 'N'
       check = 'C'

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f11xaf(trans,n,nnz,a,irow,icol,check,x,y,ifail)

!      Output results

       WRITE (nout,*)
       WRITE (nout,*) ' Matrix-vector product'
       WRITE (nout,'(E16.4)') y(1:n)

!      Calculate transposed matrix-vector product

       trans = 'T'
       check = 'N'

       ifail = 0
       CALL f11xaf(trans,n,nnz,a,irow,icol,check,x,y,ifail)

!      Output results

       WRITE (nout,*)
       WRITE (nout,*) ' Transposed matrix-vector product'
       WRITE (nout,'(E16.4)') y(1:n)

    END PROGRAM f11xafe
