NAG Library Manual, Mark 28.3
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program c05axfe

!     C05AXF Example Program Text

!     Mark 28.3 Release. NAG Copyright 2022.

!     .. Use Statements ..
      Use nag_library, Only: c05axf, nag_wp, x02ajf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: fx, scal, tol, x
      Integer                          :: i, ifail, ind, ir
!     .. Local Arrays ..
      Real (Kind=nag_wp)               :: c(26)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: exp, sqrt
!     .. Executable Statements ..
      Write (nout,*) 'C05AXF Example Program Results'

      scal = sqrt(x02ajf())
      ir = 0

loop: Do i = 3, 4
        tol = 10.0E0_nag_wp**(-i)
        Write (nout,*)
        Write (nout,99999) 'TOL =', tol
        Write (nout,*)
        x = 1.0E0_nag_wp
        ind = 1
        ifail = -1

revcomm: Do
          Call c05axf(x,fx,tol,ir,scal,c,ind,ifail)

          If (ind==0) Then
            Exit revcomm
          End If

          fx = x - exp(-x)
        End Do revcomm

        Select Case (ifail)
        Case (:-1)
          Exit loop
        Case (4,6)
          Write (nout,99998) 'Final value = ', x, ' THETA = ', c(5)
        Case (0)
          Write (nout,99998) 'Root is ', x
        End Select

      End Do loop

99999 Format (1X,A,E11.4)
99998 Format (1X,A,F14.5,A,F10.2)
    End Program c05axfe