    PROGRAM g01mufe

!      G01MUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01muf, g01zuf, nag_wp, x02alf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: mode = 0, nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: beta2, c1, c2, rkappa, x, xl, xu, y
       INTEGER                         :: ifail
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: rcomm(322)
!      .. Executable Statements ..
       WRITE (nout,*) 'G01MUF Example Program Results'
       WRITE (nout,*)

!      Skip heading in data file
       READ (nin,*)
       c1 = -x02alf()
       c2 = -x02alf()

!      Display titles
       WRITE (nout,*) '  X     RKAPPA    BETA2        Y        IFAIL'
       WRITE (nout,*)

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

          IF ((rkappa/=c1) .OR. (beta2/=c2)) THEN
!            Initialise the RCOMM array if RKAPPA or BETA2 has changed
             ifail = 0
             CALL g01zuf(rkappa,beta2,mode,xl,xu,rcomm,ifail)
          END IF

!         Compute the value of the Vavilov density function
          ifail = 0
          y = g01muf(x,rcomm,ifail)

!         Display results
          WRITE (nout,99999) x, rkappa, beta2, y, ifail
          c1 = rkappa
          c2 = beta2
       END DO D_LP

99999  FORMAT (1X,F4.1,5X,F4.1,5X,F4.1,3X,1P,E12.4,I6)
    END PROGRAM g01mufe
