    PROGRAM nag_tsa_spectral_ex01

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

      ! .. Use Statements ..
      USE nag_tsa_spectral, ONLY : nag_spectral_data, 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
      CHARACTER (1) :: method
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: cov(:), f(:), ts(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_tsa_spectral_ex01'

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

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

      READ (nag_std_in,*) ts
      method = 'p'

      CALL nag_spectral_data(method,ts,m,f,cov=cov)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) ' Results using the time series data'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,I3)') &
       'Frequency width of smoothing window = 1/', m

      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)

      CALL nag_spectral_cov(method,cov,f)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) ' Results using the time series auto-covariance'
      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 (ts,f,cov)        ! Deallocate storage

    END PROGRAM nag_tsa_spectral_ex01
