    PROGRAM c06prfe

!      C06PRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c06prf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ieof, ifail, j, m, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: work(:), x(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          aimag, real
!      .. Executable Statements ..
       WRITE (nout,*) 'C06PRF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
LOOP:  DO
          READ (nin,*,IOSTAT=ieof) m, n
          IF (ieof<0) EXIT LOOP

          ALLOCATE (work((m+2)*n+15),x(m*n))
          DO j = 1, m
             READ (nin,*) (x(i*m+j),i=0,n-1)
          END DO
          WRITE (nout,*)
          WRITE (nout,*) 'Original data values'
          DO j = 1, m
             WRITE (nout,*)
             WRITE (nout,99999) 'Real ', (real(x(i*m+j)),i=0,n-1)
             WRITE (nout,99999) 'Imag ', (aimag(x(i*m+j)),i=0,n-1)
          END DO

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

          WRITE (nout,*)
          WRITE (nout,*) 'Discrete Fourier transforms'
          DO j = 1, m
             WRITE (nout,*)
             WRITE (nout,99999) 'Real ', (real(x(i*m+j)),i=0,n-1)
             WRITE (nout,99999) 'Imag ', (aimag(x(i*m+j)),i=0,n-1)
          END DO

          ifail = 0
          CALL c06prf('B',m,n,x,work,ifail)

          WRITE (nout,*)
          WRITE (nout,*) 'Original data as restored by inverse transform'
          DO j = 1, m
             WRITE (nout,*)
             WRITE (nout,99999) 'Real ', (real(x(i*m+j)),i=0,n-1)
             WRITE (nout,99999) 'Imag ', (aimag(x(i*m+j)),i=0,n-1)
          END DO
          DEALLOCATE (x,work)
       END DO LOOP

99999  FORMAT (1X,A,6F10.4)
    END PROGRAM c06prfe
