    Program c06ekfe

!     C06EKF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: c06ekf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: ieof, ifail, j, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: xa(:), xb(:), ya(:), yb(:)
!     .. Executable Statements ..
      Write (nout,*) 'C06EKF Example Program Results'
!     Skip heading in data file
      Read (nin,*)
loop: Do
        Read (nin,*,Iostat=ieof) n
        If (ieof<0) Exit loop
        Allocate (xa(0:n-1),xb(0:n-1),ya(0:n-1),yb(0:n-1))
        Read (nin,*)(xa(j),ya(j),j=0,n-1)
        xb(0:n-1) = xa(0:n-1)
        yb(0:n-1) = ya(0:n-1)

!       ifail: behaviour on error exit   
!              =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
        ifail = 0
        Call c06ekf(1,xa,ya,n,ifail)

        Call c06ekf(2,xb,yb,n,ifail)

        Write (nout,*)
        Write (nout,*) '        Convolution  Correlation'
        Write (nout,*)
        Write (nout,99999)(j,xa(j),xb(j),j=0,n-1)
        Deallocate (xa,xb,ya,yb)
      End Do loop

99999 Format (1X,I5,2F13.5)
    End Program c06ekfe
