    PROGRAM c06pqfe

!      C06PQF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c06pqf, 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 ..
       REAL (KIND=nag_wp), ALLOCATABLE :: work(:), x(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'C06PQF 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+2)))
          DO j = 1, m*(n+2), n + 2
             READ (nin,*) (x(j+i),i=0,n-1)
          END DO
          WRITE (nout,*)
          WRITE (nout,*) 'Original data values'
          WRITE (nout,*)
          DO j = 1, m*(n+2), n + 2
             WRITE (nout,99999) '     ', (x(j+i),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 c06pqf('F',n,m,x,work,ifail)

          WRITE (nout,*)
          WRITE (nout,*) &
             'Discrete Fourier transforms in complex Hermitian format'
          DO j = 1, m*(n+2), n + 2
             WRITE (nout,*)
             WRITE (nout,99999) 'Real ', (x(j+2*i),i=0,n/2)
             WRITE (nout,99999) 'Imag ', (x(j+2*i+1),i=0,n/2)
          END DO
          WRITE (nout,*)
          WRITE (nout,*) 'Fourier transforms in full complex form'

          DO j = 1, m*(n+2), n + 2
             WRITE (nout,*)
             WRITE (nout,99999) 'Real ', (x(j+2*i),i=0,n/2), &
                (x(j+2*(n-i)),i=n/2+1,n-1)
             WRITE (nout,99999) 'Imag ', (x(j+2*i+1),i=0,n/2), &
                (-x(j+2*(n-i)+1),i=n/2+1,n-1)
          END DO

          CALL c06pqf('B',n,m,x,work,ifail)

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

99999  FORMAT (1X,A,9(:1X,F10.4))
    END PROGRAM c06pqfe
