    MODULE quad_1d_inf_ex02_mod

      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Default Accessibility ..
      PUBLIC
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)

    CONTAINS

      FUNCTION g(x)

        ! .. Implicit None Statement ..
        IMPLICIT NONE
        ! .. Intrinsic Functions ..
        INTRINSIC SIZE, SQRT
        ! .. Array Arguments ..
        REAL (wp), INTENT (IN) :: x(:)
        ! .. Function Return Value ..
        REAL (wp) :: g(SIZE(x))
        ! .. Executable Statements ..
        WHERE (x>0.0_wp)
          g = 1.0_wp/SQRT(x)
        ELSEWHERE
          g = 0.0_wp
        END WHERE

      END FUNCTION g

    END MODULE quad_1d_inf_ex02_mod

    PROGRAM nag_quad_1d_inf_ex02

      ! Example Program Text for nag_quad_1d_inf
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_out
      USE nag_math_constants, ONLY : nag_pi
      USE nag_quad_1d_inf, ONLY : nag_quad_1d_inf_wt_trig
      USE quad_1d_inf_ex02_mod, ONLY : wp, g
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Local Scalars ..
      REAL (wp) :: a, omega, pi, result
      CHARACTER (1) :: trig_wt
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_quad_1d_inf_ex02'

      pi = nag_pi(0.0_wp)
      a = 0.0_wp
      omega = 0.5_wp*pi
      trig_wt = 'cosine'

      CALL nag_quad_1d_inf_wt_trig(g,a,omega,trig_wt,result)

      WRITE (nag_std_out,'(/,1X,A,F10.4)') &
       'a  - lower limit of integration = ', a
      WRITE (nag_std_out,*) 'b  - upper limit of integration = infinity'
      WRITE (nag_std_out,'(1X,A,F9.5)') &
       'result - approximation to the integral =', result

    END PROGRAM nag_quad_1d_inf_ex02
