    PROGRAM e02defe

!      E02DEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e02def, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, m, px, py
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: c(:), ff(:), lamda(:), mu(:),        &
                                          wrk(:), x(:), y(:)
       INTEGER, ALLOCATABLE            :: iwrk(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'E02DEF Example Program Results'

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

!      Read PX and PY, the number of knots in the X and Y directions.

       READ (nin,*) px, py
       ALLOCATE (lamda(px),mu(py),c((px-4)*(py-4)),wrk(py-4),iwrk(py-4))

!      Read the knots LAMDA(1) .. LAMDA(PX) and MU(1) .. MU(PY).

       READ (nin,*) lamda(1:px)
       READ (nin,*) mu(1:py)

!      Read C, the bicubic spline coefficients.

       READ (nin,*) c(1:(px-4)*(py-4))

!      Read M, the number of spline evaluation points.

       READ (nin,*) m
       ALLOCATE (x(m),y(m),ff(m))

!      Read the X and Y co-ordinates of the evaluation points.

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

!      Evaluate the spline at the M points.

       ifail = 0
       CALL e02def(m,px,py,x,y,lamda,mu,c,ff,wrk,iwrk,ifail)

       WRITE (nout,*)
       WRITE (nout,*) '      I       X(I)       Y(I)      FF(I)'
       WRITE (nout,99999) (i,x(i),y(i),ff(i),i=1,m)

99999  FORMAT (1X,I7,3F11.3)
    END PROGRAM e02defe
