    PROGRAM g13acfe

!      G13ACF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13acf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, nk, nl, nvl
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: ar(:), p(:), r(:), v(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13ACF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) nk, nl

       ALLOCATE (ar(nl),p(nl),r(nk),v(nl))

!      Read in data
       READ (nin,*) (r(i),i=1,nk)

!      Calculate partial ACF
       ifail = -1
       CALL g13acf(r,nk,nl,p,v,ar,nvl,ifail)
       IF (ifail/=0) THEN
          IF (ifail==3) THEN
             WRITE (nout,99999) '   Only', nvl, 'valid sets were generated'
             WRITE (nout,*)
          ELSE
             GO TO 20
          END IF
       END IF

!      Display results
       WRITE (nout,*) 'Lag  Partial    Predictor error  Autoregressive'
       WRITE (nout,*) '     autocorrn  variance ratio' // '   parameter'
       WRITE (nout,*)
       WRITE (nout,99998) (i,p(i),v(i),ar(i),i=1,nvl)

20     CONTINUE

99999  FORMAT (1X,A,I2,A)
99998  FORMAT (1X,I2,F9.3,F16.3,F14.3)
    END PROGRAM g13acfe
