NAG Library Manual, Mark 30.3
Interfaces:  FL   CL   CPP   AD 

NAG AD Library Introduction
Example description
    Program e02bc_p0w_fe
!     E02BC_P0W_F Example Program Text
!     Mark 30.3 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use iso_c_binding, Only: c_ptr
      Use nagad_library, Only: e02bc_p0w_f
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Type (c_ptr)                     :: ad_handle
      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,*) 'E02BC_P0W_F Example Program Results'

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

      Read (nin,*) ncap, m
      ncap7 = ncap + 7
      Allocate (lamda(ncap7),c(ncap7))

      lamda = 0.0_nag_wp
      c = 0.0_nag_wp

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

      Do i = 1, m
        x = 0.0_nag_wp
        Read (nin,*) x

        Do left = 1, 2
!         A1W computation

          ifail = 0
          Call e02bc_p0w_f(ad_handle,ncap7,lamda,c,x,left,s,ifail)

          If (left==1) Then

            If (i==1) Then
              Write (nout,*)
              Write (nout,99999) 'x', 'Spline', '1st deriv', '2nd deriv',      &
                '3rd deriv'
            End If
99999       Format (6X,A,13X,A,5X,A,3X,A,3X,A)
            Write (nout,*)
            Write (nout,99998) x, '  Left', (s(l),l=1,4)
          Else
            Write (nout,99998) x, ' Right', (s(l),l=1,4)
          End If

        End Do

      End Do

99998 Format (1X,E10.2,A,4E12.4)

    End Program e02bc_p0w_fe