    PROGRAM e01bhfe

!      E01BHF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e01bhf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: a, b, pint
       INTEGER                         :: ifail, ioerr, n, r
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: d(:), f(:), x(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'E01BHF Example Program Results'

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

       READ (nin,*) n
       ALLOCATE (d(n),f(n),x(n))

       DO r = 1, n
          READ (nin,*) x(r), f(r), d(r)
       END DO

       WRITE (nout,*)
       WRITE (nout,*) '                               Integral'
       WRITE (nout,*) '          A            B     over (A,B)'

DATA:  DO
          READ (nin,*,IOSTAT=ioerr) a, b

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = 0
          CALL e01bhf(n,x,f,d,a,b,pint,ifail)

          WRITE (nout,99999) a, b, pint
       END DO DATA

99999  FORMAT (1X,3F13.4)
    END PROGRAM e01bhfe
