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

NAG AD Library Introduction
Example description
    Program d01ga_p0w_fe

!     D01GA_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: d01ga_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)               :: a, ans, er, xr
      Integer                          :: i, ifail, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: x(:), y(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: real
!     .. Executable Statements ..

      Write (nout,*) 'D01GA_P0W_F Example Program Results'

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

      Read (nin,*) n
      Read (nin,*) a

      Allocate (x(n),y(n))

      Do i = 1, n
        xr = real(i-1,kind=nag_wp)/real(n-1,kind=nag_wp)
        x(i) = xr
        y(i) = 4.0_nag_wp/(1.0_nag_wp+a*a*xr*xr)
      End Do

!     Call the passive routine
      ifail = 0
      Call d01ga_p0w_f(ad_handle,x,y,n,ans,er,ifail)

      Write (nout,*)
      Write (nout,99999) ' Solution, ans =', ans
      Write (nout,*)

99999 Format (1X,A,1X,F12.5)

    End Program d01ga_p0w_fe