Index: trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1439)
+++ trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1442)
@@ -101,21 +101,36 @@
   int sne = getMaxIn();
 
+  double* tabdata = new double[ndata];
+  double* tabflag = new double[ndata]; // ? pas integer ?? $CHECK$ - Reza
+  bool* tabck = new bool[ndata];
+  int i;
+  for(i=0; i<ndata; i++) {
+    tabdata[i] = -9.e19;  // $CHECK$ - Reza valeur par defaut !
+    tabflag[i] = -9.e19;  // $CHECK$ - Reza valeur par defaut !
+    tabck[i] = checkInputTOIIndex(i);
+  } 
+
   for (int sn = snb; sn <= sne; sn++) {
+    //    if ((sn%2000 == 0) || (sn<snb+5)) 
+    //  cout << " DBG-A-FitsWriter::run()" << sn << endl;
     try {
+      for (i=0; i<ndata; i++) {
+	if (tabck[i]) {
+	  tabdata[i] = getData(i, sn);
+	  if (outFlags) tabflag[i] = getFlag(i, sn);
+	}
+      }
       fits_lock();
+      //      if ((sn%2000 == 0) || (sn<snb+5)) 
+      //cout << " DBG-B-FitsWriter::run()" << sn << endl;
       double xx = sn;
       fits_write_col_dbl(fptr, 1, fitsLine, 1, 1, &xx, &fstatus);
-      fits_unlock();
-      for (int i=0; i<ndata; i++) {
-	double x = -9.e19;  // $CHECK$ - Reza valeur par defaut !
-	if (checkInputTOIIndex(i)) x = getData(i, sn);
-	fits_lock();
+      
+      for (i=0; i<ndata; i++) {
 	if (outFlags) {
-	  fits_write_col_dbl(fptr, 2*i+2, fitsLine, 1, 1, &x, &fstatus);
-	  if (checkInputTOIIndex(i))   x = getFlag(i, sn);
-	  else x = -9.e19;  // $CHECK$ - Reza valeur par defaut !
-	  fits_write_col_dbl(fptr, 2*i+3, fitsLine, 1, 1, &x, &fstatus);
+	  fits_write_col_dbl(fptr, 2*i+2, fitsLine, 1, 1, tabdata+i, &fstatus);
+	  fits_write_col_dbl(fptr, 2*i+3, fitsLine, 1, 1, tabflag+i, &fstatus);
 	} else {
-	  fits_write_col_dbl(fptr, i+2, fitsLine, 1, 1, &x, &fstatus);
+	  fits_write_col_dbl(fptr, i+2, fitsLine, 1, 1, tabdata+i, &fstatus);
 	}
 	if (fstatus != 0) {
@@ -124,12 +139,18 @@
 	  abort();
 	}
-	fits_unlock();
       }
+      fits_unlock();
+      //           if ((sn%2000 == 0) || (sn<snb+5)) 
+      //      	cout << " DBG-C-FitsWriter::run()" << sn << " line=" << fitsLine << endl;
+      fitsLine++;
     } catch (PException e) {
-      cout << "fitstoiwtr exception " << e.Msg() << endl;
-      continue;
+    cout << "fitstoiwtr exception " << e.Msg() << endl;
+    continue;
     }
-    fitsLine++;
   }
+
+  delete[] tabdata;
+  delete[] tabflag;
+  delete[] tabck;
 
   fits_lock();
@@ -137,5 +158,5 @@
   fits_report_error(stderr, fstatus);
   fits_unlock();
-  cout << "fitstoiwriter done" << endl;
+  cout << "fitstoiwriter done fitsLine= " << fitsLine << endl;
 }
 
Index: trunk/ArchTOIPipe/Kernel/toiseqbuff.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/toiseqbuff.cc	(revision 1439)
+++ trunk/ArchTOIPipe/Kernel/toiseqbuff.cc	(revision 1442)
@@ -63,5 +63,5 @@
   if (!started) return DATA_NOT_YET;
   if (iEnd >= next_in) return DATA_NOT_YET;
-  if (iStart < (next_in-buffsize)) return DATA_DELETED;
+  if (isDataDeleted(iStart)) return DATA_DELETED;
   return DATA_OK;
 }
@@ -102,6 +102,11 @@
   }
   cleanWaitGet();
-  if (isDataDeleted(i))
+  if (isDataDeleted(i)) {
+    if (dbglev > 0) 
+      cout << " TOISeqBuffered::doGetData() - DataDeleted() name=" << getName()  
+	   << " i=" << i << " next_in= " << next_in 
+	   << " next_out=" << next_out << endl;
     throw RangeCheckError("TOISeqBuffered::doGetData(i) : data deleted");
+  }
   while (i >= next_in) { 
     if (i>next_out) next_out = i; 
@@ -163,4 +168,8 @@
   else {
     if (i != next_in) {
+      if (dbglev > 0) 
+	cout << " TOISeqBuffered::doPutData() - i!=next_in() name=" << getName()  
+	     << " i=" << i << " next_in= " << next_in 
+	     << " next_out=" << next_out << endl;
       string msg = "TOISeqBuffered::doPutData() : i!=next_in TOIname="  + getName();
       throw RangeCheckError(msg);
Index: trunk/ArchTOIPipe/Kernel/toiseqbuff.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/toiseqbuff.h	(revision 1439)
+++ trunk/ArchTOIPipe/Kernel/toiseqbuff.h	(revision 1442)
@@ -59,5 +59,5 @@
   inline int_4 &        flagRef(int i) { return flags[i%buffsize]; }
   inline bool           isDataDeleted(int i) 
-    { return((i < next_in-wsize-1) ? true : false); }
+    { return((i < next_in-buffsize-1) ? true : false); }
 };
 
Index: trunk/ArchTOIPipe/ProcWSophya/rztoi.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1439)
+++ trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1442)
@@ -3,5 +3,5 @@
 #include "pexceptions.h"
 #include "fftpserver.h"
-#include "timing.h"
+#include "ctimer.h"
 
 RzTOIProc::RzTOIProc(int w1, int w2, int nmax)
@@ -15,6 +15,6 @@
 void RzTOIProc::init() {
   cout << "RzTOIProc::init" << endl;
-  declareInput("signal");
-  declareOutput("sfout");
+  declareInput("in");
+  declareOutput("out");
   name = "rzproc";
   upExtra = 1;
@@ -33,4 +33,5 @@
 
   try {
+    Timer tm("RzTOIProc::run()");
 
     FFTPackServer ffts;
@@ -116,5 +117,6 @@
 	nkv++;
       }
-      PrtTim("End of bloc");
+
+      tm.Split("End of bloc");
     }
 
@@ -150,22 +152,24 @@
   }
   catch (PException & e) {
-    cout << "RzTOIProc exception Msg= " << e.Msg() << endl;
-  }
-}
-
-
-
-RzSimpleTOIProc::RzSimpleTOIProc(double fact, int npr)
+    cout << "RzTOIProc: Catched exception " << (string)typeid(e).name()
+	 << "\n Msg= " << e.Msg() << endl;
+  }
+}
+
+
+
+RzSimpleTOIProc::RzSimpleTOIProc(int wsz, double fact)
 {
+  if (wsz < 4) wsz = 4;
   cout << "RzSimpleTOIProc::RzSimpleTOIProc() factor= " << fact 
-       << " npr=" << npr << endl; 
+       << " WSize=" << wsz << endl; 
   _fact = fact;
-  _nprt = npr;
+  _wsz = wsz;
 }
 
 void RzSimpleTOIProc::init() {
   cout << "RzSimpleTOIProc::init" << endl;
-  declareInput("signal");
-  declareOutput("sfout");
+  declareInput("in");
+  declareOutput("out");
   name = "rzsimpleproc";
   upExtra = 1;
@@ -177,19 +181,45 @@
   int sne = getMaxIn();
 
-  cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne=" << sne << endl;
+  int nstot = sne-snb;
+  int nbloc = nstot/_wsz;
+  cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne=" 
+       << sne << " NBloc=" << nbloc << endl;
 
   double val;
+  int snlast = snb;
+  int istart,ii,kb;
   try {
-    for (int k=snb; k<sne; k++) {
-      if ((k-snb)%_nprt == 0) 
-	cout << " RzSimpleTOIProc::run() - Processing sample k= " << k
-	     << endl;
-
-      val = getData(0, k);
-      putData(0, k, val*_fact);
-    }
+    Timer tm("RzSimpleTOIProc::run()");
+    Vector vin(_wsz);
+    for (kb=0; kb<nbloc; kb++) {
+      istart = kb*_wsz+snb;
+      if (kb%2 == 0) {  // On parcourt a l'envers
+	cout << " ... Processing bloc[" << kb << "] (Reverse) SampleNum=" 
+	     << istart+_wsz << " ->" << istart << endl;
+	for(ii=_wsz-1; ii>=0; ii--)
+	  vin(ii) = getData(0, ii+istart);
+      }
+      else {  // On parcourt vers l'avant 
+	cout << " ... Processing bloc[" << kb << "] SampleNum=" 
+	     << istart << " ->" << istart+_wsz << endl;
+	for(ii=0; ii<_wsz; ii++)
+	  vin(ii) = getData(0, ii+istart);	
+      }
+      for(ii=0; ii<_wsz; ii++)
+	putData(0, ii+istart, vin(ii)*_fact);
+      snlast = istart+_wsz;
+    }
+    cout << " ... Processing remaining Samples - SN=" 
+	 << snlast << " ->" << sne << endl;
+    for(ii=snlast; ii<sne; ii++) {
+      val = getData(0, ii);
+      putData(0, ii, val*_fact);
+    }
+    
+    
   }
   catch (PException & e) {
-    cout << "RzSimpleTOIProc exception Msg= " << e.Msg() << endl;
-  }
-}
+    cout << "RzSimpleTOIProc exception " << (string)typeid(e).name()
+	 << "\n  Msg= " << e.Msg() << endl;
+  }
+}
Index: trunk/ArchTOIPipe/ProcWSophya/rztoi.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/rztoi.h	(revision 1439)
+++ trunk/ArchTOIPipe/ProcWSophya/rztoi.h	(revision 1442)
@@ -23,5 +23,5 @@
 class RzSimpleTOIProc : public TOIProcessor {
 public:
-  RzSimpleTOIProc(double fact=1.0, int npr=1000);
+  RzSimpleTOIProc(int wsz=1024, double fact=1.0);
   virtual void init();  
   virtual void run();
@@ -29,5 +29,5 @@
 protected:
   double _fact;
-  int _nprt;
+  int _wsz;
 };
 
Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1442)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1442)
@@ -0,0 +1,235 @@
+#include "simtoipr.h"
+#include "toimanager.h"
+#include "pexceptions.h"
+#include "ctimer.h"
+
+SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt)
+{
+  if (wsz < 5) wsz = 5;
+  if (wsz%2 == 0) wsz++;
+  if (maxnpt > wsz) maxnpt = wsz;
+
+  cout << "SimpleDeglitcher::SimpleDeglitcher() WSize= " << wsz 
+       << " nSig=" << ns << " maxNPt=" << maxnpt << endl;
+  
+  wsize = wsz;
+  nsig = ns;
+  maxpoints = maxnpt;
+  totnscount = glnscount = glcount = 0;
+}
+
+SimpleDeglitcher::~SimpleDeglitcher()
+{
+}
+
+void SimpleDeglitcher::init() {
+  cout << "SimpleDeglitcher::init" << endl;
+  declareInput("in");
+  declareOutput("out");
+  declareOutput("mean");
+  declareOutput("sigma");
+  name = "SimpleDeglitcher";
+  //  upExtra = 1;   A quoi ca sert ?
+}
+
+void SimpleDeglitcher::run() {
+
+  //  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  bool fgout = checkOutputTOIIndex(0);
+  bool fgmean = checkOutputTOIIndex(1);
+  bool fgsigma = checkOutputTOIIndex(2);
+  
+  if (!checkInputTOIIndex(0)) {
+    cerr << " SimpleDeglitcher::run() - Input TOI (in) not connected! "
+	 << endl;
+    throw ParmError("SimpleDeglitcher::run() Input TOI (in) not connected!");
+  }
+  if (!fgout && !fgmean && !fgsigma) {
+    cerr << " SimpleDeglitcher::run() - No Output TOI connected! "
+	 << endl;
+    throw ParmError("SimpleDeglitcher::run() No output TOI connected!");
+  }
+  
+  if (!fgout) {
+    cout << "Warning:  SimpleDeglitcher::run() - No TOI connected to out \n"
+	 << " No deglitching would be performed !" << endl;
+  }
+
+  cout << " SimpleDeglitcher::run() SN=" << snb << " - " << sne << endl; 
+  try {
+    // Le debut 
+    int wsz2 = wsize/2;
+    Vector vin(wsize);
+    int k;
+    for(k=0; k<wsize; k++) 
+      vin(k) = getData(0, k+snb);
+    double s = vin.Sum()/wsize;
+    double mean = s/wsize;
+    double s2 = vin.SumX2();
+    double sigma = sqrt(s2/wsize-mean*mean);
+    int kgl = -1;
+    int ii,lastput;
+    bool fgglitch = false;
+    double valcur,valsub,valadd;
+    for(k=0;k<sne-snb;k++) {
+      totnscount++;
+      if (k%10000 == 0) cout << " DBG: K=" << k << endl;
+      // Calcul mean-sigma
+      if ((k>wsz2) && (k<sne-snb-wsz2)) {
+	valsub = vin((k+wsz2)%wsize);
+	vin((k+wsz2)%wsize) = valadd = getData(0, k+snb);
+	s += (valadd-valsub);
+	s2 += (valadd*valadd-valsub-valsub);
+	mean = s/wsize;
+	sigma = sqrt(s2/wsize-mean*mean);
+      }
+
+      //  On gere les sorties Mean et Sigma
+      if (fgmean) 
+	putData(1, k+snb, mean, 0);
+      if (fgsigma) 
+	putData(2, k+snb, sigma, 0);
+
+      if (!fgout)   continue;  // Pas de sortie out (deglitche)
+
+      valcur = vin(k%wsize);
+
+      if (valcur < mean+nsig*sigma) {  // inferieur au seuil
+	if (fgglitch) {  
+	  if (k-kgl < maxpoints) {   // On vient de detecter un glitch
+	    glcount++;
+	    for(ii=kgl; ii<k; ii++) {
+	      putData(0, ii+snb, mean, 7);
+	      glnscount++; 
+	    }
+	    lastput = snb+k-1;
+	  }
+	  else {
+	    for(ii=kgl; ii<k; ii++) {
+	      putData(0, ii+snb, vin(ii%wsize), 0);
+	    }
+	    lastput = snb+k-1;  
+	  } 
+	}
+	putData(0, k+snb, valcur, 0);
+	lastput = snb+k;
+	kgl = -1;  fgglitch = false;
+      }
+      else {  // Superieur au seuil
+	if (fgglitch) {
+	  if (k-kgl+1 >= maxpoints) {  // serie de points > seuil
+	    for(ii=kgl; ii<=k; ii++)   // -> Donc pas glitch
+	      putData(0, ii+snb, vin(ii%wsize), 0);
+	    lastput = snb+k;
+	    fgglitch = false;  
+	  }
+	}
+	else {
+	  if (kgl < 0) {  // debut possible de glitch
+	    fgglitch = true;  kgl = k;
+	  }
+	  else { // On est toujours dans une serie > seuil
+	    putData(0, k+snb, valcur, 0);
+	    lastput = snb+k;
+	  }
+	}
+      }
+
+      if (k%5000 == 0) cout << " ---DBG2: K=" << k << " glcount=" 
+			    << glcount << " LastPut= " << lastput << endl;
+    }  // Boucle sur les num-sample
+    cout << " La fin lastput=" << lastput << " SNE=" << sne; 
+    for(k=lastput-snb; k<sne-snb; k++) 
+      putData(0, k+snb, vin(k%wsize), 0);
+    cout << " DBG3- OUT of try bloc ! " << endl;
+      
+  }  // Bloc try 
+  catch (PException & exc) {
+    cerr << "SimpleDeglitcher: Catched Exception " << (string)typeid(exc).name()
+         << "\n .... Msg= " << exc.Msg() << endl;
+  }                                                                             
+}
+
+
+
+SimpleFilter::SimpleFilter(int wsz, FilterKind fk, double a, double s)
+{
+  if (wsz < 3) wsz = 3;
+  if (wsz%2 == 0) wsz++;
+  cout << "SimpleFilter::SimpleFilter() wsz= " << wsz 
+       << " fk=" << fk << endl; 
+  wsize = wsz;
+  totnscount = 0;
+  coef = new double[wsz];
+  for(int kk=0; kk<wsz; kk++) 
+    coef[kk] = 1./wsize;
+}
+
+SimpleFilter::~SimpleFilter()
+{
+  delete[] coef;
+}
+
+void SimpleFilter::init() {
+  cout << "SimpleFilter::init" << endl;
+  declareInput("in");
+  declareOutput("out");
+  name = "SimpleFilter";
+  //  upExtra = 1;
+}
+
+void SimpleFilter::run() {
+  //  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  cout << " SimpleFilter::run(): snb=" << snb << " sne=" << sne << endl;
+
+  bool fgout = checkOutputTOIIndex(0);
+
+  if (!checkInputTOIIndex(0)) {
+    cerr << " SimpleFilter::run() - Input TOI (in) not connected! "
+	 << endl;
+    throw ParmError("SimpleFilter::run() Input TOI (in) not connected!");
+  }
+  if (!fgout) {
+    cerr << " SimpleFilter::run() - No Output TOI connected! "
+	 << endl;
+    throw ParmError("SimpleFilter::run() No output TOI connected!");
+  }
+  
+
+  try {
+    // Le debut
+    int wsz2 = wsize/2;
+    Vector vin(wsize);
+    int k;
+    for(k=0; k<wsize; k++) 
+      vin(k) = getData(0, k+snb);
+    double mean = vin.Sum()/wsize;
+    for(k=0; k<wsize/2; k++) vin(k) = mean; 
+    for(k=0;k<sne-snb;k++) {
+      totnscount++;
+      // Calcul mean-sigma
+      if ((k>wsz2) && (k<sne-snb-wsz2)) 
+	vin((k+wsz2)%wsize) = getData(0, k+snb);
+      //      if (k == sne-snb-wsz2) {
+      //      }
+      double sortie = 0;
+      for(int ii=0; ii<wsize; ii++) {
+	sortie += vin((ii+k)%wsize)*coef[ii];
+      }
+      putData(0,k+snb,sortie,0);
+    }  // Boucle sur les num-sample
+  }  // Bloc try 
+
+  catch (PException & exc) {
+    cerr << "SimpleFilter: Catched Exception " << (string)typeid(exc).name()
+         << "\n .... Msg= " << exc.Msg() << endl;
+  }                                                                             
+
+
+}
Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.h	(revision 1442)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.h	(revision 1442)
@@ -0,0 +1,75 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef SIMTOIPR_H
+#define SIMTOIPR_H
+
+#include "toiprocessor.h"
+
+// ---------  Un deglitcheur simple
+// Dans chaque fenetre de largeur de wsz
+// if (val > Mean(Window)+ns*Sigma(Window)) val = Mean(Window)
+// Si Pas plus de maxnpt points remplissants cette condition
+
+class SimpleDeglitcher : public TOIProcessor {
+public:
+		SimpleDeglitcher(int wsz=64, double ns=3, int maxnpt=5);
+  virtual	~SimpleDeglitcher();
+
+  virtual void	init();  
+  virtual void	run();
+
+  inline int	WSize() const { return wsize; }
+  inline double NbSigmas() const { return nsig; }
+  inline int	MaxPoints() const { return maxpoints; }
+  
+  inline int	TotalSampleCount() const { return totnscount; }
+  inline int	GlitchCount() const { return glcount; }
+  inline int    GlitchSampleCount() const { return glnscount; }
+  
+protected:
+  int totnscount;   // Nombre total d'echantillon processe
+  int glnscount;    // Nombre total de glitch
+  int glcount;      // Nombre de glitch detecte
+
+  int wsize;        // Taille de fenetre de travail
+  double nsig;      // Seuil en nb de sigmas 
+  int maxpoints;    // Nb maxi de points > ns sigmas
+};
+
+
+//  Un filtre simple, dans le domaine temporel
+//  remplace val -> Somme(val(i)*coeff(i)) ds Fenetre
+
+class SimpleFilter : public TOIProcessor {
+public:
+  enum FilterKind {
+    UserFilter=0,	// User defined filter function
+    MeanFilter=1,       // Replace sample by the window mean value (lowpass)
+    SumFilter=2,        // Replace sample by the window sum (lowpass)
+    GaussFilter=3,      // Apply a gaussian to the window samples
+    DiffFilter=4,	// value -= MeanValue
+  };
+
+		SimpleFilter(int wsz=128, 
+			      FilterKind fk=SimpleFilter::MeanFilter,
+		              double a=1., double s=1.);
+  //		SimpleFilter(int wsz, Arr_DoubleFunctionOfX f=NULL);
+		~SimpleFilter();
+
+  inline FilterKind Type() { return fkind; }
+
+  inline int	WSize() const { return wsize; }
+  inline int	TotalSampleCount() const { return totnscount; }
+
+  virtual void	init();  
+  virtual void	run();
+
+protected:
+  FilterKind fkind;
+  int totnscount;   // Nombre total d'echantillon processe
+  int wsize;        // Taille de fenetre de travail
+  double* coef;     // Coefficients du filtre 
+  
+};
+
+#endif
Index: trunk/ArchTOIPipe/SMakefile
===================================================================
--- trunk/ArchTOIPipe/SMakefile	(revision 1439)
+++ trunk/ArchTOIPipe/SMakefile	(revision 1442)
@@ -11,10 +11,10 @@
 
 LIBOLIST := $(AOBJ)asciitoiwtr.o $(AOBJ)fitstoirdr.o $(AOBJ)fitstoiwtr.o $(AOBJ)toi.o $(AOBJ)toimanager.o $(AOBJ)toiprocessor.o $(AOBJ)toisqfilter.o \
-$(AOBJ)toiseqbuff.o 
+$(AOBJ)toiseqbuff.o $(AOBJ)simtoipr.o 
 EXEOLIST := $(AOBJ)fits2asc.o $(AOBJ)tsttoi.o $(AOBJ)tsttoi2.o
-EXELIST := $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi $(AOBJ)tsttoi2
+EXELIST := $(AOBJ)simtst $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi $(AOBJ)tsttoi2
 
 INCLIST := asciitoiwtr.h fitstoirdr.h fitstoiwtr.h toi.h config.h conf.h \
- toiprocessor.h toimanager.h toiseqbuff.h 
+ toiprocessor.h toimanager.h toiseqbuff.h simtoipr.h 
 
 
@@ -35,4 +35,6 @@
 
 $(AOBJ)tstrztoi: $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+$(AOBJ)simtst: $(AOBJ)simtst.o $(AOBJ)simtoipr.o $(LIBOLIST)
 	$(LINK.cc)  -o $@ $^ $(LIBS)
 $(AOBJ)fits2asc: $(AOBJ)fits2asc.o $(LIBOLIST)
@@ -62,2 +64,4 @@
 $(AOBJ)toiseqbuff.o: toiseqbuff.cc toiprocessor.h config.h conf.h toi.h \
 toiseqbuff.h 
+$(AOBJ)simtoipr.o: simtoipr.cc toiprocessor.h config.h conf.h toi.h \
+simtoipr.h 
Index: trunk/ArchTOIPipe/TestPipes/simtst.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/simtst.cc	(revision 1442)
+++ trunk/ArchTOIPipe/TestPipes/simtst.cc	(revision 1442)
@@ -0,0 +1,191 @@
+#include <unistd.h>
+#include <stdexcept>
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toisqfilter.h"
+#include "toimanager.h"
+#include "simtoipr.h"
+#include "toiseqbuff.h"
+#include "timing.h"
+#include "sambainit.h"
+
+void Usage(bool fgerr)
+{
+  cout << endl;
+  if (fgerr) {
+    cout << " simtst : Argument Error ! tstrztoi -h for usage " << endl; 
+    exit(1);
+  }
+  else {
+    cout << "\n Usage : tstrztoi [-sproc] [-rwtoi] [-dbg] [-start snb] [-end sne] \n" 
+	 << "         [-w1 sz] [-w2 sz] inFitsName outFitsName ppfFileName \n" 
+	 << "   -sproc : Run RzSimpleTOIProc (default RzTOIProc) \n"
+	 << "   -rwtoi : Use Regular Window TOI (default TOISeqBuffered) \n" 
+	 << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
+	 << "   -start snb : sets the start sample num \n"
+	 << "   -end sne : sets the end sample num \n"
+	 << "   -w1 sz : sets main data window size (def= 8192)\n"
+	 << "   -w2 sz : sets secondary window size (def= 512) \n"
+	 << endl;
+    exit(0);
+  }
+}
+
+int main(int narg, char** arg) {
+
+  if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
+
+  cout << "simtst starting - Decoding arguments " << " narg=" << narg << endl;
+
+  bool fgsimple = false;
+  bool fgrwtoi = false;
+  bool fgdbg = false;
+  int w1 = 8192;
+  int w2 = 512;
+  int nmax = 10;
+  int istart = 104121000+w1*5;
+  int iend = 0;
+  string infile;
+  string outfile;
+  string ppffile;
+
+  if (narg < 4) Usage(true);
+  int ko=1;
+  // decoding arguments 
+  for(int ia=1; ia<narg; ia++) {
+    if (strcmp(arg[ia],"-start") == 0) {
+      if (ia == narg-1) Usage(true);  // -start est suivi d'un argument 
+      istart = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-end") == 0) {
+      if (ia == narg-1) Usage(true);  
+      iend = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-w1") == 0) {
+      if (ia == narg-1) Usage(true);  
+      w1 = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-w2") == 0) {
+      if (ia == narg-1) Usage(true);  
+      w2 = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-sproc") == 0)  fgsimple = true;
+    else if (strcmp(arg[ia],"-rwtoi") == 0)  fgrwtoi = true;
+    else if (strcmp(arg[ia],"-dbg") == 0)  fgdbg = true;
+
+    else { ko = ia; break; }  // Debut des noms
+  }
+
+  if (iend < istart) iend = istart+w1*(nmax+5);
+  if ((narg-ko) < 3)  Usage(true); 
+  infile = arg[ko];
+  outfile = arg[ko+1];
+  ppffile = arg[ko+2];
+
+  cout << " Initializing SOPHYA ... " << endl;
+  SophyaInit();
+  InitTim();
+
+  cout << ">>>> tstrztoi: Infile= " << infile << " outFile=" << outfile 
+       << " ppfFile= " << ppffile << endl;
+  cout << ">>>> Window Size W1= " << w1 << " W2= " << w2
+       << "  iStart= " << istart << " iEnd= " << iend << endl;
+  try {
+    TOIManager* mgr = TOIManager::getManager();
+  
+    //  mgr->setRequestedSample(11680920,11710584);
+    //  mgr->setRequestedSample(104121000, 104946120);
+
+    mgr->setRequestedSample(istart, iend);
+  
+    //    FITSTOIReader r("/data/Archeops/bolo11.fits); 
+    FITSTOIReader r(infile); 
+    cout << "reader created" << endl;
+    //    FITSTOIWriter w("/data/Archeops/rz.fits");
+    FITSTOIWriter w(outfile);
+    cout << "fits writer created" << endl;
+
+
+    char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
+    char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
+    TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
+    if (fgdbg) toiin->setDebugLevel(1);
+    TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
+    if (fgdbg) toiout->setDebugLevel(1);
+    TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
+    if (fgdbg) toimean->setDebugLevel(1);
+    TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w1);
+    if (fgdbg) toisig->setDebugLevel(1);
+    
+  
+
+    // Connecting TOI to FITSTOIReader Processor
+    //    for(kk=0; kk<5; kk++) {
+    //      r.addOutput(colname[kk], toitab[kk]);
+    //    }
+
+    int kk = 2;
+    r.addOutput(colname[kk], toiin);
+    //  toi->dbg=true;
+    //  r.addOutput("boloMuV_11", toi);
+    cout << " connecting in/out to RzTOIProcessor ... " << endl;
+
+    //    TOIProcessor * filt = NULL;
+
+    cout << " Creating SimpleDeglitcher() " << endl;
+    SimpleDeglitcher degl;
+    degl.addInput("in", toiin);
+    degl.addOutput("out", toiout);
+    degl.addOutput("mean", toimean);
+    degl.addOutput("sigma", toisig);
+    
+
+
+    w.setOutFlags(true);
+    w.addInput("degli", toiout);
+    w.addInput("mean", toimean);
+    w.addInput("sigma", toisig);
+
+    cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
+    r.PrintStatus(cout);  
+    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
+    w.PrintStatus(cout);  
+
+    PrtTim("starting threads");
+    r.start();
+    degl.start();
+    w.start();
+    
+    //    for(int jj=0; jj<3; jj++) {
+    //      sleep(2);
+    //      cout << *toi; 
+    //    }
+
+    mgr->joinAll();
+    PrtTim("End threads");
+
+    //    cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
+    //    r.PrintStatus(cout);  
+    //    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
+    //    w.PrintStatus(cout);  
+
+    cout << " ------ toiin and toiout Status information ------- " << endl;
+    cout << *toiin; 
+    cout << *toiout;
+  }
+  catch (PThrowable & exc) {
+    cerr << "\nrztsttoi: Catched Exception \n" << (string)typeid(exc).name() 
+	 << " - Msg= " << exc.Msg() << endl;
+  }
+  catch (const std::exception & sex) {
+    cerr << "\nrztsttoi: Catched std::exception \n" 
+	 << (string)typeid(sex).name() << endl; 
+  }
+  catch (...) {
+    cerr << "\nrztsttoi: some other exception was caught ! " << endl;
+  }
+
+  return(0);
+}
Index: trunk/ArchTOIPipe/TestPipes/tstrztoi.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/tstrztoi.cc	(revision 1439)
+++ trunk/ArchTOIPipe/TestPipes/tstrztoi.cc	(revision 1442)
@@ -148,10 +148,10 @@
 
     cout << " Creating Rz TOIProcessors: RzTOIProc () " << endl;
-    RzSimpleTOIProc rzs(2., 1000);
+    RzSimpleTOIProc rzs(w2, 3.);
     RzTOIProc rzp(w1, w2, nmax);
     if (fgsimple) {
       cout << " Using Simple TOIProcessor: RzSimpleTOIProc () " << endl;
-      rzs.addInput("signal", toi);
-      rzs.addOutput("sfout", toi2);
+      rzs.addInput("in", toi);
+      rzs.addOutput("out", toi2);
       }
     else {
@@ -159,6 +159,6 @@
       //      rzp.setOutPPF("/data/Archeops/toto.ppf");
       rzp.setOutPPF(ppffile);
-      rzp.addInput("signal", toi);
-      rzp.addOutput("sfout", toi2);
+      rzp.addInput("in", toi);
+      rzp.addOutput("out", toi2);
     }
 
