    Program g01fbfe

!     G01FBF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g01fbf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: df, p, x
      Integer                          :: ifail
      Character (1)                    :: tail
!     .. Executable Statements ..
      Write (nout,*) 'G01FBF Example Program Results'
      Write (nout,*)

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

!     Display titles
      Write (nout,*) '     P      DF    TAIL      X'
      Write (nout,*)

d_lp: Do
        Read (nin,*,Iostat=ifail) p, df, tail
        If (ifail/=0) Then
          Exit d_lp
        End If

!       Calculate deviates (inverse CDF)
        ifail = -1
        x = g01fbf(tail,p,df,ifail)
        If (ifail/=0) Then
          If (ifail/=4 .And. ifail/=5) Then
            Exit d_lp
          End If
        End If

!       Display results 
        Write (nout,99999) p, df, tail, x
      End Do d_lp

99999 Format (1X,2F8.3,3X,A1,3X,F8.3,A,I1)
    End Program g01fbfe
