*     C06PSF Example Program Text
*     Mark 19 Release. NAG Copyright 1999.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          MMAX, NMAX
      PARAMETER        (MMAX=5,NMAX=20)
*     .. Local Scalars ..
      INTEGER          I, IFAIL, J, M, N
*     .. Local Arrays ..
      COMPLEX *16      WORK(NMAX+MMAX*NMAX+15), X(MMAX*NMAX)
*     .. External Subroutines ..
      EXTERNAL         C06PSF
*     .. Intrinsic Functions ..
      INTRINSIC        DBLE, DIMAG
*     .. Executable Statements ..
      WRITE (NOUT,*) 'C06PSF Example Program Results'
*     Skip heading in data file
      READ (NIN,*)
   20 CONTINUE
      READ (NIN,*,END=120) M, N
      IF (M.LE.MMAX .AND. N.LE.NMAX) THEN
         DO 40 J = 1, M*N, N
            READ (NIN,*) (X(J+I),I=0,N-1)
   40    CONTINUE
         WRITE (NOUT,*)
         WRITE (NOUT,*) 'Original data values'
         DO 60 J = 1, M*N, N
            WRITE (NOUT,*)
            WRITE (NOUT,99999) 'Real ', (DBLE(X(J+I)),I=0,N-1)
            WRITE (NOUT,99999) 'Imag ', (DIMAG(X(J+I)),I=0,N-1)
   60    CONTINUE
         IFAIL = 0
*
         CALL C06PSF('F',N,M,X,WORK,IFAIL)
*
         WRITE (NOUT,*)
         WRITE (NOUT,*) 'Discrete Fourier transforms'
         DO 80 J = 1, M*N, N
            WRITE (NOUT,*)
            WRITE (NOUT,99999) 'Real ', (DBLE(X(J+I)),I=0,N-1)
            WRITE (NOUT,99999) 'Imag ', (DIMAG(X(J+I)),I=0,N-1)
   80    CONTINUE
*
         CALL C06PSF('B',N,M,X,WORK,IFAIL)
*
         WRITE (NOUT,*)
         WRITE (NOUT,*) 'Original data as restored by inverse transform'
         DO 100 J = 1, M*N, N
            WRITE (NOUT,*)
            WRITE (NOUT,99999) 'Real ', (DBLE(X(J+I)),I=0,N-1)
            WRITE (NOUT,99999) 'Imag ', (DIMAG(X(J+I)),I=0,N-1)
  100    CONTINUE
         GO TO 20
      ELSE
         WRITE (NOUT,*) 'Invalid value of M or N'
      END IF
  120 CONTINUE
      STOP
*
99999 FORMAT (1X,A,6F10.4)
      END
