    PROGRAM c05bafe

!      C05BAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

       READ (nin,*) branch
       READ (nin,*) offset

       WRITE (nout,*)
       WRITE (nout,99998) 'BRANCH = ', branch

       IF (offset) THEN
          WRITE (nout,99997) 'OFFSET = .TRUE.'
       ELSE
          WRITE (nout,99997) 'OFFSET = .FALSE.'
       END IF

       WRITE (nout,*)
       WRITE (nout,*) '        X           W(X)     IFAIL'
       WRITE (nout,*)

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

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = -1
          w = c05baf(x,branch,offset,ifail)

          IF (ifail<0) THEN
             EXIT DATA
          END IF

          WRITE (nout,99999) x, w, ifail
       END DO DATA

99999  FORMAT (1X,1P,2(1X,E13.5),1X,I5)
99998  FORMAT (1X,A,I3)
99997  FORMAT (1X,A)
    END PROGRAM c05bafe
