    PROGRAM g05mbfe

!      G05MBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kbf, g05mbf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: n = 10, nout = 6, nr = 40000
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: p
       INTEGER                         :: ifail, igen
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: r(nr)
       INTEGER                         :: iseed(4), x(n)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05MBF Example Program Results'
       WRITE (nout,*)
!      Set the distribution parameter P
       p = 0.001E0_nag_wp
!      Initialize the seed to a repeatable sequence
       iseed(1) = 1762543
       iseed(2) = 9324783
       iseed(3) = 423441
       iseed(4) = 742355
!      IGEN identifies the stream.
       igen = 1
       CALL g05kbf(igen,iseed)
!      Choose MODE = 3 because P is close to 0
       ifail = 1
       CALL g05mbf(3,p,n,x,igen,iseed,r,nr,ifail)

       IF (ifail==0) THEN

          WRITE (nout,99999) x

       ELSE
          WRITE (nout,99998) ifail
       END IF

99999  FORMAT (1X,I12)
99998  FORMAT (1X,' ** G05MBF returned with IFAIL = ',I5)
    END PROGRAM g05mbfe
