#!/usr/bin/env ruby
require("gsl") 

n = 128
data = FFT::Complex::PackedArray.new(2*n)

data.set_real(0, 1.0)
c = Complex.new(1, 0)
for i in 1..10 do
  data[i] = [1.0, 0.0]
  data[n-i] = [1.0, 0.0]
end

file0 = "testradix2-0.dat"
file1 = "testradix2-1.dat"

File.open(file0, "w") do |f|
  for i in 0...n do
#    f.printf("%d %e %e\n", i, data.real(i), data.imag(i))
    f.printf("%d %e %e\n", i, data[i].re, data[i].im)
  end
end

#data.radix2_forward()
#data.radix2_transform(FFT::Forward)
#FFT::Complex.radix2_forward(data)
FFT::Complex::Radix2.forward(data)
#FFT::Complex.radix2_transform(data, FFT::Forward)
sqrtn = Math::sqrt(n)
File.open(file1, "w") do |f|
  for i in 0...n do
    f.printf("%d %e %e\n", i, data.real(i)/sqrtn, data.imag(i)/sqrtn)
  end
end

#puts("Data files #{file0} and #{file1} are created.")
#puts("Try \"gnuplot -persist radix2.gp\"")
system("gnuplot -persist radix2.gp")
File.delete(file0)
File.delete(file1)
