    PROGRAM e02ahfe

!      E02AHF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e02ahf, e02akf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       REAL (KIND=nag_wp), PARAMETER   :: xmax = 2.5E0_nag_wp
       REAL (KIND=nag_wp), PARAMETER   :: xmin = -0.5E0_nag_wp
       INTEGER, PARAMETER              :: nout = 6, np1 = 7
       INTEGER, PARAMETER              :: la = np1
       INTEGER, PARAMETER              :: ladif = np1
       REAL (KIND=nag_wp), PARAMETER   :: a(la) = (/ 2.53213E0_nag_wp,         &
                                          1.13032E0_nag_wp, 0.27150E0_nag_wp,  &
                                          0.04434E0_nag_wp, 0.00547E0_nag_wp,  &
                                          0.00054E0_nag_wp, 0.00004E0_nag_wp/)
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: deriv, deriv2, patm1, x
       INTEGER                         :: i, ifail, m
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: adif(ladif), adif2(ladif)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'E02AHF Example Program Results'

       ifail = 0
       CALL e02ahf(np1,xmin,xmax,a,1,la,patm1,adif,1,ladif,ifail)

       ifail = 0
       CALL e02ahf(np1-1,xmin,xmax,adif,1,ladif,patm1,adif2,1,ladif,ifail)

       m = 4

       WRITE (nout,*)
       WRITE (nout,*) '   I  Argument    1st deriv    2nd deriv'

       DO i = 1, m
          x = (xmin*real(m-i,kind=nag_wp)+xmax*real(i-1,kind=nag_wp))/ &
             real(m-1,kind=nag_wp)

          ifail = 0
          CALL e02akf(np1-1,xmin,xmax,adif,1,ladif,x,deriv,ifail)

          ifail = 0
          CALL e02akf(np1-2,xmin,xmax,adif2,1,ladif,x,deriv2,ifail)

          WRITE (nout,99999) i, x, deriv, deriv2
       END DO

99999  FORMAT (1X,I4,F9.4,2(4X,F9.4))
    END PROGRAM e02ahfe
