Index: trunk/SophyaExt/IFFTW/fftwserver.cc
===================================================================
--- trunk/SophyaExt/IFFTW/fftwserver.cc	(revision 1401)
+++ trunk/SophyaExt/IFFTW/fftwserver.cc	(revision 1403)
@@ -13,4 +13,6 @@
   void Recreate(int n);
   void Recreate(int nd, int * nxyz);
+
+  static void FillSizes(const BaseArray & in, int * sz);
 
   int _n;  // Array dimension for 1-d arrays
@@ -123,4 +125,13 @@
 }
 
+void
+FFTWServerPlan::FillSizes(const BaseArray & in, int * sz)
+{
+  int k1 = 0;
+  int k2 = 0;
+  for(k1=in.NbDimensions()-1; k1>=0; k1--) {
+    sz[k2] = in.Size(k1); k2++; 
+  }
+}
 
 /* --Methode-- */
@@ -176,9 +187,10 @@
       throw ParmError("FFTWServer::FFTForward( complex<r_8>, complex<r_8> ) rank > MAXND_FFTW !"); 
     int sz[MAXND_FFTW];
-    int k1 = 0;
-    int k2 = 0;
-    for(k1=in.NbDimensions()-1; k1>=0; k1--) {
-      sz[k2] = in.Size(k1); k2++; 
-    }
+    FFTWServerPlan::FillSizes(in, sz);
+    //    int k1 = 0;
+    //    int k2 = 0;
+    //    for(k1=in.NbDimensions()-1; k1>=0; k1--) {
+    //      sz[k2] = in.Size(k1); k2++; 
+    //    }
     if (_pndf) _pndf->Recreate(in.NbDimensions(), sz);
     else _pndf = new FFTWServerPlan(in.NbDimensions(), sz, FFTW_FORWARD, false);
@@ -202,9 +214,10 @@
       throw ParmError("FFTWServer::FFTForward( complex<r_8>, complex<r_8> ) rank > MAXND_FFTW !"); 
     int sz[MAXND_FFTW];
-    int k1 = 0;
-    int k2 = 0;
-    for(k1=in.NbDimensions()-1; k1>=0; k1--) {
-      sz[k2] = in.Size(k1); k2++; 
-    }
+    FFTWServerPlan::FillSizes(in, sz);
+    //    int k1 = 0;
+    //    int k2 = 0;
+    //    for(k1=in.NbDimensions()-1; k1>=0; k1--) {
+    //      sz[k2] = in.Size(k1); k2++; 
+    //    }
     if (_pndb) _pndb->Recreate(in.NbDimensions(), sz);
     else _pndb = new FFTWServerPlan(in.NbDimensions(), sz, FFTW_BACKWARD, false);
@@ -231,9 +244,10 @@
       throw ParmError("FFTWServer::FFTForward( complex<r_8>, complex<r_8> ) rank > MAXND_FFTW !"); 
     int sz[MAXND_FFTW];
-    int k1 = 0;
-    int k2 = 0;
-    for(k1=in.NbDimensions()-1; k1>=0; k1--) {
-      sz[k2] = in.Size(k1); k2++; 
-    }
+    FFTWServerPlan::FillSizes(in, sz);
+    //    int k1 = 0;
+    //    int k2 = 0;
+    //   for(k1=in.NbDimensions()-1; k1>=0; k1--) {
+    //      sz[k2] = in.Size(k1); k2++; 
+    //    }
     if (_pndrf) _pndrf->Recreate(in.NbDimensions(), sz);
     else _pndrf = new FFTWServerPlan(in.NbDimensions(), sz, FFTW_REAL_TO_COMPLEX, true);
@@ -248,8 +262,9 @@
 
 
-void FFTWServer::FFTBackward(TArray< complex<r_8> > const & in, TArray< r_8 > & out)
+void FFTWServer::FFTBackward(TArray< complex<r_8> > const & in, TArray< r_8 > & out,
+			     bool usoutsz)
 {
   
-  int rank = ckR8.CheckResize(in, out);
+  int rank = ckR8.CheckResize(in, out, usoutsz);
   if (rank == 1) { // One dimensional transform 
     TArray<r_8> intemp;
@@ -266,11 +281,12 @@
   else {   // Multi dimensional 
     if (in.NbDimensions() > MAXND_FFTW) 
-      throw ParmError("FFTWServer::FFTForward( complex<r_8>, complex<r_8> ) rank > MAXND_FFTW !"); 
+      throw ParmError("FFTWServer::FFTForward( complex<r_8>, r_8 ) rank > MAXND_FFTW !"); 
     int sz[MAXND_FFTW];
-    int k1 = 0;
-    int k2 = 0;
-    for(k1=in.NbDimensions()-1; k1>=0; k1--) {
-      sz[k2] = in.Size(k1); k2++; 
-    }
+    FFTWServerPlan::FillSizes(out, sz);
+    //    int k1 = 0;
+    //    int k2 = 0;
+    //    for(k1=out.NbDimensions()-1; k1>=0; k1--) {
+    //      sz[k2] = out.Size(k1); k2++; 
+    //    }
     if (_pndrb) _pndrb->Recreate(in.NbDimensions(), sz);
     else _pndrb = new FFTWServerPlan(in.NbDimensions(), sz, FFTW_COMPLEX_TO_REAL, true);
@@ -281,67 +297,4 @@
 }
 
-/*
-void FFTWServer::FFTForward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out)
-{
-  out.ReSize(in.NRows(),in.NCols());
-
-  if (_pndf) _pndf->Recreate( in.NRows(),in.NCols());
-  else _pndf = new FFTWServerPlan( in.NCols(),in.NRows(), FFTW_FORWARD, false);
-  
-  fftwnd_one(_pndf->pnd, (fftw_complex *)(in.Data()) , (fftw_complex *)(out.Data()) );
-  if(this->getNormalize()) out=out/complex<r_8>(pow(in.NRows()*in.NCols(),0.5),0.);  
-}
-
-void FFTWServer::FFTBackward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out)
-{
-  if (_pndb) _pndb->Recreate(in.NCols(), in.NRows());
-  else _pndb = new FFTWServerPlan(in.NCols(), in.NRows(), FFTW_BACKWARD, false);
-  out.ReSize(in.NRows(), in.NCols());
-  fftwnd_one(_pndb->pnd, (fftw_complex *)(in.Data()) , (fftw_complex *)(out.Data()) );
-  if(this->getNormalize()) out=out/complex<r_8>(pow(in.NRows()*in.NCols(),0.5),0.);
-
-}
-
-
-void FFTWServer::FFTForward(TArray< r_8 > const & in, TArray< complex<r_8> > & out)
-{
-
-  TArray< r_8 > inNew(in.NCols(),in.NRows());
-  for(int i=0; i<in.NRows(); i++)
-    for(int j=0;j<in.NCols(); j++)
-      inNew(j,i) = in(i,j);
-  
-  if (_pndrf) _pndrf->Recreate(inNew.NRows(),inNew.NCols());
-  else _pndrf = new FFTWServerPlan(inNew.NRows(), inNew.NCols(),FFTW_REAL_TO_COMPLEX, true);
-  //  rfftwnd_plan p;
-  TArray< complex<r_8> > outTemp;
-  outTemp.ReSize(in.NRows(),in.NCols());
-
-  rfftwnd_one_real_to_complex(_pndrf->rpnd, (fftw_real *)(in.Data()) , (fftw_complex *)(out.Data()) );
-}
-
-void FFTWServer::FFTBackward(TArray< complex<r_8> > const & in, TArray< r_8 > & out)
-{
-
-  TArray< complex<r_8> > inNew(in.NCols(),in.NRows());
-  for(int i=0; i<in.NRows(); i++)
-    for(int j=0;j<in.NCols(); j++)
-      inNew(j,i) = in(i,j);
-  
-  if (_pndrb) _pndrb->Recreate(inNew.NRows(),inNew.NCols());
-  else _pndrb = new FFTWServerPlan(inNew.NRows(), inNew.NCols(),FFTW_COMPLEX_TO_REAL, true);
-  //  rfftwnd_plan p;
-  out.ReSize(in.NRows(),in.NCols());
-
-  rfftwnd_one_complex_to_real(_pndrb->rpnd, (fftw_complex *)(in.Data()) , (fftw_real *)(out.Data()) );
-  cout << " in the function !!!" << endl;
-  if(this->getNormalize()) 
-    {
-      r_8 norm = (r_8)(in.NRows()*in.NCols());
-      out=out/norm;
-    }
-}
-
-*/
 
 
