    PROGRAM g13ccfe

!      G13CCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13ccf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: pxy
       INTEGER                         :: i, ic, ifail, ii, ish, iw, kc, l,    &
                                          lxg, lyg, mtxy, mw, nc, ng, nxy, nxyg
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: cxy(:), cyx(:), xg(:), yg(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          max, min
!      .. Executable Statements ..
       WRITE (nout,*) 'G13CCF Example Program Results'
       WRITE (nout,*)

!      Skip heading in data file
       READ (nin,*)

!      Read in the problem size
       READ (nin,*) nxy, nc, ic

!      Read in control parameters
       READ (nin,*) mtxy, pxy
       READ (nin,*) iw, mw
       READ (nin,*) ish, kc, l

       IF (ic==0) THEN
          nxyg = max(kc,l)
       ELSE
          nxyg = l
       END IF
       lxg = max(nxyg,nxy)
       lyg = max(nxyg,nxy)
       ALLOCATE (xg(lxg),yg(lyg),cxy(nc),cyx(nc))

       IF (ic==0) THEN
          READ (nin,*) (xg(i),i=1,nxy)
          READ (nin,*) (yg(i),i=1,nxy)
       ELSE
          READ (nin,*) (cxy(i),i=1,nc)
          READ (nin,*) (cyx(i),i=1,nc)
       END IF

       ifail = 0
       CALL g13ccf(nxy,mtxy,pxy,iw,mw,ish,ic,nc,cxy,cyx,kc,l,nxyg,xg,yg,ng, &
          ifail)

!      Display results
       WRITE (nout,*) '                  Returned cross covariances'
       WRITE (nout,*)
       WRITE (nout,*) &
          'Lag     XY       YX   Lag     XY       YX   Lag     XY       YX'
       DO i = 1, nc, 3
          WRITE (nout,99999) (ii-1,cxy(ii),cyx(ii),ii=i,min(i+2,nc))
       END DO
       WRITE (nout,*)
       WRITE (nout,*) '                      Returned sample spectrum'
       WRITE (nout,*)
       WRITE (nout,*) '       Real  Imaginary       Real  Imaginary &
          &      Real  Imaginary'
       WRITE (nout,*) &
          'Lag    part     part  Lag    part     part  Lag    part     part'
       DO i = 1, ng, 3
          WRITE (nout,99999) (ii-1,xg(ii),yg(ii),ii=i,min(i+2,ng))
       END DO

99999  FORMAT (1X,I3,2F9.4,I4,2F9.4,I4,2F9.4)
    END PROGRAM g13ccfe
