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

NAG FL Interface Introduction
Example description
!   D01BDF Example Program Text
!   Mark 28.4 Release. NAG Copyright 2022.

    Module d01bdfe_mod

!     D01BDF Example Program Module:
!            Parameters and User-defined Routines

!     .. Use Statements ..
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Accessibility Statements ..
      Private
      Public                           :: f
!     .. Parameters ..
      Integer, Parameter, Public       :: nout = 6
    Contains
      Function f(x)

!       .. Use Statements ..
        Use nag_library, Only: x01aaf
!       .. Function Return Value ..
        Real (Kind=nag_wp)             :: f
!       .. Scalar Arguments ..
        Real (Kind=nag_wp), Intent (In) :: x
!       .. Intrinsic Procedures ..
        Intrinsic                      :: sin
!       .. Executable Statements ..
        f = (x**2)*sin(10.0E0_nag_wp*x01aaf(f)*x)

        Return

      End Function f
    End Module d01bdfe_mod
    Program d01bdfe

!     D01BDF Example Main Program

!     .. Use Statements ..
      Use d01bdfe_mod, Only: f, nout
      Use nag_library, Only: d01bdf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: a, abserr, b, epsabs, epsrel, result
!     .. Intrinsic Procedures ..
      Intrinsic                        :: abs, max
!     .. Executable Statements ..
      Write (nout,*) 'D01BDF Example Program Results'

      epsabs = 0.0E0_nag_wp
      epsrel = 1.0E-04_nag_wp
      a = 0.0E0_nag_wp
      b = 1.0E0_nag_wp

      Call d01bdf(f,a,b,epsabs,epsrel,result,abserr)

      Write (nout,*)
      Write (nout,99999) 'A      - lower limit of integration = ', a
      Write (nout,99999) 'B      - upper limit of integration = ', b
      Write (nout,99998) 'EPSABS - absolute accuracy requested = ', epsabs
      Write (nout,99998) 'EPSREL - relative accuracy requested = ', epsrel
      Write (nout,*)
      Write (nout,99997) 'RESULT - approximation to the integral = ', result
      Write (nout,99998) 'ABSERR - estimate to the absolute error = ', abserr
      Write (nout,*)

      If (abserr>max(epsabs,epsrel*abs(result))) Then
        Write (nout,*)                                                         &
          'Warning - requested accuracy may not have been achieved'
      End If

99999 Format (1X,A,F10.4)
99998 Format (1X,A,E9.2)
99997 Format (1X,A,F9.5)
    End Program d01bdfe