    PROGRAM x05bafe

!      X05BAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x05baf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nout = 6
       INTEGER, PARAMETER              :: nterms = 10**7
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: cptime, h, s1, s2
       INTEGER                         :: n
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'X05BAF Example Program Results'

       s1 = x05baf()

!      Do a non-trivial amount of intermediate work.

       h = 0.0_nag_wp

       DO n = nterms, 1, -1
          h = h + 1.0_nag_wp/real(n,kind=nag_wp)
       END DO

       s2 = x05baf()

       cptime = s2 - s1
       WRITE (nout,99999) 'It took', cptime, ' seconds to compute', nterms, &
          ' terms of the harmonic series.', 'Value of partial sum =', h, '.'

99999  FORMAT (1X,A,1P,E10.2,A/1X,I8,A/1X,A,E13.5,A)
    END PROGRAM x05bafe
