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

NAG AD Library Introduction
Example description
    Program g01fe_t1w_fe

!     G01FE_T1W_F Example Program Text
!     Mark 27.2 Release. NAG Copyright 2021.

!     .. Use Statements ..
      Use iso_c_binding, Only: c_ptr
      Use nagad_library, Only: g01fe_t1w_f, nagad_t1w_set_derivative,          &
                               nagad_t1w_w_rtype, x10aa_t1w_f, x10ab_t1w_f,    &
                               Assignment (=)
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Type (nagad_t1w_w_rtype)         :: a, b, p, tol, x
      Type (c_ptr)                     :: ad_handle
      Real (Kind=nag_wp)               :: ar, br, dxda, dxdb, dxdp, pr
      Integer                          :: i, ifail, n
!     .. Executable Statements ..
      Write (nout,*) 'G01FE_T1W_F Example Program Results'

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

      tol = 0.0_nag_wp

      Write (nout,*)
      Write (nout,*) ' deviates and derivatives'
      Write (nout,*)
      Write (nout,99998) 'p', 'a', 'b', 'x', 'dx/dp', 'dx/da', 'dx/db'

!     Create AD configuration data object
      ifail = 0
      Call x10aa_t1w_f(ad_handle,ifail)

      Do i = 1, n

        Read (nin,*) pr, ar, br

        p = pr
        a = ar
        b = br
        Call nagad_t1w_set_derivative(p,1.0_nag_wp)
        ifail = 0
        Call g01fe_t1w_f(ad_handle,p,a,b,tol,x,ifail)
        dxdp = x%tangent

        p = pr
        a = ar
        b = br
        Call nagad_t1w_set_derivative(a,1.0_nag_wp)
        ifail = 0
        Call g01fe_t1w_f(ad_handle,p,a,b,tol,x,ifail)
        dxda = x%tangent

        p = pr
        a = ar
        b = br
        Call nagad_t1w_set_derivative(b,1.0_nag_wp)
        ifail = 0
        Call g01fe_t1w_f(ad_handle,p,a,b,tol,x,ifail)
        dxdb = x%tangent

        Write (nout,99999) p%value, a%value, b%value, x%value, dxdp, dxda,     &
          dxdb
      End Do
99999 Format (1X,1P,7E11.2)
99998 Format (1X,A4,3A11,A15,2A11)

!     Remove computational data object
      Call x10ab_t1w_f(ad_handle,ifail)

    End Program g01fe_t1w_fe