      PROGRAM FFTDEMO

      INCLUDE 'stdhdr.for'

      REAL fftr(0: maxv), ffti(0: maxv), ar(0: maxv)
      REAL bi(0: maxv), xr(0: maxv), yi(0: maxv)
      INTEGER nd, i

      ! {main program fft}
      nd = 128
      DO i = 0, nd - 1
        xr(i) = COS(pi * i / 16) + COS(pi * i / 32)
        yi(i) = 0
        ar(i) = xr(i)
        bi(i) = yi(i)
      END DO

      CALL FFTCalc(xr, yi, nd)


      DO i = 0, nd
        fftr(i) = xr(i)
        ffti(i) = yi(i)
      END DO

      CALL FFTInvCalc(xr, yi, nd)

      WRITE(*,*) 'Index       Rawdata       FFT data   Inverse FFT data'
      CALL DisplayData(ar, fftr, xr, nd)

      END


      SUBROUTINE DisplayData (dat1, dat2, dat3, numdat)
      INCLUDE 'stdhdr.for'

      REAL dat1(0:maxv),dat2(0:maxv),dat3(0:maxv)
      INTEGER nextpage, numdat
      INTEGER increment,strt,finish

      strt = 0
      finish = 19
      DO WHILE (nextpage .NE. 3)
        DO i = strt, finish
          WRITE (*,10)  i, dat1(i), dat2(i), dat3(i)
        END DO
10      FORMAT (I3, 3(4X F12.2))
        WRITE (*,*) 'prompt > '
        WRITE (*,*) '1-Next page   2-Back page   3-Quit display '
        READ *, nextpage

        IF (nextpage .EQ. 1) increment = 20
        IF (nextpage .EQ. 2) increment = -20
        strt = strt + increment
        IF (strt .LT. 0 .OR. strt .GT. numdat - 19)  strt = 0
        finish = finish + increment
        IF (finish .LT. 19 .OR. finish .GT. numdat)  finish = 19
      END DO

      END !SUBROUTINE


