#include "fft2d_decl.h"

void test (Config &cfg, 
           Env &env)
{
  int pe=env.pre.pe;
  Alias(PartOne,ALL1,env.pre.ALL1);
  Alias(PartOne,ONE1,env.pre.ONE1);
  Alias(PartNP,ALLn,env.pre.ALLn);
  Alias(PartNP,ONEn,env.pre.ONEn);
  Alias(PartNP,PPEn,env.pre.PPEn);

  Data (File, fout); 
  Data (Int, cond); Data (Int, i); 
  DataRa (PartRange1D, r1, ALLn[pe]); 
  DataRa (PartRange2D, col, ALLn[pe]); DataRa (PartRange2D, row, ALLn[pe]); 
  DataRa (SwapRange2D, sw_cr, PPEn[pe]); DataRa (SwapRange2D, sw_rc, PPEn[pe]); 

  init (cfg, row, col, r1, fout);

  DataRa (Vector1Dcplx, W_r1, r1[pe]); 
  DataRa (Vector2Dcplx, A_col, col[pe]); DataRa (Vector2Dcplx, A_row, row[pe]); 
  DataRa (Vector2Dcplx, Ame_col, col[pe]); DataRa (Vector2Dcplx, Bme_row, row[pe]); 
  DataRa (Vector2Dcplx, R_col, col[pe]); DataRa (Vector2Dcplx, Xe2_col, col[pe]); 

  computeSwap (col, row, sw_cr);

  computeSwap (row, col, sw_rc);

  pre_fft (r1[pe], W_r1);

  matrix_read (cfg, col[pe], A_col, R_col);

  CLK_MAIN_LP_BEGIN;

  for (i=0, cond=1; cond; i++)
  {
      CLK_MAIN_BEGIN(i);

      fft_col (A_col, W_r1, col[pe], r1[pe], Xe2_col);

      swapBegin (sw_cr, Xe2_col, Bme_row, 0, pe);

      econd (cfg, i, cond);

      swapEnd (sw_cr, Xe2_col, Bme_row, 0, pe);

      fft_row (Bme_row, W_r1, row[pe], r1[pe], A_row);

      swapBegin (sw_rc, A_row, Xe2_col, 0, pe);

      swapEnd (sw_rc, A_row, Xe2_col, 0, pe);

      negate_im (Xe2_col, col[pe], Ame_col);

      fft_col (Ame_col, W_r1, col[pe], r1[pe], Xe2_col);

      swapBegin (sw_cr, Xe2_col, A_row, 0, pe);

      swapEnd (sw_cr, Xe2_col, A_row, 0, pe);

      fft_row (A_row, W_r1, row[pe], r1[pe], Bme_row);

      negate_im (Bme_row, row[pe], A_row);

      swapBegin (sw_rc, A_row, A_col, 0, pe);

      swapEnd (sw_rc, A_row, A_col, 0, pe);

      CLK_MAIN_END(i);
  }

  CLK_MAIN_LP_END;

  check_equal (A_col, R_col, col[pe]);

  Print (fout, A_col, col[pe]);
}


