      program dft
      
      complex f(8),I
      real x(8), value, PI
      integer i,j,sign,k
      PI = 3.14159265
      I = (0,1)
      
      open(1, file = 'data.txt')
      read(1,*)  x(1),x(2),x(3),x(4),x(5),x(6),x(7)
      write(*,*) x(1),x(2),x(3),x(4),x(5),x(6),x(7)
      
      dft(x(8))
      
      write(*,*) f(1),f(2),f(3),f(4),f(5),f(6),f(7)
      write(1,*) f(1),f(2),f(3),f(4),f(5),f(6),f(7)
      
      end


      function dft(x(8))
      
      dftbody(x(8), 1)
      return
      end

      function dftinverse(x(8))

      dftbody(x(8),-1)
      do 30 k = 1, 8
         f(k) = f(k)/8
 30   continue
      return
      end
            

      function dftbody(array(8),sign)
      
      real x(8)
      complex f(8), I
      real PI, value
      integer outer, inner,sign
      PI = 3.14159265
      I = (0,1)

      do 10 outer = 1, 8
         do 20 inner = 1, 8
            value = sign*2.0*PI*outer*inner/8
            f(outer)+= x(inner)*EXP(I*value)
 10      continue
 20   continue
      return
      end
