    PROGRAM g01fmfe

!      G01FMF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01fmf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: p, v, valq
       INTEGER                         :: ifail, ir
!      .. Executable Statements ..
       WRITE (nout,*) 'G01FMF Example Program Results'
       WRITE (nout,*)

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

!      Display titles
       WRITE (nout,*) '  P     V    IR    Quantile '
       WRITE (nout,*)

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

!         Compute deviate
          ifail = -1
          valq = g01fmf(p,v,ir,ifail)
          IF (ifail/=0) THEN
             IF (ifail/=3) THEN
                EXIT D_LP
             END IF
          END IF

!         Display results
          WRITE (nout,99999) p, v, ir, valq
       END DO D_LP

99999  FORMAT (1X,F5.2,2X,F4.1,1X,I3,1X,F10.4)
    END PROGRAM g01fmfe
