    MODULE quad_1d_ex07_mod

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

    CONTAINS

      FUNCTION f(x)

        ! .. Implicit None Statement ..
        IMPLICIT NONE
        ! .. Intrinsic Functions ..
        INTRINSIC ABS, SIZE, SQRT
        ! .. Array Arguments ..
        REAL (wp), INTENT (IN) :: x(:)
        ! .. Function Return Value ..
        REAL (wp) :: f(SIZE(x))
        ! .. Local Arrays ..
        REAL (wp) :: a(SIZE(x))
        ! .. Executable Statements ..
        a = ABS(x-1.0_wp/7.0_wp)

        WHERE (a==0.0_wp)
          f = 0.0_wp
        ELSEWHERE
          f = 1.0_wp/(SQRT(a))
        END WHERE

      END FUNCTION f

    END MODULE quad_1d_ex07_mod

    PROGRAM nag_quad_1d_ex07

      ! 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_quad_1d, ONLY : nag_quad_1d_gen
      USE quad_1d_ex07_mod, ONLY : wp, f
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Parameters ..
      INTEGER, PARAMETER :: n = 1
      ! .. Local Scalars ..
      REAL (wp) :: a, b, result
      ! .. Local Arrays ..
      REAL (wp) :: brk_pts(n)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_quad_1d_ex07'

      a = 0.0_wp
      b = 1.0_wp
      brk_pts(1) = 1.0_wp/7.0_wp

      CALL nag_quad_1d_gen(f,a,b,result,brk_pts=brk_pts)

      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
      WRITE (nag_std_out,'(1X,A,F10.4)') &
       'brk_pts(1) - given break-point = ', brk_pts(1)
      WRITE (nag_std_out,'(1X,A,F9.5)') &
       'result - approximation to the integral =', result

    END PROGRAM nag_quad_1d_ex07
