    MODULE quad_1d_ex03_mod

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

    CONTAINS

      FUNCTION g1(x)

        ! .. Implicit None Statement ..
        IMPLICIT NONE
        ! .. Intrinsic Functions ..
        INTRINSIC COS, SIZE
        ! .. Array Arguments ..
        REAL (wp), INTENT (IN) :: x(:)
        ! .. Function Return Value ..
        REAL (wp) :: g1(SIZE(x))
        ! .. Executable Statements ..
        g1 = COS(10.0_wp*pi*x)

      END FUNCTION g1

      FUNCTION g2(x)

        ! .. Implicit None Statement ..
        IMPLICIT NONE
        ! .. Intrinsic Functions ..
        INTRINSIC SIN, SIZE
        ! .. Array Arguments ..
        REAL (wp), INTENT (IN) :: x(:)
        ! .. Function Return Value ..
        REAL (wp) :: g2(SIZE(x))
        ! .. Executable Statements ..
        g2 = SIN(10.0_wp*x)

      END FUNCTION g2

    END MODULE quad_1d_ex03_mod

    PROGRAM nag_quad_1d_ex03

      ! Example Program Text for nag_quad_1d
      ! 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, ONLY : nag_quad_1d_wt_end_sing
      USE quad_1d_ex03_mod, ONLY : wp, g1, g2, pi
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Local Scalars ..
      REAL (wp) :: a, alpha1, alpha2, b, beta1, beta2, result1, result2
      CHARACTER (1) :: log_wt
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_quad_1d_ex03'

      pi = nag_pi(0.0_wp)
      a = 0.0_wp
      b = 1.0_wp
      alpha1 = 0.0_wp
      beta1 = 0.0_wp
      log_wt = 'lower'

      WRITE (nag_std_out,'(/,1X,A,F10.4)') &
       'a  - lower limit of integration = ', a
      WRITE (nag_std_out,'(1X,A,F10.4)') 'b  - upper limit of integration = ', b

      CALL nag_quad_1d_wt_end_sing(g1,a,b,alpha1,beta1,log_wt,result1)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,F10.4)') &
       'alpha1  - parameter in the first weight function = ', alpha1
      WRITE (nag_std_out,'(1X,A,F10.4)') &
       'beta1  - parameter in the first weight function  = ', beta1
      WRITE (nag_std_out,'(1X,A,F9.5)') &
       'result1 - approximation to the first integral =', result1

      alpha2 = -0.5_wp
      beta2 = -0.5_wp
      log_wt = 'none'

      CALL nag_quad_1d_wt_end_sing(g2,a,b,alpha2,beta2,log_wt,result2)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,F10.4)') &
       'alpha2  - parameter in the second weight function = ', alpha2
      WRITE (nag_std_out,'(1X,A,F10.4)') &
       'beta2  - parameter in the second weight function  = ', beta2
      WRITE (nag_std_out,'(1X,A,F9.5)') &
       'result2 - approximation to the second integral =', result2

    END PROGRAM nag_quad_1d_ex03
