    PROGRAM g05mrfe

!      G05MRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kbf, g05mrf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: k = 4, n = 20, nout = 6, nr = 6007
       INTEGER, PARAMETER              :: ldx = n
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, igen, j, m
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: p(k), r(nr)
       INTEGER                         :: iseed(4), x(ldx,k)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05MRF Example Program Results'
       WRITE (nout,*)
!      Set the distribution parameters P and M
       p(1) = 0.08E0_nag_wp
       p(2) = 0.1E0_nag_wp
       p(3) = 0.8E0_nag_wp
       p(4) = 0.02E0_nag_wp
       m = 6000
!      Initialize the seed to a repeatable sequence
       iseed(1) = 1762543
       iseed(2) = 9324783
       iseed(3) = 42344
       iseed(4) = 742355
!      IGEN identifies the stream.
       igen = 1
       CALL g05kbf(igen,iseed)
!      Choose MODE = 2
       ifail = 1
       CALL g05mrf(2,m,k,p,n,x,ldx,igen,iseed,r,nr,ifail)

       IF (ifail==0) THEN

          DO i = 1, n
             WRITE (nout,99999) (x(i,j),j=1,k)
          END DO

       ELSE
          WRITE (nout,99998) ifail
       END IF

99999  FORMAT (1X,10(1X,I12))
99998  FORMAT (1X,' ** G05MRF returned with IFAIL = ',I5)
    END PROGRAM g05mrfe
