Index: /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1438)
+++ /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1439)
@@ -32,9 +32,7 @@
 }
 
-
-void FITSTOIWriter::run() {
-  cout << "fitstoiwriter running" << endl;
-  // init done here
-  delete[] inTOIs;
+void FITSTOIWriter::afterinit()
+{
+  if (inTOIs) delete[] inTOIs;
   inTOIs = new (TOI*[fwinputs.size()]);
 
@@ -42,4 +40,12 @@
     inTOIs[i] = fwinputs[i];
   }
+  
+}
+
+void FITSTOIWriter::run() {
+  cout << "fitstoiwriter running" << endl;
+  // init done here
+  afterinit();
+  inited=true;
 
   int ndata = inIx.size();
@@ -54,15 +60,25 @@
   colunits[0] = "integer";
 
+  cout << " FITSTOIWriter::run() - Creating output FITS file: "
+       << name << endl;
+
+  vector<string> coln;
+  int ck=0;
   for (map<string, int>::iterator ii = inIx.begin(); ii != inIx.end(); ii++) {
     int j = (*ii).second;
-    string n = (*ii).first;
+    coln.push_back((*ii).first);
     if (outFlags) j += j;
-    colnames[j+1] = const_cast<char*>(n.c_str());
+    colnames[j+1] = const_cast<char*>(coln[ck].c_str());  
+    cout << " Column[" << j+1 << "] Name=" << coln[ck] << endl;
+    ck++;
     coltypes[j+1] = "1D";
-    colunits[j+1] = "?";
+    colunits[j+1] = "double";
     if (outFlags) {
-      colnames[j+2] = const_cast<char*>((n+"_flg").c_str());
+      coln.push_back("fg_" + coln[ck-1]); 
+      colnames[j+2] = const_cast<char*>(coln[ck].c_str());  
+      cout << " Column[" << j+1 << "] -Flag- Name=" << coln[ck] << endl;
+      ck++;
       coltypes[j+2] = "1D";
-      colunits[j+2] = "?";
+      colunits[j+2] = "IntFlag";
     }
   }
Index: /trunk/ArchTOIPipe/Kernel/fitstoiwtr.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoiwtr.h	(revision 1438)
+++ /trunk/ArchTOIPipe/Kernel/fitstoiwtr.h	(revision 1439)
@@ -16,4 +16,6 @@
   ~FITSTOIWriter();
   
+  virtual void afterinit();
+
   virtual void  addInput(string name, TOI* toi);
 
Index: /trunk/ArchTOIPipe/Kernel/toiprocessor.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toiprocessor.cc	(revision 1438)
+++ /trunk/ArchTOIPipe/Kernel/toiprocessor.cc	(revision 1439)
@@ -47,8 +47,8 @@
   inTOIs = new (TOI*[inIx.size()]);
   for(i=0; i<inIx.size(); i++) 
-    inTOIs[i] = NULL;
+    inTOIs[i] = NULL;     // Protection-Initialisation - Reza  11/3/2001
   outTOIs = new (TOI*[outIx.size()]);
   for(i=0; i<outIx.size(); i++) 
-    outTOIs[i] = NULL;
+    outTOIs[i] = NULL;    // Protection-Initialisation - Reza  11/3/2001
 }
 
@@ -80,4 +80,5 @@
   for (int i=0; i<nIn; i++) {
     TOI* toi = inTOIs[i];
+    if (toi == NULL) continue;  // Protection - Reza  13/3/2001
     int x = toi->getMinSn();
     if (x > minIn) minIn = x;
@@ -91,4 +92,5 @@
   for (int i=0; i<nIn; i++) {
     TOI* toi = inTOIs[i];
+    if (toi == NULL) continue;  // Protection - Reza  13/3/2001
     int x = toi->getMaxSn();
     if (x < maxIn) maxIn = x;
@@ -163,4 +165,5 @@
 void TOIProcessor::PrintStatus(ostream & os) 
 {
+  chkinit();
   os << " TOIProcessor::PrintStatus() - Name= " << name 
      << " MinIn=" << getMinIn() << " MaxIn=" << getMaxIn() << endl;
@@ -191,5 +194,6 @@
   if (i == inIx.end()) throw NotFoundExc("TOIProcessor::addInput "+
 					 name+" not declared");
-  inTOIs[(*i).second] = toi; 
+  inTOIs[(*i).second] = toi;
+  toi->addConsumer(this);   // $CHECK$  Reza 13/3/2001 
 }
 
Index: /trunk/ArchTOIPipe/ProcWSophya/rztoi.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1438)
+++ /trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1439)
@@ -45,12 +45,13 @@
     if (outppf.length() > 0)    fgppf = true;
     
-    Vector vin, vout;
+    Vector vin, vout, vsave(_width2);
     TVector< complex<r_8> > vfft;
+    double vlast = 0.;
 
     for (int k=0; k<_nmax; k++) {
-      istart = snb + k*_width1;
-      //      if (k>0)  istart -= _width2;
+      //      istart = snb + k*_width1;
+      istart = snb + k*_width1 - k*_width2;
       iend = istart +_width1;
-      cout << " RzTOIProc::run() - Processing bloc k= " << k 
+      cout << "---RzTOIProc::run() - Processing bloc k= " << k 
 	   << " istart= " << istart << " iend= " << iend << endl;
       if (iend > sne) {
@@ -60,12 +61,22 @@
       //      Vector vin = getData(0, istart, iend);
       vin.ReSize(_width1);
-      jj = 0;
-      for(ii=istart; ii<iend; ii++)  
-	vin(jj++) = getData(0, ii);
-      
-      cout << " End of getData() for bloc " << k << endl;
+      if (k == 0) {
+	jj = 0;
+	for(ii=istart; ii<iend; ii++)  
+	  vin(jj++) = getData(0, ii);
+      }
+      else {
+	vin(Range(0,-1,_width2)) = vsave;
+	jj = _width2;
+	for(ii=istart+_width2; ii<iend; ii++)  
+	  vin(jj++) = getData(0, ii);
+      }
+
+      vsave = vin(Range(_width1-_width2, -1,_width2));
+      cout << "> End of getData() for bloc " << k << endl;
 
       vout.ReSize(vin.Size());
-      double vlast = 0.;
+      //      cout << " DBG : Bloc[" << k << "] FirstSN=" << istart
+      //	   << " LastSN= " << istart+vout.Size()-_width2-1 << endl;
       for(int i=0; i<vout.Size()-_width2; i++) {
 	vout(i) = vin(Range(i,-1,_width2)).Sum()/(r_8)_width2;
@@ -76,9 +87,10 @@
       for(int i=vout.Size()-_width2; i<vout.Size(); i++) {
 	vout(i) = vlast;
-	putData(0, i+istart, vout(i));
+	//	putData(0, i+istart, vout(i));
       }
 
-      cout << " End of putData() for bloc " << k << " Mean vout= " 
-	   << vout.Sum()/vout.Size() << endl;
+      cout << ">> End of putData() for bloc[" << k << "] FirstSN=" 
+	   << istart << " LastSN= " << istart+vout.Size()-_width2-1 
+	   << " Mean vout= " << vout.Sum()/vout.Size() << endl;
 
       vin -= vout;
@@ -121,6 +133,10 @@
     }
 
-    cout << " Filling -9999 : putData(0, ii, -9999.) ii: "
+    cout << " Filling with flag!=0  : putData(0, ii, flag) ii: "
 	 << iend << " .. " << sne << endl;
+    for(ii=iend-_width2; ii<iend; ii++) {
+      putData(0, ii, vlast, 1);
+    }
+
     double xxx;
     for(ii=iend; ii<sne; ii++) {
@@ -129,5 +145,5 @@
 	     << endl;
       xxx=getData(0,ii);
-      putData(0,ii,xxx-9999.);
+      putData(0,ii,xxx,2);
     }
 
Index: /trunk/ArchTOIPipe/TestPipes/tstrztoi.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tstrztoi.cc	(revision 1438)
+++ /trunk/ArchTOIPipe/TestPipes/tstrztoi.cc	(revision 1439)
@@ -1,3 +1,4 @@
 #include <unistd.h>
+#include <stdexcept>
 #include "toi.h"
 #include "toiprocessor.h"
@@ -105,9 +106,9 @@
     //    FITSTOIWriter w("/data/Archeops/rz.fits");
     FITSTOIWriter w(outfile);
-    w.setOutFlags(true);
     cout << "fits writer created" << endl;
 
 
     char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
+    char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
     TOI* toitab[5];
     TOI* toi2;
@@ -116,5 +117,5 @@
       cout << " Using TOIRegularWindow TOI's ... " << endl;
       for(kk=0; kk<5; kk++) {
-	toitab[kk] = new TOIRegularWindow((string)"t_"+colname[kk]);
+	toitab[kk] = new TOIRegularWindow(toiname[kk]);
       }
       toi2 = new TOIRegularWindow("t2");
@@ -123,5 +124,5 @@
       cout << " Using TOISeqBuffered TOI's ... " << endl;
       for(kk=0; kk<5; kk++) {
-	TOISeqBuffered * toisb = new TOISeqBuffered((string)"t_"+colname[kk], w1);
+	TOISeqBuffered * toisb = new TOISeqBuffered(toiname[kk], w1);
 	toitab[kk] = toisb;
 	if (fgdbg) toisb->setDebugLevel(1);
@@ -163,5 +164,11 @@
 
 
-    w.addInput("bolo_filtered", toi2);
+    w.setOutFlags(true);
+    w.addInput("bolodrift", toi2);
+
+    cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
+    r.PrintStatus(cout);  
+    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
+    w.PrintStatus(cout);  
 
     PrtTim("starting threads");
@@ -170,14 +177,18 @@
     else rzp.start();
     w.start();
-
-    r.PrintStatus(cout);  
     
-    for(int jj=0; jj<3; jj++) {
-      sleep(2);
-      cout << *toi; 
-    }
+    //    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 << " ------ toi and toi2 Status information ------- " << endl;
     cout << *toi; 
@@ -185,9 +196,13 @@
   }
   catch (PThrowable & exc) {
-    cerr << "rztsttoi: Catched Exception \n" << (string)typeid(exc).name() 
+    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 << "rztsttoi: some other exception was caught ! " << endl;
+    cerr << "\nrztsttoi: some other exception was caught ! " << endl;
   }
 
