//
// This file is part of the book "Language C++ et calcul scientifique"
//
// Copyright (C) 2005-2012 Pierre Saramito <Pierre.Saramito@imag.fr>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
#include "fish2d_fft.h"
#include "interpolate_2d.h"
#include "index.h"
#include "valarray_io.h"
using namespace std;
double f (const double& x, const double& y) { return 1; }
int main (int argc, char** argv) {
  size_t m = (argc > 1) ? atoi(argv[1]) : 64;
  double h = 2./m;
  index_type elt (m+1), num (m-1);
  valarray<double> pi_h_f = interpolate(m, f), b ((m-1)*(m-1));
  for (size_t i = 0; i < m-1; i++)
    for (size_t j = 0; j < m-1; j++)
      b [num(i,j)] = h*h*pi_h_f [elt (i+1,j+1)];
  valarray<double> uh(0.,(m+1)*(m+1)), x = fish2d_fft(m, b);
  for (size_t i = 0; i < m-1; i++)
    for (size_t j = 0; j < m-1; j++)
      uh [elt(i+1, j+1)] = x[num(i,j)];
  cout << uh;
}
