#ifndef FT_MAIN_H
#define FT_MAIN_H
#include "npb-aux.h"
#include "const.h"
#include "dpcm.h"
#include "ArrayND.h"

typedef Array3D<dcomplex> Vector3Dcplx;
typedef Array3D<int> Vector3Dint;
typedef dcomplex Checksums[MAXITER+1]; // 0..MAXITER
typedef ArrayNP<dcomplex> ArrayCplx;
typedef dcomplex Cplx;
typedef int Int;
typedef boolean Bool;
typedef int Dim3[3];

struct Setup;
struct Env;

#include "ft_decl.h"

struct Setup 
{
  void alloc() {
    ex = new double[EXPMAX+1];  // ex(0:expmax)
    y0 = new dcomplex[NX][FFTBLOCKPAD];
    y1 = new dcomplex[NX][FFTBLOCKPAD];
    u = new dcomplex[NX];
  }

  // config
  int fftblock, fftblockpad, niter;
  char class2;

  // compute_index_map
  double *ex;    
  Vector3Dint indexmap;

  // fft buffers
  dcomplex *u;   // fft_init
  dcomplex (*y0)[FFTBLOCKPAD];
  dcomplex (*y1)[FFTBLOCKPAD];
};

struct Env 
{
  PreEnv pre;

  PartRange3D dom0, dom1, dom2;
  SwapRange3D sw01, sw12, sw02, sw21, sw10, sw20;

  int niter, fdir, finv, lay1d;
  Setup sp;
};

inline void print (FILE* f, const dcomplex x) { 
  fprintf(f,"%6.3lf,%6.3lf ", x.real, x.imag); }

#endif // FT_MAIN_H

