    PROGRAM s14acfe

!      S14ACF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, s14acf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: f, x
       INTEGER                         :: ifail, ioerr
!      .. Executable Statements ..
       WRITE (nout,*) 'S14ACF Example Program Results'

!      Skip heading in data file
       READ (nin,*)

       WRITE (nout,*)
       WRITE (nout,*) '       X        psi(X)-log(X)'
       WRITE (nout,*)

DATA:  DO
          READ (nin,*,IOSTAT=ioerr) x

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = -1
          f = s14acf(x,ifail)

          IF (ifail<0) THEN
             EXIT DATA
          END IF

          WRITE (nout,99999) x, f
       END DO DATA

99999  FORMAT (1X,F12.4,F15.4)
    END PROGRAM s14acfe
