    PROGRAM nag_spline_1d_ex01

      ! 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_auto_fit, nag_spline_1d_extract, nag_deallocate
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: m, p
      REAL (wp) :: smooth, theta
      CHARACTER (1) :: start
      TYPE (nag_spline_1d_comm_wp) :: spline
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: f(:), wt(:), x(:)
      REAL (wp), POINTER :: lambda(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_spline_1d_ex01.'

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) m

      ALLOCATE (x(m),f(m),wt(m))   ! Allocate storage

      READ (nag_std_in,*) x
      READ (nag_std_in,*) f
      READ (nag_std_in,*) wt

      start = 'cold start'

      DO

        ! Read in successive values of smooth and generate spline for
        ! each.
        READ (nag_std_in,*,end=20) smooth

        ! Determine the spline approximation.

        CALL nag_spline_1d_auto_fit(start,x,f,smooth,spline,wt=wt,theta=theta)

        ! Extract the knots.

        CALL nag_spline_1d_extract(spline,p=p,lambda=lambda)

        WRITE (nag_std_out,'(//1X,A,1P,E13.6)') &
         'Calling with smoothing factor =', smooth
        WRITE (nag_std_out,'(/1X,A,I8)') 'Total number of knots =', p
        WRITE (nag_std_out,'(1X,A/(2X,1PE12.6))') 'Interior knots', lambda
        WRITE (nag_std_out,'(/1X,A,1PE12.4)') 'Residual sum of squares =', &
         theta

        start = 'warm start'
        DEALLOCATE (lambda)        ! Deallocate storage to avoid memory leak

      END DO

20    CONTINUE

      DEALLOCATE (x,f,wt)          ! Deallocate storage

      NULLIFY (lambda)

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

    END PROGRAM nag_spline_1d_ex01
