    PROGRAM g13bcfe

!      G13BCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g13bcf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: r0xy, r0yx, statxy, statyx, sxy, syx
       INTEGER                         :: i, ifail, nl, nxy
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: rxy(:), ryx(:), x(:), y(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G13BCF Example Program Results'
       WRITE (nout,*)

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

!      Read series length and number of lags
       READ (nin,*) nxy, nl

       ALLOCATE (x(nxy),y(nxy),rxy(nl),ryx(nl))

!      Read series
       READ (nin,*) x(1:nxy)
       READ (nin,*) y(1:nxy)

!      Call routine to calculate cross correlations between X and Y
       ifail = 0
       CALL g13bcf(x,y,nxy,nl,sxy,r0xy,rxy,statxy,ifail)

!      Call routine to calculate cross correlations between Y and X
       ifail = 0
       CALL g13bcf(y,x,nxy,nl,syx,r0yx,ryx,statyx,ifail)

!      Display results
       WRITE (nout,*) '                           Between        Between'
       WRITE (nout,*) '                           X and Y        Y and X'
       WRITE (nout,*)
       WRITE (nout,99999) 'Standard deviation ratio', sxy, syx
       WRITE (nout,*)
       WRITE (nout,*) 'Cross correlation at lag'
       WRITE (nout,99999) '                       0', r0xy, r0yx
       WRITE (nout,99998) (i,rxy(i),ryx(i),i=1,nl)
       WRITE (nout,*)
       WRITE (nout,99997) 'Test statistic          ', statxy, statyx

99999  FORMAT (1X,A,F10.4,F15.4)
99998  FORMAT (21X,I4,F10.4,F15.4)
99997  FORMAT (1X,A,F10.4,F15.4)
    END PROGRAM g13bcfe
