    PROGRAM nag_tsa_spectral_ex07

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

      ! .. Use Statements ..
      USE nag_tsa_spectral, ONLY : nag_bivar_spectral_data
      USE nag_examples_io, ONLY : nag_std_out, nag_std_in
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC AIMAG, KIND, REAL
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, k, l, m, n, ne, s
      REAL (wp) :: tap
      CHARACTER (1) :: correc, method
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: xy_cov(:), x_ts(:), yx_cov(:), y_ts(:)
      COMPLEX (wp), ALLOCATABLE :: f_xy(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_tsa_spectral_ex07'

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

      ALLOCATE (x_ts(n),y_ts(n),xy_cov(k),yx_cov(k), &
       f_xy(l))                    ! Allocate storage

      READ (nag_std_in,*) x_ts
      READ (nag_std_in,*) y_ts

      CALL nag_bivar_spectral_data(method,x_ts,y_ts,m,f_xy,s=s,correc=correc, &
       tap=tap,ne=ne,xy_cov=xy_cov,yx_cov=yx_cov)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) '                 Returned cross covariances'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) &
       ' Lag    XY       YX    Lag    XY       YX    Lag    XY       YX'
      WRITE (nag_std_out,'((3(I4,2F9.4)))') (i-1,xy_cov(i),yx_cov(i),i=1,k)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) '                 Returned sample spectrum'
      WRITE (nag_std_out,*) &
       '       Real  Imaginary       Real  Imaginary       Real  Imaginary'
      WRITE (nag_std_out,*) &
       ' Lag   part     part   Lag   part     part   Lag   part     part'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'((3(I4,2F9.4)))') (i-1,REAL(f_xy(i)),AIMAG(f_xy(i)), &
       i=1,l)

      DEALLOCATE (x_ts,y_ts,xy_cov,yx_cov,f_xy) ! Deallocate storage

    END PROGRAM nag_tsa_spectral_ex07
