!   D01ASF Example Program Text
!   Mark 23 Release. NAG Copyright 2011.

    MODULE d01asfe_mod

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

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER                  :: limlst = 50, lw = 800, nout = 6
       INTEGER, PARAMETER                  :: liw = lw/2
    CONTAINS
!dec$ attributes offload : mic :: g
       FUNCTION g(x)

!         .. Implicit None Statement ..
          IMPLICIT NONE
!         .. Function Return Value ..
          REAL (KIND=nag_wp)                  :: g
!         .. Scalar Arguments ..
          REAL (KIND=nag_wp), INTENT (IN)     :: x
!         .. Intrinsic Functions ..
          INTRINSIC                              sqrt
!         .. Executable Statements ..
          IF (x>0.0E0_nag_wp) THEN
             g = 1.0E0_nag_wp/sqrt(x)
          ELSE
             g = 0.0E0_nag_wp
          END IF

          RETURN

!dec$ attributes offload : mic :: g
       END FUNCTION g
    END MODULE d01asfe_mod
    PROGRAM d01asfe

!      D01ASF Example Main Program

!      .. Use Statements ..
       USE nag_library, ONLY : d01asf, nag_wp, x01aaf
       USE d01asfe_mod, ONLY : g, limlst, liw, lw, nout
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Local Scalars ..
       REAL (KIND=nag_wp)                  :: a, abserr, epsabs, omega, result
       INTEGER                             :: ifail, key, lst
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE     :: erlst(:), rslst(:), w(:)
       INTEGER, ALLOCATABLE                :: ierlst(:), iw(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'D01ASF Example Program Results'

       ALLOCATE (erlst(limlst),rslst(limlst),w(lw),ierlst(limlst),iw(liw))

       epsabs = 1.0E-03_nag_wp
       a = 0.0E0_nag_wp
       omega = 0.5E0_nag_wp*x01aaf(omega)
       key = 1

       ifail = -1
       CALL d01asf(g,a,omega,key,epsabs,result,abserr,limlst,lst,erlst,rslst, &
          ierlst,w,lw,iw,liw,ifail)

       IF (ifail>=0) THEN
          WRITE (nout,*)
          WRITE (nout,99999) 'A      - lower limit of integration = ', a
          WRITE (nout,*) 'B      - upper limit of integration =  infinity'
          WRITE (nout,99998) 'EPSABS - absolute accuracy requested = ', epsabs

          IF (ifail/=6 .AND. ifail/=10) 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) 'LST    - number of intervals used = ', lst
             WRITE (nout,99996) 'IW(1)  - max. no. of subintervals &
                &used in any one interval = ', iw(1)
          END IF

       END IF

99999  FORMAT (1X,A,F10.4)
99998  FORMAT (1X,A,E9.2)
99997  FORMAT (1X,A,F9.5)
99996  FORMAT (1X,A,I4)
    END PROGRAM d01asfe
