    PROGRAM e02bcfe

!      E02BCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e02bcf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: x
       INTEGER                         :: i, ifail, l, left, m, ncap, ncap7
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: c(:), lamda(:)
       REAL (KIND=nag_wp)              :: s(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'E02BCF Example Program Results'

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

       READ (nin,*) ncap, m
       ncap7 = ncap + 7
       ALLOCATE (lamda(ncap7),c(ncap7))

       READ (nin,*) lamda(1:ncap7)
       READ (nin,*) c(1:(ncap+3))

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

          DO left = 1, 2

             ifail = 0
             CALL e02bcf(ncap7,lamda,c,x,left,s,ifail)

             IF (left==1) THEN

                IF (i==1) THEN
                   WRITE (nout,*)
                   WRITE (nout,*) '      X             Spline  &
                      &  1st deriv   2nd deriv   3rd deriv'
                END IF

                WRITE (nout,*)
                WRITE (nout,99999) x, '  LEFT', (s(l),l=1,4)
             ELSE
                WRITE (nout,99999) x, ' RIGHT', (s(l),l=1,4)
             END IF

          END DO

       END DO

99999  FORMAT (1X,E10.2,A,4E12.4)
    END PROGRAM e02bcfe
