    PROGRAM nag_spline_1d_ex04

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_spline_1d, ONLY : nag_spline_1d_comm_wp => nag_spline_1d_comm_dp &
       , nag_spline_1d_set, nag_spline_1d_eval, nag_spline_1d_intg, &
       nag_deallocate
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, n, p
      REAL (wp) :: a, alpha, b, beta, integral, s, sd1, sd2, sd3, x
      TYPE (nag_spline_1d_comm_wp) :: spline
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: kappa(:), lambda(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_spline_1d_ex04'

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

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

      READ (nag_std_in,*) lambda
      READ (nag_std_in,*) kappa
      READ (nag_std_in,*) n
      READ (nag_std_in,*) alpha, beta

      ! Initialize spline.

      CALL nag_spline_1d_set(a,b,lambda,kappa,spline)

      ! Calculate values of the spline and its derivatives on a uniform
      ! mesh.
      WRITE (nag_std_out,'(/,6X,A,13X,A,6X,A,3X,A,3X,A)') 'x', 'spline', &
       '1st deriv', '2nd deriv', '3rd deriv'
      x = 0.0_wp
      DO i = 1, n

        CALL nag_spline_1d_eval(spline,x,s,sd1=sd1,sd2=sd2,sd3=sd3)

        WRITE (nag_std_out,'(/E12.4,1X,A,4E12.4)') x, 'LEFT ', s, sd1, sd2, &
         sd3

        CALL nag_spline_1d_eval(spline,x,s,sd1=sd1,sd2=sd2,sd3=sd3, &
         right_hand=.TRUE.)

        WRITE (nag_std_out,'(E12.4,1X,A,4E12.4)') x, 'RIGHT', s, sd1, sd2, sd3
        x = x + 1.0_wp
      END DO

      ! Evaluate spline integral on (alpha, beta).

      integral = nag_spline_1d_intg(spline,alpha=alpha,beta=beta)

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

      DEALLOCATE (lambda,kappa)    ! Deallocate storage

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

    END PROGRAM nag_spline_1d_ex04
