    PROGRAM g05pafe

!      G05PAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kbf, g05paf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: ip = 2, iq = 0, n = 10, nout = 6
       INTEGER, PARAMETER              :: nr = ip + iq + 5 + ip
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: avar, var, xmean
       INTEGER                         :: i, ifail, igen, mode
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: phi(ip), r(nr), theta(1), x(n)
       INTEGER                         :: iseed(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05PAF Example Program Results'
       WRITE (nout,*)
!      Set the ARMA model parameters
       xmean = 0.0E0_nag_wp
       phi(1) = 0.4E0_nag_wp
       phi(2) = 0.2E0_nag_wp
       avar = 1.0E0_nag_wp
!      Initialize the seed to a repeatable sequence
       iseed(1) = 1762543
       iseed(2) = 9324783
       iseed(3) = 4234401
       iseed(4) = 742355
!      IGEN identifies the stream.
       igen = 1
       CALL g05kbf(igen,iseed)
       mode = 0
       ifail = -1
!      Set up the reference vector
       CALL g05paf(mode,xmean,ip,phi,iq,theta,avar,var,n,x,igen,iseed,r,nr, &
          ifail)
       IF (ifail==0) THEN
          mode = 1
!         Generate a sample of 10 observations
          ifail = -1
          CALL g05paf(mode,xmean,ip,phi,iq,theta,avar,var,n,x,igen,iseed,r,nr, &
             ifail)
          IF (ifail==0) THEN
             DO i = 1, n
                WRITE (nout,99999) x(i)
             END DO
          END IF
       END IF

99999  FORMAT (1X,F12.4)
    END PROGRAM g05pafe
