    PROGRAM g01fafe

!      G01FAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01faf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: dev, p
       INTEGER                         :: ifail
       CHARACTER (1)                   :: tail
!      .. Executable Statements ..
       WRITE (nout,*) 'G01FAF Example Program Results'
       WRITE (nout,*)

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

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

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

!         Calculate the deviate (inverse CDF)
          ifail = 0
          dev = g01faf(tail,p,ifail)

!         Display results
          WRITE (nout,99999) tail, p, dev
       END DO D_LP

99999  FORMAT (3X,A1,8X,F6.3,8X,F7.4)
    END PROGRAM g01fafe
