!   E04ABA Example Program Text
!   Mark 23 Release. NAG Copyright 2011.
    MODULE e04abae_mod

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

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER                  :: nout = 6
    CONTAINS
!dec$ attributes offload : mic :: funct
       SUBROUTINE funct(xc,fc,iuser,ruser)
!         Routine to evaluate F(x) at any point in (A, B)

!         .. Implicit None Statement ..
          IMPLICIT NONE
!         .. Scalar Arguments ..
          REAL (KIND=nag_wp), INTENT (OUT)    :: fc
          REAL (KIND=nag_wp), INTENT (IN)     :: xc
!         .. Array Arguments ..
          REAL (KIND=nag_wp), INTENT (INOUT)  :: ruser(*)
          INTEGER, INTENT (INOUT)             :: iuser(*)
!         .. Intrinsic Functions ..
          INTRINSIC                              sin
!         .. Executable Statements ..
          fc = sin(xc)/xc

          RETURN

!dec$ attributes offload : mic :: funct
       END SUBROUTINE funct
    END MODULE e04abae_mod
    PROGRAM e04abae

!      E04ABA Example Main Program

!      .. Use Statements ..
       USE nag_library, ONLY : e04aba, nag_wp
       USE e04abae_mod, ONLY : funct, nout
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Local Scalars ..
       REAL (KIND=nag_wp)                  :: a, b, e1, e2, f, x
       INTEGER                             :: ifail, maxcal
!      .. Local Arrays ..
       REAL (KIND=nag_wp)                  :: ruser(1)
       INTEGER                             :: iuser(1)
!      .. Executable Statements ..
       WRITE (nout,*) 'E04ABA Example Program Results'

!      E1 and E2 are set to zero so that E04ABA will reset them to
!      their default values

       e1 = 0.0_nag_wp
       e2 = 0.0_nag_wp

!      The minimum is known to lie in the range (3.5, 5.0)

       a = 3.5_nag_wp
       b = 5.0_nag_wp

!      Allow 30 calls of FUNCT

       maxcal = 30

       ifail = -1
       CALL e04aba(funct,e1,e2,a,b,maxcal,x,f,iuser,ruser,ifail)

       SELECT CASE (ifail)
       CASE (0,2)
          WRITE (nout,*)
          WRITE (nout,99999) 'The minimum lies in the interval', a, ' to', b
          WRITE (nout,99999) 'Its estimated position is', x, ','
          WRITE (nout,99998) 'where the function value is ', f
          WRITE (nout,99997) maxcal, 'function evaluations were required'
       END SELECT

99999  FORMAT (1X,A,F11.8,A,F11.8)
99998  FORMAT (1X,A,F7.4)
99997  FORMAT (1X,I2,1X,A)
    END PROGRAM e04abae
