    Program g13abfe

!     G13ABF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
