!   C05AUF Example Program Text
!   Mark 26.1 Release. NAG Copyright 2016.

    Module c05aufe_mod

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

!     .. Use Statements ..
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Accessibility Statements ..
      Private
      Public                           :: f
!     .. Parameters ..
      Integer, Parameter, Public       :: nout = 6
    Contains
      Function f(x,iuser,ruser)

!       .. Function Return Value ..
        Real (Kind=nag_wp)             :: f
!       .. Scalar Arguments ..
        Real (Kind=nag_wp), Intent (In) :: x
!       .. Array Arguments ..
        Real (Kind=nag_wp), Intent (Inout) :: ruser(*)
        Integer, Intent (Inout)        :: iuser(*)
!       .. Intrinsic Procedures ..
        Intrinsic                      :: exp
!       .. Executable Statements ..
        f = x - exp(-x)

        Return

      End Function f
    End Module c05aufe_mod
    Program c05aufe

!     C05AUF Example Main Program

!     .. Use Statements ..
      Use c05aufe_mod, Only: f, nout
      Use nag_library, Only: c05auf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: a, b, eps, eta, h, x
      Integer                          :: ifail
!     .. Local Arrays ..
      Real (Kind=nag_wp)               :: ruser(1)
      Integer                          :: iuser(1)
!     .. Executable Statements ..
      Write (nout,*) 'C05AUF Example Program Results'

      x = 1.0E0_nag_wp
      h = 0.1E0_nag_wp
      eps = 1.0E-5_nag_wp
      eta = 0.0E0_nag_wp

      ifail = -1
      Call c05auf(x,h,eps,eta,f,a,b,iuser,ruser,ifail)

      Write (nout,*)

      Select Case (ifail)
      Case (0)
        Write (nout,99999) 'Root is ', x
        Write (nout,99998) 'Interval searched is [', a, ',', b, ']'
      Case (3,4)
        Write (nout,99999) 'Final value = ', x
      End Select

99999 Format (1X,A,F13.5)
99998 Format (1X,A,2(F8.5,A))
    End Program c05aufe