    PROGRAM g01gefe

!      G01GEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01gef, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: a, b, prob, rlamda, tol, x
       INTEGER                         :: ifail, maxit
!      .. Executable Statements ..
       WRITE (nout,*) 'G01GEF Example Program Results'
       WRITE (nout,*)

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

!      Display titles
       WRITE (nout,*) '     X       A       B    RLAMDA   PROB'
       WRITE (nout,*)

!      Use default tolerance
       tol = 0.0E0_nag_wp
       maxit = 100

D_LP:  DO
          READ (nin,*,IOSTAT=ifail) x, a, b, rlamda
          IF (ifail/=0) THEN
             EXIT D_LP
          END IF

!         Calculate probability
          ifail = -1
          prob = g01gef(x,a,b,rlamda,tol,maxit,ifail)
          IF (ifail/=0) THEN
             IF (ifail<3) THEN
                EXIT D_LP
             END IF
          END IF

!         Display results
          WRITE (nout,99999) x, a, b, rlamda, prob
       END DO D_LP

99999  FORMAT (1X,4F8.3,F8.4,A,I1)
    END PROGRAM g01gefe
