    PROGRAM g01fefe

!      G01FEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

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

!      Display titles
       WRITE (nout,*) ' Probability     A         B     Deviate'
       WRITE (nout,*)

!      Use default tolerance
       tol = 0.0E0_nag_wp

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

!         Calculate deviates (inverse CDF)
          ifail = -1
          x = g01fef(p,a,b,tol,ifail)
          IF (ifail/=0) THEN
             IF (ifail/=3 .AND. ifail/=4) THEN
                EXIT D_LP
             END IF
          END IF

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

99999  FORMAT (1X,F9.4,2F10.3,F10.4,A,I1)
    END PROGRAM g01fefe
