    PROGRAM c06pcfe

!      C06PCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c06pcf, 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(:), x(:), xx(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'C06PCF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
LOOP:  DO
          READ (nin,*,IOSTAT=ieof) n
          IF (ieof<0) EXIT LOOP

          ALLOCATE (work(2*n+15),x(0:n-1),xx(0:n-1))
          READ (nin,*) x(0:n-1)
          xx(0:n-1) = x(0:n-1)

!         ifail: behaviour on error exit   
!                =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
          ifail = 0
          CALL c06pcf('F',x,n,work,ifail)

          WRITE (nout,*)
          WRITE (nout,*) 'Components of discrete Fourier transform'
          WRITE (nout,*)
          WRITE (nout,*) '              Real      Imag'
          WRITE (nout,*)
          DO j = 0, n - 1
             WRITE (nout,99999) j, x(j)
          END DO

          CALL c06pcf('B',x,n,work,ifail)

          WRITE (nout,*)
          WRITE (nout,*) 'Original sequence as restored by inverse transform'
          WRITE (nout,*)
          WRITE (nout,*) '                 Original                 Restored'
          WRITE (nout,*) &
             '              Real      Imag           Real      Imag'
          WRITE (nout,*)
          DO j = 0, n - 1
             WRITE (nout,99999) j, xx(j), x(j)
          END DO
          DEALLOCATE (work,x,xx)
       END DO LOOP

99999  FORMAT (1X,I5,2(:5X,'(',F8.5,',',F8.5,')'))
    END PROGRAM c06pcfe
