    PROGRAM c06fkfe

!      C06FKF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c06fkf, 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 :: work(:), xa(:), xb(:), ya(:), yb(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'C06FKF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
LOOP:  DO
          READ (nin,*,IOSTAT=ieof) n
          IF (ieof<0) EXIT LOOP

          ALLOCATE (work(n),xa(n),xb(n),ya(n),yb(n))
          READ (nin,*) (xa(j),ya(j),j=1,n)
          xb(1:n) = xa(1:n)
          yb(1:n) = ya(1:n)

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

          CALL c06fkf(2,xb,yb,n,work,ifail)

          WRITE (nout,*) '        Convolution  Correlation'
          WRITE (nout,*)
          WRITE (nout,99999) (j-1,xa(j),xb(j),j=1,n)
          DEALLOCATE (xa,xb,ya,yb,work)
       END DO LOOP

99999  FORMAT (1X,I5,2F13.5)
    END PROGRAM c06fkfe
