    PROGRAM c05bbfe

!      C05BBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

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

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

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

       WRITE (nout,*)
       WRITE (nout,99999)
       WRITE (nout,*)

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

          IF (ioerr<0) THEN
             EXIT DATA
          END IF

          ifail = -1
          CALL c05bbf(branch,offset,z,w,resid,ifail)

          IF (ifail<0) THEN
             EXIT DATA
          END IF

          WRITE (nout,99998) z, w, resid, ifail
       END DO DATA

99999  FORMAT (1X,14X,'Z',28X,'W(Z)',18X,'RESID',4X,'IFAIL')
99998  FORMAT (1X,1P,2('(',E13.5,',',E13.5,')',1X),E13.5,1X,I5)
99997  FORMAT (1X,A,I3)
99996  FORMAT (1X,A)
    END PROGRAM c05bbfe
