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

    MODULE g05yhfe_mod

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

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER                  :: n = 2, nout = 6
    CONTAINS
!dec$ attributes offload : mic :: fun
       FUNCTION fun(idim,x,n)

!         .. Implicit None Statement ..
          IMPLICIT NONE
!         .. Function Return Value ..
          REAL (KIND=nag_wp)                  :: fun
!         .. Scalar Arguments ..
          INTEGER, INTENT (IN)                :: idim, n
!         .. Array Arguments ..
          REAL (KIND=nag_wp), INTENT (IN)     :: x(2,idim)
!         .. Local Scalars ..
          REAL (KIND=nag_wp)                  :: tmp, tmp1
          INTEGER                             :: j
!         .. Intrinsic Functions ..
          INTRINSIC                              abs
!         .. Executable Statements ..
          tmp = 1.0E0_nag_wp
          tmp1 = 1.0E0_nag_wp
          DO j = 1, idim
             tmp = tmp*abs(4.0E0_nag_wp*x(1,j)-2.0E0_nag_wp)
             tmp1 = tmp1*abs(4.0E0_nag_wp*x(2,j)-2.0E0_nag_wp)
          END DO
          fun = tmp + tmp1
          RETURN
!dec$ attributes offload : mic :: fun
       END FUNCTION fun
    END MODULE g05yhfe_mod
    PROGRAM g05yhfe

!      G05YHF Example Main Program

!      .. Use Statements ..
       USE nag_library, ONLY : g05ygf, g05yhf, nag_wp
       USE g05yhfe_mod, ONLY : fun, n, nout
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Local Scalars ..
       REAL (KIND=nag_wp)                  :: sum, vsbl
       INTEGER                             :: i, idim, ifail, iskip, ntimes
!      .. Local Arrays ..
       REAL (KIND=nag_wp)                  :: quasi(n,6)
       INTEGER                             :: iref(2000)
!      .. Intrinsic Functions ..
       INTRINSIC                              real
!      .. Executable Statements ..
       WRITE (nout,*) 'G05YHF Example Program Results'
       idim = 6
       ntimes = 5000
       ifail = 0
       iskip = 0

       CALL g05ygf(idim,iref,iskip,ifail)

       IF (ifail>=0) THEN
          sum = 0.0E0_nag_wp
          DO i = 1, ntimes

             CALL g05yhf(n,quasi,iref,ifail)

             sum = sum + fun(idim,quasi,n)
          END DO
          vsbl = sum/real(2*ntimes,kind=nag_wp)
          WRITE (nout,99999)
          WRITE (nout,99999) 'Value of integral = ', vsbl
       END IF

99999  FORMAT (1X,A,F8.4)
    END PROGRAM g05yhfe
