    Program g01fmfe

!     G01FMF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
