Program e01tgfe

!     E01TGF Example Program Text

!     Mark 25 Release. NAG Copyright 2014.

!     .. 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