    PROGRAM e01tgfe

!      E01TGF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e01tgf, e01thf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, liq, lrq, m, n, nq, nw
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: f(:), q(:), qx(:), qy(:), qz(:),     &
                                          rq(:), u(:), v(:), w(:), x(:), y(:), &
                                          z(:)
       INTEGER, ALLOCATABLE            :: iq(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'E01TGF Example Program Results'

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

!      Input the number of nodes.

       READ (nin,*) m
       liq = 2*m + 1
       lrq = 10*m + 7
       ALLOCATE (x(m),y(m),z(m),f(m),iq(liq),rq(lrq))

       DO i = 1, m
          READ (nin,*) x(i), y(i), z(i), f(i)
       END DO

!      Generate the interpolant.

       nq = 0
       nw = 0

       ifail = 0
       CALL e01tgf(m,x,y,z,f,nw,nq,iq,liq,rq,lrq,ifail)

!      Input the number of evaluation points.

       READ (nin,*) n
       ALLOCATE (u(n),v(n),w(n),q(n),qx(n),qy(n),qz(n))

!      Input the evaluation points.

       DO i = 1, n
          READ (nin,*) u(i), v(i), w(i)
       END DO

!      Evaluate the interpolant using E01THF.

       ifail = -0
       CALL e01thf(m,x,y,z,f,iq,liq,rq,lrq,n,u,v,w,q,qx,qy,qz,ifail)

       WRITE (nout,*)
       WRITE (nout,*) '     I     U(I)      V(I)      W(I)      Q(I)'

       DO i = 1, n
          WRITE (nout,99999) i, u(i), v(i), w(i), q(i)
       END DO

99999  FORMAT (1X,I6,4F10.4)
    END PROGRAM e01tgfe
