    PROGRAM nag_spline_2d_ex04

      ! Example Program Text for nag_spline_2d
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_spline_2d, ONLY : nag_spline_2d_comm_wp => nag_spline_2d_comm_dp
      USE nag_spline_2d, ONLY : nag_spline_2d_set
      USE nag_spline_2d, ONLY : nag_spline_2d_intg
      USE nag_spline_2d, ONLY : nag_deallocate
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: p, q
      REAL (wp) :: a, alpha, b, beta, c, d, delta, gamma, integral
      TYPE (nag_spline_2d_comm_wp) :: spline
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: kappa(:,:), lambda(:), mu(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_spline_2d_ex04'

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) a, b, c, d
      READ (nag_std_in,*) p, q

      ALLOCATE (lambda(p-8),mu(q-8),kappa(p-4,q-4)) ! Allocate storage

      READ (nag_std_in,*) lambda
      READ (nag_std_in,*) mu
      READ (nag_std_in,*) kappa

      ! Initialize spline.

      CALL nag_spline_2d_set(a,b,c,d,lambda,mu,kappa,spline)

      ! Read integration region.
      READ (nag_std_in,*) alpha, beta, gamma, delta

      ! Evaluate spline integral on [alpha, beta] x [gamma,delta].

      integral = nag_spline_2d_intg(spline,alpha=alpha,beta=beta,gamma=gamma, &
       delta=delta)

      WRITE (nag_std_out,'(/1X,A,ES12.4)') 'Spline integral = ', integral

      DEALLOCATE (lambda,mu,kappa) ! Deallocate storage

      CALL nag_deallocate(spline)  ! Free structure allocated by NAG fl90

    END PROGRAM nag_spline_2d_ex04
