Index: /trunk/SophyaProg/Tests/tfft.cc
===================================================================
--- /trunk/SophyaProg/Tests/tfft.cc	(revision 714)
+++ /trunk/SophyaProg/Tests/tfft.cc	(revision 715)
@@ -3,4 +3,5 @@
 
 #include "fftpserver.h"
+#include "fftmserver.h"
 #include "sambainit.h"
 
@@ -14,11 +15,12 @@
 }
 
+// Max Matrix print elts
+static int nprt = 2;
+static int nprtfc = 8;
+
 template <class T>
-void TestFFTS(T seuil, FFTServerInterface & ffts)
-{
-  
-  int num=16;
+void TestFFTPack(T seuil, int num)
+{
   int i;
-
   T fact = 1./num;
 
@@ -26,16 +28,22 @@
   TVector< T > in(num), ino(num), bk(num),dif(num);
   TVector< complex<T> > outc(num);
+
+  cout << " DBG/1 outc " << outc.NElts()  << endl; 
+  outc.ReSize(32);
+  cout << " DBG/2 outc " << outc.NElts()  << endl; 
+  outc.ReSize(10);
+  cout << " DBG/3 outc " << outc.NElts()  << endl; 
+  outc.ReSize(48);
+  cout << " DBG/4 outc " << outc.NElts()  << endl; 
+
+  for (int i=0; i<num ; i++){
+    ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num) 
+                         + 2*sin(4*M_PI*(double)i/(double)num);
+    inc[i] = complex<T> (in[i], 0.);
+  }
   
-  
-  for (int i=0; i<num ; i++){
-    ino[i] = in[i] = cos(2*M_PI*i/8.) + sin(2*M_PI*i/4.);
-    inc[i] = complex<T> (in[i], 0.);
-  }
-  
-
-  cout << " Testing FFTServer " << ffts.getInfo() << endl;
 
   cout << "Input / L = " << num << endl; 
-  in.Print(0,0,num,0,num);
+  in.Print(0,0,nprt,0,nprt);
   cout << endl;
 
@@ -44,81 +52,157 @@
   cout << " Testing FFTPackServer "  << endl;
   fftp.fftf(in.NElts(), in.Data());
-  in /= (num/2.);
+  //  in /= (num/2.);
   cout << " fftp.fftf(in.NElts(), in.Data()) FORWARD: " << endl; 
-  in.Print(0,0,num,0,num);
+  in.Print(0,0,nprtfc,0,nprtfc);
   cout << endl;
   fftp.fftb(in.NElts(), in.Data());
   cout << " fftp.fftb(in.NElts(), in.Data()) BACKWARD: " << endl; 
-  in.Print(0,0,num,0,num);
-  cout << endl;
-
-  in = ino;
+  in.Print(0,0,nprt,0,nprt);
+  cout << endl;
+  dif = ino-in;
+  cout << " dif , NElts= " << dif.NElts() << endl;
+  dif.Print(0,0,nprt,0,nprt);
+
+  int ndiff = 0;
+  T maxdif=0., vdif;
+  for(i=0; i<num; i++) {
+    vdif = fabs(dif(i));
+    if (vdif > seuil)  ndiff++;
+    if (vdif > maxdif) maxdif = vdif;
+  }
+  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 
+       << " MaxDiff= " << maxdif << endl;
+
+}
+
+template <class T>
+void TestFFTS(T seuil, FFTServerInterface & ffts, int num)
+{
+
+  cout <<" ===>  TestFFTS " << ffts.getInfo() << " ArrSz= " << num << endl;  
+  int i;
+
+  T fact = 1.;
+
+  TVector< complex<T> > inc(num), bkc(num), difc(num);
+  TVector< T > in(num), ino(num), bk(num),dif(num);
+  TVector< complex<T> > outc(num);
+
+  for (int i=0; i<num ; i++){
+    ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num) 
+                         + 2*sin(4*M_PI*(double)i/(double)num);
+    inc[i] = complex<T> (in[i], 0.);
+  }
+  
+
+  cout << " Testing FFTServer " << ffts.getInfo() << endl;
+
+  cout << "Input / L = " << num << endl; 
+  in.Print(0,0,nprt,0,nprt);
+  cout << endl;
+
+  int ndiff = 0;
 
   cout << "\n ----  Testing FFT(T, complex<T>) ---- " << endl;
-
   ffts.FFTForward(in, outc);
-  cout << " outc , NElts= " << outc.NElts() << endl;
-  outc.Print(0,0,num,0,num);
+  cout << " FourierCoefs , NElts= " << outc.NElts() << endl;
+  outc.Print(0,0,nprtfc,0,nprtfc);
 
   ffts.FFTBackward(outc, bk);
-  cout << " bk , NElts= " << bk.NElts() << endl;
-  bk.Print(0,0,num,0,num);
+  cout << " Backward , NElts= " << bk.NElts() << endl;
+  bk.Print(0,0,nprt,0,nprt);
  
   dif = bk*fact - in;
-  cout << " dif , NElts= " << dif.NElts() << endl;
-  dif.Print(0,0,num,0,num);
-
-  int ndiff = 0;
-  for(i=0; i<num; i++) 
-    if (fabs(dif(i)) > seuil)  ndiff++;
-
-  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff << endl;
+  cout << " Difference , NElts= " << dif.NElts() << endl;
+  dif.Print(0,0,nprt,0,nprt);
+
+  ndiff = 0;
+  T maxdif=0., vdif;
+  for(i=0; i<num; i++) {
+    vdif = fabs(dif(i));
+    if (vdif > seuil)  ndiff++;
+    if (vdif > maxdif) maxdif = vdif;
+  }
+  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 
+       << " MaxDiff= " << maxdif << endl;
  
   cout << "\n ----  Testing FFT(complex<T>, complex<T>) ---- " << endl;
   ffts.FFTForward(inc, outc);
-  cout << " outc , NElts= " << outc.NElts() << endl;
-  outc.Print(0,0,num,0,num);
+  cout << " FourierCoef , NElts= " << outc.NElts() << endl;
+  outc.Print(0,0,nprtfc,0,nprtfc);
 
   ffts.FFTBackward(outc, bkc);
-  cout << " bkc , NElts= " << bkc.NElts() << endl;
-  bkc.Print(0,0,num,0,num);
+  cout << " Backward , NElts= " << bkc.NElts() << endl;
+  bkc.Print(0,0,nprt,0,nprt);
  
   difc = bkc*complex<T>(fact,0.) - inc;
-  cout << " difc , NElts= " << difc.NElts() << endl;
-  difc.Print(0,0,num,0,num);
-
-  int ndiffc = 0;
-  for(i=0; i<num; i++) 
-    if (fabs(module(difc(i))) > seuil)  ndiffc++;
-  cout << " Difference, Seuil= " << seuil << " NDiffC= " << ndiffc << endl;
-}
-
-
-int main(int narg, char* arg)
+  cout << " Difference , NElts= " << difc.NElts() << endl;
+  difc.Print(0,0,nprt,0,nprt);
+
+  ndiff = 0;
+  maxdif=0., vdif;
+  for(i=0; i<num; i++) {
+    vdif = fabs(module(difc(i)));
+    if (vdif > seuil)  ndiff++;
+    if (vdif > maxdif) maxdif = vdif;
+  }
+  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 
+       << " MaxDiff= " << maxdif << endl;
+}
+
+
+
+
+
+int main(int narg, char* arg[])
 {
 
   PeidaInit();
   InitTim();   // Initializing the CPU timer
-  FFTPackServer ffts;
-
+
+  if (narg < 4) {
+    cout << "tfft/ args error - \n  Usage tfft size p/P/M f/d [NPrtFC NPrt] \n" 
+	 << " p=FFTPackTest  P=FFTPack, M=FFTMayer, f=float, d=double " << endl;
+    exit(0);
+  }
+
+  FFTPackServer fftp;
+  FFTMayerServer fftm;
+
+  int sz = atoi(arg[1]);
+  if (narg > 4) nprtfc = atoi(arg[4]);
+  if (narg > 5) nprt = atoi(arg[4]);
+
+  if (sz < 2) sz = 2;
+  FFTServerInterface * ffts;
+  if (*arg[2] == 'M')  ffts = fftm.Clone();
+  else ffts = fftp.Clone();
+
+  float fs = 1.e-4;
+  double ds = 1.e-6;
 
   try {
-  float fs = 1.e-6;
-  double ds = 1.e-12;
-  cout << "\n ======================================== \n"
-       << "    ------ Testing FFTS for float ----- \n"
-       << " ======================================== " << endl;
-  TestFFTS(fs, ffts);
-  cout << "\n ======================================== \n"
-       << "    ------ Testing FFTS for double ----- \n"
-       << " ======================================== " << endl;
-  TestFFTS(ds, ffts);
+    if (*arg[3] == 'd') {
+      cout << "\n ========================================== \n"
+	   << "    ------ Testing FFTServer for double ----- \n"
+	   << " ============================================ " << endl;
+      if (*arg[2] == 'p') TestFFTPack(ds, sz);
+      else TestFFTS(ds, *ffts, sz);
+    }
+    else {
+      cout << "\n ========================================= \n"
+	   << "    ------ Testing FFTServer for float ----- \n"
+	   << " =========================================== " << endl;
+      if (*arg[2] == 'p') TestFFTPack(fs, sz);
+      else TestFFTS(fs, *ffts, sz);
+    }
   }
   catch(PThrowable exc ) {
-    cerr << "TestFFT-main() , Catched exception: " << exc.Msg() << endl;
+    cerr << "TestFFT-main() , Catched exception: \n" << exc.Msg() << endl;
   }
   catch(std::exception ex) {
     cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl;
   }
+
   /*
   catch(...) {
@@ -127,3 +211,4 @@
   */
   PrtTim("End of tfft ");
-}
+  delete ffts;
+}
