    PROGRAM g01fdfe

!      G01FDF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01fdf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: df1, df2, f, p
       INTEGER                         :: ifail
!      .. Executable Statements ..
       WRITE (nout,*) 'G01FDF Example Program Results'
       WRITE (nout,*)

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

!      Display titles
       WRITE (nout,*) '     P      DF1     DF2      F'
       WRITE (nout,*)

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

!         Calculate deviates (inverse CDF)
          ifail = -1
          f = g01fdf(p,df1,df2,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, df1, df2, f
       END DO D_LP

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