    PROGRAM s14bafe

!      S14BAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, s14baf, x02ajf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: a, p, q, tol, x
       INTEGER                         :: ifail, ioerr
!      .. Executable Statements ..
       WRITE (nout,*) 'S14BAF Example Program Results'

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

       WRITE (nout,*)
       WRITE (nout,*) '         A           X           P           Q'

       tol = x02ajf()

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

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = 0
          CALL s14baf(a,x,tol,p,q,ifail)

          WRITE (nout,99999) a, x, p, q
       END DO DATA

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