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

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

table = FFT::Complex::Wavetable.new(n)
space = FFT::Complex::Workspace.new(n)

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

file0 = "testforward-0.dat"
file1 = "testforward-1.dat"
File.delete(file0) if FileTest.exist?(file0)
File.delete(file1) if FileTest.exist?(file1)

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))
  end
end

#data.forward(1, n, table, space)
#data.forward(n, table, space)
#data.forward(table, space)
#data.forward(n, table)
#data.forward(n, space)
#data.forward(n)
#data.forward(table)
#data.forward(space)
#data.forward()
#data.transform(table, space, FFT::Forward)
#data.transform(FFT::Forward)
FFT::Complex.forward(data, table, space)
#FFT::Complex.forward(data)
#FFT::Complex.transform(data, table, space, FFT::Forward)
#FFT::Complex.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.")
system("gnuplot -persist forward.gp")
File.delete(file0)
File.delete(file1)
