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

NAG FL Interface Introduction
Example description
!   D01AQF Example Program Text
!   Mark 30.3 Release. nAG Copyright 2024.

    Module d01aqfe_mod

!     D01AQF 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                           :: g
!     .. Parameters ..
      Integer, Parameter, Public       :: lw = 800, nout = 6
      Integer, Parameter, Public       :: liw = lw/4
    Contains
      Function g(x)

!       .. Function Return Value ..
        Real (Kind=nag_wp)             :: g
!       .. Scalar Arguments ..
        Real (Kind=nag_wp), Intent (In) :: x
!       .. Local Scalars ..
        Real (Kind=nag_wp)             :: aa
!       .. Executable Statements ..
        aa = 0.01E0_nag_wp
        g = 1.0E0_nag_wp/(x**2+aa**2)

        Return

      End Function g
    End Module d01aqfe_mod
    Program d01aqfe

!     D01AQF Example Main Program

!     .. Use Statements ..
      Use d01aqfe_mod, Only: g, liw, lw, nout
      Use nag_library, Only: d01aqf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: a, abserr, b, c, epsabs, epsrel,     &
                                          result
      Integer                          :: ifail
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: w(:)
      Integer, Allocatable             :: iw(:)
!     .. Executable Statements ..
      Write (nout,*) 'D01AQF Example Program Results'

      Allocate (w(lw),iw(liw))

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

      ifail = -1
      Call d01aqf(g,a,b,c,epsabs,epsrel,result,abserr,w,lw,iw,liw,ifail)

      If (ifail>=0) Then
        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,99998) 'C     ', 'weight function parameter', c
      End If

      If (ifail>=0 .And. ifail<=3) Then
        Write (nout,*)
        Write (nout,99997) 'RESULT', 'approximation to the integral', result
        Write (nout,99998) 'ABSERR', 'estimate of the absolute error', abserr
        Write (nout,99996) 'IW(1) ', 'number of subintervals used', iw(1)
      End If

99999 Format (1X,A6,' - ',A32,' = ',F10.4)
99998 Format (1X,A6,' - ',A32,' = ',E9.2)
99997 Format (1X,A6,' - ',A32,' = ',F9.2)
99996 Format (1X,A6,' - ',A32,' = ',I4)
    End Program d01aqfe