PROGRAM g13abfe

!      G13ABF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13abf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: stat, xm, xv
       INTEGER                         :: i, ifail, nk, nx
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: r(:), x(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13ABF Example Program Results'
       WRITE (nout,*)

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

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

       ALLOCATE (x(nx),r(nk))

!      Read in data
       READ (nin,*) x(1:nx)

!      Compute autocorrelation
       ifail = 0
       CALL g13abf(x,nx,nk,xm,xv,r,stat,ifail)

!      Display results
       WRITE (nout,99999) 'The first ', nk, ' coefficients are required'
       WRITE (nout,99998) 'The input array has sample mean ', xm
       WRITE (nout,99998) 'The input array has sample variance ', xv
       WRITE (nout,*) 'The sample autocorrelation coefficients are'
       WRITE (nout,*)
       WRITE (nout,*) '   Lag    Coeff      Lag    Coeff'
       WRITE (nout,99997) (i,r(i),i=1,nk)
       WRITE (nout,*)
       WRITE (nout,99998) 'The value of STAT is ', stat

99999  FORMAT (1X,A,I2,A)
99998  FORMAT (1X,A,F12.4)
99997  FORMAT (1X,I6,F10.4,I8,F10.4)
    END PROGRAM g13abfe