    PROGRAM g01mbfe

!      G01MBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : a00acf, g01mbf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: rm, x, xmu, xsig, z
       INTEGER                         :: ifail
!      .. Executable Statements ..
       WRITE (nout,*) 'G01MBF Example Program Results '
       WRITE (nout,*)

!      Check for valid licence prior to calling G01MBF
       IF ( .NOT. a00acf()) THEN
          WRITE (nout,*) ' ** A valid licence key was not found'

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

!         Display titles
          WRITE (nout,*) ' Mean     Sigma    X        Reciprocal'
          WRITE (nout,*) '                            Mills Ratio'
          WRITE (nout,*)

D_LP:     DO
             READ (nin,*,IOSTAT=ifail) x, xmu, xsig
             IF (ifail/=0) THEN
                EXIT D_LP
             END IF

             z = (x-xmu)/xsig
             rm = g01mbf(z)/xsig

!            Display results
             WRITE (nout,99999) xmu, xsig, x, rm
          END DO D_LP
       END IF

99999  FORMAT (1X,4(F7.4,2X))
    END PROGRAM g01mbfe
