    PROGRAM nag_tsa_spectral_ex06

      ! Example Program Text for nag_tsa_spectral
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_tsa_spectral, ONLY : nag_spectral_cov
      USE nag_examples_io, ONLY : nag_std_out, nag_std_in
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, l, m, n
      REAL (wp) :: tap
      CHARACTER (1) :: method
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: cov(:), f(:)
      REAL (wp) :: stats(4)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_tsa_spectral_ex06'

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) m, l, n
      READ (nag_std_in,*) tap
      READ (nag_std_in,*) method

      ALLOCATE (cov(m),f(l))       ! Allocate storage

      READ (nag_std_in,*) cov

      CALL nag_spectral_cov(method,cov,f,tap=tap,n=n,stats=stats)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,F4.1,A,F7.4)') 'Degrees of freedom = ', &
       stats(1), '        Bandwidth = ', stats(4)
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,F7.4,A,F7.4)') &
       '95 percent confidence limits -   Lower = ', stats(2), '   Upper = ', &
       stats(3)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) &
       '       Spectrum       Spectrum       Spectrum       Spectrum'
      WRITE (nag_std_out,*) &
       '       estimate       estimate       estimate       estimate'
      WRITE (nag_std_out,'((1X,4(I5,F10.3)))') (i,f(i),i=1,l)

      DEALLOCATE (cov,f)           ! Deallocate storage

    END PROGRAM nag_tsa_spectral_ex06
