    PROGRAM nag_tsa_spectral_ex10

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

      ! .. Use Statements ..
      USE nag_tsa_spectral, ONLY : nag_bivar_spectral_lin_sys
      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, n
      REAL (wp) :: rfse
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: arf(:), crf(:), f_x(:), f_y(:), ns(:), &
       ns_bounds(:,:)
      REAL (wp) :: stats(4)
      COMPLEX (wp), ALLOCATABLE :: f_xy(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_tsa_spectral_ex10'

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

      ALLOCATE (f_x(l),f_y(l),f_xy(l),ns(l),ns_bounds(l,2),crf(l), &
       arf(l-2))                   ! Allocate storage

      READ (nag_std_in,*) stats
      READ (nag_std_in,*) f_x
      READ (nag_std_in,*) f_y
      READ (nag_std_in,*) f_xy

      CALL nag_bivar_spectral_lin_sys(f_x,f_y,f_xy,stats,n,ns=ns, &
       ns_bounds=ns_bounds,crf=crf,arf=arf,rfse=rfse)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) '                     Noise spectrum'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) &
       '                               Lower           Upper'
      WRITE (nag_std_out,*) &
       '               Value           bound           bound'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,I5,3F16.4)') (i-1,ns(i),ns_bounds(i,:),i=1,l)
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) '    Impulse causal response function'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,I5,F16.4)') (i-1,crf(i),i=1,l)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) '    Impulse anticipatory response function'
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,I5,F16.4)') (i-1,arf(i),i=1,l-2)
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,A,F10.4,A,F10.4)') &
       '    Impulse response function standard error =', rfse
      WRITE (nag_std_out,*)

      DEALLOCATE (f_x,f_y,f_xy,ns,ns_bounds,crf,arf) ! Deallocate storage

    END PROGRAM nag_tsa_spectral_ex10
