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

n = 100
data = Vector.new(n)

for i in (n/3)...(2*n/3) do
  data[i] = 1.0
end

file0 = "testreal-halfcomplex-0.dat"
file1 = "testreal-halfcomplex-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\n", i, data[i])
  end
end

rtable = FFT::Real::Wavetable.new(n)
rwork = FFT::Real::Workspace.new(n)

#data.real_transform(1, n, rtable, rwork)
#data.real_transform(n, rtable, rwork)
#data.real_transform(rtable, rwork)
#data.real_transform(n, rtable)
#data.real_transform(n, rwork)
#data.real_transform(n)
#data.real_transform(rtable)
#data.real_transform(rwork)
#data.real_transform()
FFT::Real.transform(data)

for i in 11...n do
  data[i] = 0.0
end

hctable = FFT::HalfComplex::Wavetable.new(n)

#data.halfcomplex_inverse(hctable, rwork)
data.halfcomplex_inverse()
#FFT::HalfComplex.inverse(data)

File.open(file1, "w") do |f|
  for i in 0...n do
    f.printf("%d %e\n", i, data[i])
  end
end

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