Index: /trunk/ArchTOIPipe/Kernel/toiseqbuff.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toiseqbuff.cc	(revision 1483)
+++ /trunk/ArchTOIPipe/Kernel/toiseqbuff.cc	(revision 1484)
@@ -11,8 +11,13 @@
 
 TOISeqBuffered::TOISeqBuffered(int wsz) {
+  data = NULL;
+  flags = NULL;
   AllocBuffer(wsz);
+  setName("toiseqbuff");
 }
 
 TOISeqBuffered::TOISeqBuffered(string nm, int wsz) {
+  data = NULL;
+  flags = NULL;
   AllocBuffer(wsz);
   setName(nm);
@@ -29,4 +34,6 @@
   wsize = wsz;
   buffsize = 2*wsz;
+  if (data)   delete[] data;
+  if (flags)  delete[] flags;
   data = new double[buffsize];
   flags = new int_8[buffsize];
@@ -43,5 +50,6 @@
 void TOISeqBuffered::PrintStatus(ostream & os) const
 {
-  os << "---TOISeqBuffered::PrintStatus() - Name=" << getName() << endl;
+  os << "---TOISeqBuffered::PrintStatus() - Name=" << getName() 
+     << "\n  WindowSize= " << wsize << " BufferSize= " << buffsize << endl;
   os << "Index: FirstIn= " << getFirstIn() << " LastIn= " << getLastIn()
      << "  Total= " << getLastIn()-getFirstIn()+1 << endl;
@@ -72,5 +80,6 @@
 
 void TOISeqBuffered::doWontNeedBefore(int i) {
-  next_out = i;
+  // $CHECK$  Reza 30/4/2001 - Je ne sais pas a quoi ca sert !
+  //  next_out = i; $CHECK$  Reza 30/4/2001
 }
 
Index: /trunk/ArchTOIPipe/Kernel/toiseqbuff.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toiseqbuff.h	(revision 1483)
+++ /trunk/ArchTOIPipe/Kernel/toiseqbuff.h	(revision 1484)
@@ -5,7 +5,10 @@
 #include "toi.h"
 
+// -------------------  TOISeqBuffered ---------------------------
 // Classe de TOI avec buffer, et echantillonnage regulier.
 // Pour le moment au moins,
 // il faut que les providers fassent arriver les donnees par samplenum croissant.
+// ---------------------------------------------------------------
+
 class TOISeqBuffered : public TOIRegular {
 public:
@@ -13,4 +16,8 @@
   TOISeqBuffered(string nm, int wsz=8192);
   virtual ~TOISeqBuffered();
+
+  
+  inline  void SetBufferSize(int wsz)  // ATTENTION - Ne doit pas etre appele
+               { AllocBuffer(wsz); }   // apres le demarrage des threads
 
   virtual void PrintStatus(ostream & os) const; 
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;
Index: /trunk/ArchTOIPipe/SMakefile
===================================================================
--- /trunk/ArchTOIPipe/SMakefile	(revision 1483)
+++ /trunk/ArchTOIPipe/SMakefile	(revision 1484)
@@ -17,5 +17,5 @@
             $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o \
             $(AOBJ)fits2ascii.o $(AOBJ)tstmap2toi.o $(AOBJ)tsttoi2map.o 
-EXELIST := $(AOBJ)simtst $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi \
+EXELIST := $(AOBJ)sfftc $(AOBJ)simtst $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi \
            $(AOBJ)tsttoi2 $(AOBJ)fits2ascii $(AOBJ)tstmap2toi $(AOBJ)tsttoi2map
 
@@ -41,5 +41,7 @@
 $(AOBJ)tstrztoi: $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o $(LIBOLIST)
 	$(LINK.cc)  -o $@ $^ $(LIBS)
-$(AOBJ)simtst: $(AOBJ)simtst.o $(AOBJ)simtoipr.o $(LIBOLIST)
+$(AOBJ)sfftc: $(AOBJ)sfftc.o  $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+$(AOBJ)simtst: $(AOBJ)simtst.o  $(LIBOLIST)
 	$(LINK.cc)  -o $@ $^ $(LIBS)
 $(AOBJ)fits2asc: $(AOBJ)fits2asc.o $(LIBOLIST)
@@ -56,4 +58,6 @@
 	$(LINK.cc)  -o $@ $^ $(LIBS)
 
+$(AOBJ)simtst.o: simtst.cc $(INCLIST)
+$(AOBJ)sfftc.o: sfftc.cc $(INCLIST)
 $(AOBJ)tstrztoi.o: tstrztoi.cc rztoi.h $(INCLIST)
 $(AOBJ)rztoi.o: rztoi.cc rztoi.h $(INCLIST)
@@ -63,5 +67,5 @@
 $(AOBJ)fits2ascii.o: fits2ascii.cc $(INCLIST)
 $(AOBJ)tstmap2toi.o: tstmap2toi.cc $(INCLIST)
-$(AOBJ)tsttoi2toi.o: tsttoi2map.cc $(INCLIST)
+$(AOBJ)tsttoi2map.o: tsttoi2map.cc $(INCLIST)
 
 $(AOBJ)asciitoiwtr.o: asciitoiwtr.cc asciitoiwtr.h toi.h config.h conf.h \
Index: /trunk/ArchTOIPipe/TestPipes/simtst.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/simtst.cc	(revision 1483)
+++ /trunk/ArchTOIPipe/TestPipes/simtst.cc	(revision 1484)
@@ -2,6 +2,17 @@
 
 ----------------   Exemple d'appel  ---------------------
-csh> simtst -start 104385384 -end 104399964 -range -500,500 
-            -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 inputbolo.fits degli.fits xx.ppf
+csh> simtst -start 104385384 -end 104399964 -range -500,500 \
+            -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
+	    inputbolo.fits filt.fits xx.ppf
+# Avec Filtre de Fourier
+csh> simtst -start 104385384 -end 104399964 -range -500,500 \
+            -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
+            -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 \ 
+	    inputbolo.fits filtfft.fits spectre.ppf
+# Autre exemple b545k02
+cool> ./simtst -start 104389122 -end 104649122 -range -1000.,1000. -intoi boloMu
+V_23 -wtoi 8192 -wdegli 1024 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 Cmv/b545k02
+2_16.00_16.49.fits b545.fits b545.ppf
+
 */
 
@@ -28,10 +39,11 @@
   cout << endl;
   if (fgerr) {
-    cout << " simtst : Argument Error ! tstrztoi -h for usage " << endl; 
+    cout << " simtst : Argument Error ! simtst -h for usage " << endl; 
     exit(1);
   }
   else {
-    cout << "\n Usage : simtst [-dbg] [-start snb] [-end sne] \n" 
-	 << "         [-wtoi sz] [-wdegli sz] [-wfft sz] [-keepfft n] \n"
+    cout << "\n Usage : simtst [-intoi toiname] [-start snb] [-end sne] \n" 
+	 << "         [-dbg] [-wtoi sz] [-wdegli sz] [-range min,max] \n"
+	 <<"          [-wfft sz] [-keepfft n] [-killfreq bf,nharm,sigf \n"
 	 << "         inFitsName outFitsName  outPPFName \n" 
 	 << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
@@ -45,4 +57,6 @@
 	 << "   -wfft sz : Activate Fourier filter and sets its width \n"
 	 << "   -keepfft n : Keeps n spectra (if Fourier filter activated) \n" 
+	 << "   -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
+            "              with a gaussian with width=sigf \n" 
 	 << endl;
     exit(0);
@@ -72,4 +86,8 @@
   string intoi = "boloMuV_27";
   bool fg_f_filt = false;
+  bool fg_killfreq = false;
+  int bf_killfreq = 1;
+  int nharm_killfreq = 1;
+  double sigf_killfreq = 1.;
 
   if (narg < 4) Usage(true);
@@ -103,4 +121,10 @@
       keepfft = atoi(arg[ia+1]); ia++;
     }    
+    else if (strcmp(arg[ia],"-killfreq") == 0) {
+      if (ia == narg-1) Usage(true);
+      sscanf(arg[ia+1],"%d,%d,%lf",&bf_killfreq, &nharm_killfreq, &sigf_killfreq);
+      fg_killfreq = true;
+      ia++;
+    }    
     else if (strcmp(arg[ia],"-range") == 0) {
       if (ia == narg-1) Usage(true);
@@ -127,5 +151,5 @@
   InitTim();
 
-  cout << ">>>> tstrztoi: Infile= " << infile << " outFile=" 
+  cout << ">>>> simtst: Infile= " << infile << " outFile=" 
        << outfile << endl; 
   cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
@@ -150,5 +174,5 @@
 
     int w1 = wtoi;
-    int w2 = (fg_f_filt) ? 2*wfft+w1 : w1; 
+    int w2 = (fg_f_filt) ? wfft+w1 : w1; 
 
     //    char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
@@ -234,9 +258,20 @@
     filt.addOutput("incopie", toideglioffcopie);
 
-    Vector fcoef(wfft/2);
-    fcoef = RegularSequence(1., -2./wfft);
+    Vector fcoef(wfft/2+1);
+    //    fcoef = RegularSequence(1., -2./wfft);
+    fcoef = 1.;
+    for(int kfk=0; kfk<nharm_killfreq; kfk++) {
+      double cfreq = bf_killfreq*(kfk+1);
+      double xfreq = 0.;
+      for(int kfj=cfreq-3.*sigf_killfreq; kfj<= cfreq+3.*sigf_killfreq; kfj++) {
+	if ( (kfj < 0) || (kfj >= fcoef.Size() ) )  continue;
+	xfreq = (cfreq-kfj)/sigf_killfreq;
+	fcoef(kfj) -= exp(-xfreq*xfreq);
+      }
+    }
     cout << " Creating Fourier Filter ... " << endl;
     SimpleFourierFilter sfft(fcoef);
     sfft.KeepSpectra(outppfname, keepfft);
+    sfft.ComputeMeanSpectra(true);
     TOISeqBuffered * toifft = NULL;
     TOISeqBuffered * toifiltcopie = NULL;
@@ -259,5 +294,5 @@
       w.addInput("fftout", toifft);
     } 
-    else   w.addInput("out", toiout);
+    else   w.addInput("filtout", toiout);
     w.addInput("degli", toidegli1);
     w.addInput("deglioff", toideglioffcopie);
