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

NAG AD Library Introduction
Example description
    Program s18de_t1w_fe

!     S18DE_T1W_F Example Program Text
!     Mark 29.3 Release. NAG Copyright 2023.

!     .. Use Statements ..
      Use iso_c_binding, Only: c_ptr
      Use nagad_library, Only: nagad_t1w_set_derivative, nagad_t1w_w_ctype,    &
                               nagad_t1w_w_rtype, s18de_t1w_f, x10aa_t1w_f,    &
                               x10ab_t1w_f, Assignment (=)
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: n = 1, nout = 6
!     .. Local Scalars ..
      Type (c_ptr)                     :: ad_handle
      Type (nagad_t1w_w_rtype)         :: fnu, yi, yr
      Type (nagad_t1w_w_ctype)         :: z
      Real (Kind=nag_wp)               :: dyidnu, dyrdnu
      Integer                          :: ifail, nz
      Character (1)                    :: scal
!     .. Local Arrays ..
      Type (nagad_t1w_w_ctype)         :: cy(n)
!     .. Executable Statements ..
      Write (nout,*) 'S18DE_T1W_F Example Program Results'

      fnu = 5.5_nag_wp
      scal = 'S'
      z%vreal = -6.1_nag_wp
      z%vimag = 9.8_nag_wp

      Write (nout,99998) 'fnu', 'z', 'scal', 'cy(1)', 'dcy/dfnu'

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

!     Register variables to differentiate w.r.t.
      Call nagad_t1w_set_derivative(fnu,1.0_nag_wp)

      ifail = 0
      Call s18de_t1w_f(ad_handle,fnu,z,n,scal,cy,nz,ifail)

!     Get derivatives
      yr = cy(1)%vreal
      yi = cy(1)%vimag
      dyrdnu = yr%tangent
      dyidnu = yi%tangent

      Write (nout,99999) fnu%value, z%vreal%value, z%vimag%value, scal,        &
        yr%value, yi%value, dyrdnu, dyidnu

      ifail = 0
      Call x10ab_t1w_f(ad_handle,ifail)

99999 Format (1X,F7.4,'  (',F7.3,',',F7.3,')   ',A,2('  (',F7.3,',',F7.3,')'))
99998 Format (/,A7,A12,A13,A13,A22)
    End Program s18de_t1w_fe