! C05AY_T1W_F Example Program Text
! Mark 28.6 Release. NAG Copyright 2022.
Module c05ay_t1w_fe_mod
! C05AY_T1W_F Example Program Module:
! Parameters and User-defined Routines
! .. Use Statements ..
Use iso_c_binding, Only: c_ptr
Use nagad_library, Only: exp, nagad_t1w_w_rtype, Operator (-), &
Operator (*)
! .. Implicit None Statement ..
Implicit None
! .. Accessibility Statements ..
Private
Public :: f
! .. Parameters ..
Integer, Parameter, Public :: nin = 5, nout = 6
Contains
Subroutine f(ad_handle,x,z,iuser,ruser)
! .. Scalar Arguments ..
Type (c_ptr), Intent (Inout) :: ad_handle
Type (nagad_t1w_w_rtype), Intent (In) :: x
Type (nagad_t1w_w_rtype), Intent (Out) :: z
! .. Array Arguments ..
Type (nagad_t1w_w_rtype), Intent (Inout) :: ruser(*)
Integer, Intent (Inout) :: iuser(*)
! .. Executable Statements ..
z = exp(-x) - x*ruser(1)
Return
End Subroutine f
End Module c05ay_t1w_fe_mod
Program c05ay_t1w_fe
! C05AY_T1W_F Example Main Program
! .. Use Statements ..
Use c05ay_t1w_fe_mod, Only: f, nin, nout
Use iso_c_binding, Only: c_ptr
Use nagad_library, Only: c05ay_t1w_f, nagad_t1w_w_rtype, x10aa_t1w_f, &
x10ab_t1w_f, Assignment (=)
Use nag_library, Only: nag_wp
! .. Implicit None Statement ..
Implicit None
! .. Local Scalars ..
Type (nagad_t1w_w_rtype) :: a, b, eps, eta, x
Type (c_ptr) :: ad_handle
Real (Kind=nag_wp) :: ar, br, epsr, etar, rr
Integer :: ifail
! .. Local Arrays ..
Type (nagad_t1w_w_rtype) :: ruser(1)
Integer :: iuser(1)
! .. Executable Statements ..
Write (nout,*) 'C05AY_T1W_F Example Program Results'
! Skip first line of data file
Read (nin,*)
! Read problem parameters
Read (nin,*) ar
Read (nin,*) br
Read (nin,*) epsr
Read (nin,*) etar
Read (nin,*) rr
a = ar
b = br
eps = epsr
eta = etar
ruser(1) = rr
! Create AD configuration data object
ifail = 0
Call x10aa_t1w_f(ad_handle,ifail)
! Call AD routine
ruser(1)%tangent = 1.0_nag_wp
ifail = 0
Call c05ay_t1w_f(ad_handle,a,b,eps,eta,f,x,iuser,ruser,ifail)
Write (nout,*)
Write (nout,99999) ' Solution, x =', x%value
Write (nout,99999) ' dx/druser(1) =', x%tangent
99999 Format (1X,A,1X,E12.5)
! Remove computational data object
Call x10ab_t1w_f(ad_handle,ifail)
End Program c05ay_t1w_fe