    PROGRAM d01gafe

!      D01GAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : d01gaf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: ans, er
       INTEGER                         :: i, ifail, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: x(:), y(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'D01GAF Example Program Results'

!      Skip heading in data file
       READ (nin,*)

       READ (nin,*) n
       ALLOCATE (x(n),y(n))

       READ (nin,*) (x(i),y(i),i=1,n)

       ifail = -1
       CALL d01gaf(x,y,n,ans,er,ifail)

       SELECT CASE (ifail)
       CASE (0)
          WRITE (nout,*)
          WRITE (nout,99999) 'Integral = ', ans, '     Estimated error = ', er
       CASE (1)
          WRITE (nout,*)
          WRITE (nout,*) 'Less than 4 points supplied'
       CASE (2)
          WRITE (nout,*)
          WRITE (nout,*) 'Points not in increasing or decreasing order'
       CASE (3)
          WRITE (nout,*)
          WRITE (nout,*) 'Points not all distinct'
       END SELECT

99999  FORMAT (1X,A,F7.4,A,F7.4)
    END PROGRAM d01gafe
