Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1483)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1484)
@@ -162,6 +162,9 @@
     uint_8 fgcur;
     bool fgokcur=false;
+
+    int sx_refresh_count = 0;
+    int sx_refresh_count_max = 16*wsize;
+
     // Boucle sur les sampleNum 
-
     int knext;
     int kfin = sne-snb;
@@ -199,6 +202,15 @@
 	} 
 	else {
-	  s += (valadd-valsub);
-	  s2 += (valadd*valadd-valsub*valsub);
+	  if (sx_refresh_count >= sx_refresh_count_max) {
+	    //  On recalcule la somme
+	    s = vas.Sum();
+	    s2 = vas.SumX2();
+	    sx_refresh_count = 0;
+	  }
+	  else {
+	    s += (valadd-valsub);
+	    s2 += (valadd*valadd-valsub*valsub);
+	    sx_refresh_count++;
+	  }
 	  mean = s/wsize;
 	  sigma = sqrt(s2/wsize-mean*mean);
@@ -616,4 +628,7 @@
     throw ParmError("SimpleFourierFilter::SimpleFourierFilter() WSize<16 !");
   KeepSpectra("spectra.ppf", 0);
+  ComputeMeanSpectra(false);
+  totnscount = 0;
+  totnbblock = 0;
 }
 
@@ -629,6 +644,12 @@
      << WSize() << endl; 
   TOIProcessor::PrintStatus(os);
-  os << " Coeff= " << ffcoef << endl;
-  os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
+  os << " Coeff (Size= " << ffcoef.Size() << "): " << endl;  
+  for(int i=0; i<16; i++) {
+    os << ffcoef(i) << "  " ; 
+    if (i == 7) os << endl;
+  }
+  os << "  .... " << endl;
+  os << " ProcessedSampleCount=" << ProcessedSampleCount() 
+     << " NbFFTBlocks= " << totnbblock << endl;
   os << " ------------------------------------------------------ " << endl;
 }
@@ -657,9 +678,11 @@
     throw ParmError("SimpleFourierFilter::run() Input TOI (in) not connected!");
   }
-  if (!fgout) {
-    cerr << " SimpleFourierFilter::run() - No Output TOI connected! "
-	 << endl;
-    throw ParmError("SimpleFourierFilter::run() No output TOI connected!");
-  }
+
+  // ---- On peut utiliser cette classe pour calculer un spectre de Fourier ----
+  //  if (!fgout) {
+  //    cerr << " SimpleFourierFilter::run() - No Output TOI connected! "
+  //	 << endl;
+  //    throw ParmError("SimpleFourierFilter::run() No output TOI connected!");
+  //  }
 
   cout << " SimpleFourierFilter::run() SNRange=" << snb << " - " << sne << endl; 
@@ -673,4 +696,5 @@
     TVector<int_8> vfg(wsize);
     TVector< complex<r_8> > vfft, vfftmean;
+    Vector meanpowerspectra;
     TVector< complex<r_8> > zcoef(ffcoef.Size());
     zcoef = ffcoef;
@@ -684,6 +708,6 @@
     int k,i,klast;
     int nks = 0;
-    int nblk = 0;
     klast = snb-1;
+    totnbblock = 0;
     // Boucle sur les sampleNum
     // 1er partie, on traite par paquets de wsize
@@ -692,21 +716,37 @@
 	getData(0, k+i, vin(i), vfg(i));
       ffts.FFTForward(vin, vfft);
-      if (nblk == 0)  vfftmean = vfft;
-      else vfftmean += vfft;
-      nblk++;
+      if (c_meanspectra) { // Compute mean-spectra
+	if (totnbblock == 0)  { 
+	  vfftmean = vfft;
+	  meanpowerspectra.ReSize(vfft.Size());
+	  for(i=0; i<meanpowerspectra.Size(); i++) 
+	    meanpowerspectra(i) = sqrt(vfft(i).real()*vfft(i).real() + 
+				    vfft(i).imag()*vfft(i).imag() );
+	}
+	else { 
+	  vfftmean += vfft;
+	  for(i=0; i<meanpowerspectra.Size(); i++) 
+	    meanpowerspectra(i) += sqrt(vfft(i).real()*vfft(i).real() + 
+					vfft(i).imag()*vfft(i).imag() );
+	}
+      }
+      totnbblock++;
       if (nks < nb_keep) {
 	TVector< complex<r_8> > vfftcopie;
 	vfftcopie = vfft;
-	string nomvfft = "spectra" + MuTyV(nks);
+	string nomvfft = "spectra" + (string)MuTyV(nks);
 	pout.PutObject(vfftcopie, nomvfft); 
 	nks++;
       }
-      vfft.MulElt(zcoef);
-      ffts.FFTBackward(vfft, vout);
-      for(i=0; i<wsize; i++) 
-	putData(0,k+i,vout(i),vfg(i));
-      if (fgincopie) 
-	for(i=0; i<wsize; i++) 
+      if (fgout) { 
+	vfft.MulElt(zcoef);
+	ffts.FFTBackward(vfft, vout);
+      }
+      for(i=0; i<wsize; i++) {
+	if (fgout) 
+	  putData(0,k+i,vout(i),vfg(i));
+	if (fgincopie)  
 	  putData(1, k+i, vin(i), vfg(i));
+      }
       klast+=wsize;
       totnscount+=wsize;
@@ -720,5 +760,5 @@
       for(k=klast+1; k<=sne; k++) {
 	getData(0, k, inval, inflg);
-	putData(0, k, inval, inflg);
+	if (fgout) putData(0, k, inval, inflg);
 	if (fgincopie) 
 	  putData(1, k, inval, inflg);
@@ -726,9 +766,14 @@
       }
 
-    
-    vfftmean /= complex<r_8>((r_8)nblk, 0.);    
-    pout.PutObject(vfftmean, "meanspectra");
-
-    cout << " SimpleFourierFilter::run() - End of processing " << endl;
+    if (c_meanspectra) { 
+      vfftmean /= complex<r_8>((r_8)totnbblock, 0.);    
+      pout.PutObject(vfftmean, "meanspectra");
+      meanpowerspectra /= (r_8)totnbblock;
+      pout.PutObject(vfftmean, "meanpowerspectra");
+    }
+    pout.PutObject(ffcoef, "fourierfilter");
+
+    cout << " SimpleFourierFilter::run() - End of processing " 
+	 << " NbFFTBlocks= " << totnbblock << endl;
   }  // Bloc try 
 
Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.h	(revision 1483)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.h	(revision 1484)
@@ -160,8 +160,12 @@
   inline  void  KeepSpectra(string outname, int nb) 
                 { outppfname = outname; nb_keep = nb; }
+  inline  void  ComputeMeanSpectra(bool fg)
+                {  c_meanspectra = fg; }
 protected:
   int_8 totnscount;   // Nombre total d'echantillon processe
+  int_8 totnbblock;   // Nombre total de blocs pour FFT
   int wsize;         // Taille de fenetre de travail
   Vector ffcoef;     // Coefficients du filtre
+  bool c_meanspectra;
   int nb_keep;
   string outppfname;
