    PROGRAM s18cdfe

!      S18CDF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

       WRITE (nout,*)
       WRITE (nout,*) '     X           Y'
       WRITE (nout,*)

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

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = -1
          y = s18cdf(x,ifail)

          IF (ifail<0) THEN
             EXIT DATA
          END IF

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

99999  FORMAT (1X,1P,2E12.3)
    END PROGRAM s18cdfe
