Index: /trunk/SophyaProg/Tests/tfft.cc
===================================================================
--- /trunk/SophyaProg/Tests/tfft.cc	(revision 2840)
+++ /trunk/SophyaProg/Tests/tfft.cc	(revision 2841)
@@ -3,5 +3,7 @@
 
 #include <math.h>
+#include <ctype.h>
 #include <iostream>
+#include <typeinfo>
 
 #include "nbrandom.h"
@@ -14,4 +16,21 @@
 #include "timing.h"
 
+/*  --------------------------------------------------------- */
+/*  ----       Programme de test de calcul de FFT        ---  */
+/*  ----          par les FFTServer de SOPHYA            ---  */
+/*  2000-2005      -   C. Magneville,  R. Ansari              */
+/*      Test FFT-1D real<>complex complex<>complex            */
+/*  Aide/Liste d'arguments :                                  */
+/*  csh> tfft                                                 */
+/*  Tests de base     ( ==> Rc=0 )                            */
+/*  csh> tfft 15 P                                            */
+/*  csh> tfft 16 P                                            */  
+/*  csh> tfft 15 W                                            */
+/*  csh> tfft 16 W                                            */ 
+/*  csh> tfft 1531 P D 0 50 0.0002                            */
+/*  csh> tfft 1220 P D 0 50 0.0002                            */
+/*  csh> tfft 1531 W D 0 50 0.0002                            */
+/*  csh> tfft 1220 W D 0 50 0.0002                            */
+/*  --------------------------------------------------------- */
 
 static bool inp_typ_random = false ;  // true -> random input
@@ -27,6 +46,8 @@
 static int nprtfc = 8;
 
+static  int prtlev = 0;
+
 template <class T>
-void TestFFTPack(T seuil, int num)
+void TestFFTPack(T seuil, sa_size_t num)
 {
   int i;
@@ -86,5 +107,5 @@
 
 template <class T>
-void TestFFTS(T seuil, FFTServerInterface & ffts, int num)
+int TestFFTS(T seuil, FFTServerInterface & ffts, sa_size_t num)
 {
 
@@ -98,27 +119,42 @@
   TVector< complex<T> > outc(num);
 
-  for (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.);
-  }
-  
+  if (inp_typ_random) {
+    cout << " TestFFTS/Random input vector ... " << endl;
+    ino = in = RandomSequence() ; // Nombre aleatoire gaussienne - sigma=1, mean=0
+    ComplexMathArray< T > cma;
+    TVector< T > im(num);
+    im = RandomSequence(RandomSequence::Flat);
+    inc = cma.FillFrom(in, im);
+  }
+  else {
+    cout << " TestFFTS/Random input vector = 0.5+cos(2x)+2sin(4x)... " << endl;
+    for (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 << in << endl; 
-  cout << endl;
+  cout << "Input / Length= " << num << endl;
+  if (prtlev > 0) 
+    cout << in << endl; 
 
   int ndiff = 0;
-
-  cout << "\n ----  Testing FFT(T, complex<T>) ---- " << endl;
+  int rc = 0;
+
+  cout << "\n ----  Testing FFT-1D(T, complex<T>) ---- " << endl;
   ffts.FFTForward(in, outc);
-  cout << " FourierCoefs , NElts= " << outc.NElts() << outc << endl;
+  if (prtlev > 0) 
+    cout << " FourierCoefs: outc= \n" << outc << endl;
 
   ffts.FFTBackward(outc, bk);
-  cout << " Backward , NElts= " << bk.NElts() << bk << endl;
+  if (prtlev > 0) 
+    cout << " Backward: bk= \n" << bk << endl;
  
   dif = bk*fact - in;
-  cout << " Difference , NElts= " << dif.NElts() << dif << endl;
+  if (prtlev > 0) 
+    cout << " Difference dif= \n" << dif << endl;
 
   ndiff = 0;
@@ -132,13 +168,18 @@
        << " MaxDiff= " << maxdif << endl;
  
-  cout << "\n ----  Testing FFT(complex<T>, complex<T>) ---- " << endl;
+  if (ndiff != 0)  rc += 4;
+
+  cout << "\n ----  Testing FFT-1D(complex<T>, complex<T>) ---- " << endl;
   ffts.FFTForward(inc, outc);
-  cout << " FourierCoef , NElts= " << outc.NElts() << outc << endl;
+  if (prtlev > 0) 
+    cout << " FourierCoef , outc= \n" << outc << endl;
 
   ffts.FFTBackward(outc, bkc);
-  cout << " Backward , NElts= " << bkc.NElts() << bkc << endl;
+  if (prtlev > 0) 
+    cout << " Backward , bkc= \n " << bkc << endl;
  
   difc = bkc*complex<T>(fact,0.) - inc;
-  cout << " Difference , NElts= " << difc.NElts() << difc << endl;
+  if (prtlev > 0) 
+    cout << " Difference , difc= \n " << difc << endl;
 
   ndiff = 0;
@@ -151,4 +192,7 @@
   cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 
        << " MaxDiff= " << maxdif << endl;
+
+  if (ndiff != 0)  rc += 8;
+  return rc;
 }
 
@@ -163,9 +207,12 @@
   InitTim();   // Initializing the CPU timer
 
-  if (narg < 4) {
-    cout << "tfft/ args error - \n  Usage tfft size px/Px/Mx/Wx f/d [NPrt=50 PrtLev=0] \n" 
-	 << " p=FFTPackTest  P=FFTPack, M=FFTMayer, W= FFTWServer" 
-         << " x=0 -> Random input - f=float, d=double " << endl;
-    exit(0);
+  if (narg < 3) {
+    cout << "tfft/ args error - \n  Usage tfft size p/P/M/W [f/d/F/D  PrtLev=0 MaxNPrt=50 diffthr] \n" 
+	 << " 1D real/complex-FFT test (FFTServer) \n"
+	 << " size: input vector length \n " 
+	 << " p=FFTPackTest  P=FFTPack, M=FFTMayer, W= FFTWServer \n " 
+         << " F/f:float, D/d:double F/D:random in_vector (default=D) \n" 
+         << " diffthr : Threshold for diff checks (=10^-6/10^-4 double/float)" << endl;
+    return(1);
   }
 
@@ -175,15 +222,21 @@
   FFTWServer fftw;
 
-  inp_typ_random = false;
-  if (arg[2][1] == '0')  inp_typ_random = true;
-
-  int sz = atoi(arg[1]);
+  sa_size_t sz = atol(arg[1]);
   int nprt = 50;
-  int prtlev = 0;
-  if (narg > 4) nprt = atoi(arg[4]);
-  if (narg > 5) prtlev = atoi(arg[5]);
+  if (narg > 4) prtlev = atoi(arg[4]);
+  if (narg > 5) nprt = atoi(arg[5]);
   BaseArray::SetMaxPrint(nprt, prtlev);
+  float fs = 1.e-4;
+  double ds = 1.e-6;
+  if (narg > 6) fs = ds = atof(arg[6]);
 
   if (sz < 2) sz = 2;
+
+  char dtyp = 'D';
+  if (narg > 3) dtyp = *arg[3];
+  inp_typ_random = true;
+  if (islower(dtyp))  inp_typ_random = false;
+  dtyp = toupper(dtyp);
+
   FFTServerInterface * ffts;
   if (*arg[2] == 'M')  ffts = fftm.Clone();
@@ -191,36 +244,37 @@
   else ffts = fftp.Clone();
 
-  float fs = 1.e-4;
-  double ds = 1.e-6;
-
+  cout << "\n ============================================= \n"
+       << " ------ Testing FFTServer " << typeid(*ffts).name() << "\n"
+       << "   VecSize= " << sz << " InputType= " 
+       << ( (inp_typ_random ) ? " random " : " fixed(sin+cos) ") << "\n"
+       << " =============================================== " << endl;
+
+  int rc = 0;
   try {
-    if (*arg[3] == 'd') {
-      cout << "\n ========================================== \n"
-	   << "    ------ Testing FFTServer for double ----- \n"
-	   << " ============================================ " << endl;
+    if (dtyp == 'D') {
+      cout << "   ------ Testing FFTServer for double (r_8)----- " << endl;
       if (*arg[2] == 'p') TestFFTPack(ds, sz);
-      else TestFFTS(ds, *ffts, sz);
+      else rc = TestFFTS(ds, *ffts, sz);
     }
     else {
-      cout << "\n ========================================= \n"
-	   << "    ------ Testing FFTServer for float ----- \n"
-	   << " =========================================== " << endl;
+      cout << "   ------ Testing FFTServer for float (r_4)----- " << endl;
       if (*arg[2] == 'p') TestFFTPack(fs, sz);
-      else TestFFTS(fs, *ffts, sz);
-    }
-  }
-  catch(PThrowable exc ) {
+      else rc = TestFFTS(fs, *ffts, sz);
+    }
+  }
+  catch(PThrowable& exc ) {
     cerr << "TestFFT-main() , Catched exception: \n" << exc.Msg() << endl;
+    rc = 97;
   }
   catch(std::exception ex) {
     cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl;
-  }
-
-  /*
+    rc = 98;
+  }
   catch(...) {
     cerr << "TestFFT-main() , Catched ... exception ! " << endl;
-  }
-  */
+    rc = 99;
+  }
   PrtTim("End of tfft ");
   delete ffts;
-}
+  cout << " =========== End of tfft Rc= " << rc << " =============" << endl;
+}
