    PROGRAM nag_pch_interp_ex02

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_pch_interp, ONLY : nag_pch_comm_wp => nag_pch_comm_dp, &
       nag_pch_monot_interp, nag_pch_eval, nag_deallocate
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND, REAL
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, m, n
      REAL (wp) :: dx
      TYPE (nag_pch_comm_wp) :: interp
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: d(:), f(:), h(:), hd(:), u(:), x(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_pch_interp_ex02'

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

      ALLOCATE (x(m),f(m),d(m),u(n),h(n),hd(n)) ! Allocate storage

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

      ! Initialize structure interp.

      CALL nag_pch_monot_interp(x,f,interp,d=d)

      ! Evaluate interp at n equally spaced points in [x(1), x(m)].
      IF (n<=1) THEN
        WRITE (nag_std_out,*) 'n <= 1.'
      ELSE
        dx = (x(m)-x(1))/REAL(n-1,kind=wp)
        u = (/ (x(1)+(i-1)*dx,i=1,n-1), x(m) /)

        CALL nag_pch_eval(interp,u,h,hd=hd)

        WRITE (nag_std_out,'(/,9X,''u'',11X,''h'',11X,''hd'')')
        WRITE (nag_std_out,'(1X,2F12.4,ES15.4)') (u(i),h(i),hd(i),i=1,n)
      END IF

      DEALLOCATE (x,f,d,u,h,hd)    ! Deallocate storage

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

    END PROGRAM nag_pch_interp_ex02
