    PROGRAM c06pkfe

!      C06PKF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c06pkf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ieof, ifail, j, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: work(:), xa(:), xb(:), ya(:), yb(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'C06PKF 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(2*n+15),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 c06pkf(1,xa,ya,n,work,ifail)

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

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

99999  FORMAT (1X,I5,2(1X,'(',F9.5,',',F9.5,')'))
    END PROGRAM c06pkfe
