Index: trunk/ArchTOIPipe/Kernel/flagtoidef.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/flagtoidef.h	(revision 1502)
+++ trunk/ArchTOIPipe/Kernel/flagtoidef.h	(revision 1502)
@@ -0,0 +1,18 @@
+
+enum FlagToiDef {
+// Out of Range Valuet of Range Value
+  FlgToiOut     =  (unsigned long long)1 << 0,
+// Spike-like sample (ex: glitch)
+  FlgToiSpike   =  (unsigned long long)1 << 2,
+// Discontinuity-like sample (ex: step)
+  FlgToiDisc    =  (unsigned long long)1 << 3,
+// Large-Sigma-like sample
+  FlgToiSigma   =  (unsigned long long)1 << 4,
+// Cleaned sample (ex: clean after spike,step...)
+  FlgToiClean   =  (unsigned long long)1 << 5,
+// Sample Value has been interpolated/Replaced ...
+  FlgToiInterp  =  (unsigned long long)1 << 6,
+// et on peut continuer ainsi jusqu'a 1<<63 cad le bit 64 ieme
+// Pour imprimer la valeur: cout<<(unsigned long long)FlgToi...<<endl;
+}
+
Index: trunk/ArchTOIPipe/ProcWSophya/genwproc.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/genwproc.cc	(revision 1501)
+++ trunk/ArchTOIPipe/ProcWSophya/genwproc.cc	(revision 1502)
@@ -6,7 +6,4 @@
 #include "ctimer.h"
 
-
-// #define DEBUGGENW 1 
-
 // -------------------------------------------------------------
 //   Class GenWindowTOIProcessor : generic processor with window
@@ -14,13 +11,15 @@
 
 ////////////////////////////////////////////////////////////////
-GenWindowTOIProcessor::GenWindowTOIProcessor(int nbinput,int nboutput
-                                   ,int wsz, int wstep, int wsztot)
+GenWindowTOIProcessor::GenWindowTOIProcessor(int_4 nbinput,int_4 nboutput
+                                   ,int_4 wsz, int_4 wstep, int_4 wsztot)
 {
   if(nbinput<1) throw ParmError("GenWindowTOIProcessor::Creator nbinput<1 !");
   if(nboutput<0) nboutput=0;
   if(wsz<2) throw ParmError("GenWindowTOIProcessor::Creator wsz<2 !");
-  if(wsz%2==0) wsz++;
+  if(wsz%2==0) {if(wsztot==wsz) wsztot++; wsz++;}
   if(wstep<1) wstep=1;
-  if(wsztot<wsz) wsztot = 2*wsz;  // CMV prise de decision wsztot / wstep
+  if(wsztot<wsz) wsztot = 2*wsz;
+  // cas sans intersection entre 2 samples successifs
+  if(wstep>=wsz) wsztot = wsz;
 
   NbInput = nbinput;
@@ -30,7 +29,10 @@
   WSizeTot = wsztot;
 
-  SNdeb = SNend = StartSample = CurWtIndex = -1;
-  TotNsCount = 0;
-
+  CurWtIndex = -1;
+  SNbegin = SNend = StartSample = LastFilledSn = -1;
+  TotNsCount = TotDecalCount = 0;
+
+  SetDbgLevel();
+  SetWSizeLCR();
   SetDefaultValue();
 
@@ -38,5 +40,5 @@
   TVector<int_8> vi8(1);   // constructeur copie de TArray (taille nulle)
   
-  int k;
+  int_4 k;
   for(k=0;k<NbInput;k++) {
     WDataIn.push_back(vr8);
@@ -44,12 +46,13 @@
     WInFlg.push_back(false);
   }
-  if(NbOutput) for(k=0;k<NbOutput;k++) {
-    WDataOut.push_back(vr8);
-    WFlagOut.push_back(vi8);
-    WOutFlg.push_back(false);
-    WPutOutFlg.push_back(false);
-    WPutOutOwnVector.push_back(false);
-    OutSample.push_back(0);
-  }
+  if(NbOutput)
+    for(k=0;k<NbOutput;k++) {
+      WDataOut.push_back(vr8);
+      WFlagOut.push_back(vi8);
+      WOutFlg.push_back(false);
+      WPutOutFlg.push_back(false);
+      WPutOutOwnVector.push_back(false);
+      OutSample.push_back(0);
+    }
 }
 
@@ -59,18 +62,23 @@
 
 ////////////////////////////////////////////////////////////////
-void GenWindowTOIProcessor::PrintStatus(ostream & os)
-{
-  os<<"\n ------------------------------------------------------ \n" 
-    <<" GenWindowTOIProcessor::PrintStatus() - ["
-    <<NbInput<<","<<NbOutput<<"] (wtot="<<WSizeTot
-    <<" WindowSize="<<GetWSize()
-    <<" WStep= "<<GetWStep()<<endl;
-  TOIProcessor::PrintStatus(os);
-  os<<"ProcessedSampleCount="<<ProcessedSampleCount()<<endl;
-  os<<"------------------------------------------------------ "<<endl;
-}
-
-////////////////////////////////////////////////////////////////
-TVector<r_8> GenWindowTOIProcessor::GetWData(int numtoi)
+void GenWindowTOIProcessor::PrintStatus(ostream & os,int lp)
+{
+os<<"\n ------------------------------------------------------ \n" 
+  <<" GenWindowTOIProcessor::PrintStatus() - ["<<NbInput<<","<<NbOutput<<"]"<<endl
+  <<" WSizeTot="<<WSizeTot<<" WSize="<<GetWSize()<<" WStep= "<<GetWStep()<<endl;
+if(lp>0) {
+  os<<" WindowLCR: "
+    <<" L=("<<W0Left<<","<<GetWSize('l')<<")"
+    <<" C=("<<W0Center<<","<<GetWSize('c')<<")"
+    <<" R=("<<W0Right<<","<<GetWSize('r')<<")"
+    <<endl;
+}
+TOIProcessor::PrintStatus(os);
+os<<"ProcessedSampleCount="<<ProcessedSampleCount()<<" NbDecal="<<TotDecalCount<<endl;
+os<<"------------------------------------------------------ "<<endl;
+}
+
+////////////////////////////////////////////////////////////////
+TVector<r_8> GenWindowTOIProcessor::GetWData(int_4 numtoi)
 {
   if(numtoi<0 || numtoi>=NbInput)
@@ -81,5 +89,5 @@
 }
 
-TVector<int_8> GenWindowTOIProcessor::GetWFlag(int numtoi)
+TVector<int_8> GenWindowTOIProcessor::GetWFlag(int_4 numtoi)
 {
   if(numtoi<0 || numtoi>=NbInput)
@@ -90,5 +98,5 @@
 }
 
-r_8 * GenWindowTOIProcessor::GetWDataPointer(int numtoi)
+r_8 * GenWindowTOIProcessor::GetWDataPointer(int_4 numtoi)
 {
   if(numtoi<0 || numtoi>=NbInput)
@@ -100,5 +108,5 @@
 }
  
-int_8 * GenWindowTOIProcessor::GetWFlagPointer(int numtoi)
+int_8 * GenWindowTOIProcessor::GetWFlagPointer(int_4 numtoi)
 {
   if(numtoi<0 || numtoi>=NbInput)
@@ -109,5 +117,5 @@
 }
 
-void GenWindowTOIProcessor::GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag)
+void GenWindowTOIProcessor::GetData(int_4 numtoi, int_8 numsample, r_8 & data, int_8 & flag)
 {
   if(numtoi<0 || numtoi>=NbInput)
@@ -115,5 +123,5 @@
   if(!WInFlg[numtoi])
     throw ParmError("GenWindowTOIProcessor::GetData : toi not connected!");
-  int_8 k = numsample-GetStartSample();
+  int_8 k = numsample-GetWStartSample();
   if ((k<0) || (k >= GetWSize()))
     throw RangeCheckError("GenWindowTOIProcessor::GetData : numsample out of window!");
@@ -127,5 +135,5 @@
                                     ,TVector<r_8>& data,TVector<int_8>& flag)
 {
-  if(numtoi<0 || numtoi>=NbOutput)
+  if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0)
     throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
   if(!WOutFlg[numtoi])
@@ -145,5 +153,5 @@
                                     ,r_8 data,int_8 flag)
 {
-  if(numtoi<0 || numtoi>=NbOutput)
+  if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0)
     throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
   if(!WOutFlg[numtoi])
@@ -160,4 +168,122 @@
 }
 
+/******* cmv routines
+void GenWindowTOIProcessor::PutWData(int_4 numtoi,int_8 numsample
+                                    ,TVector<r_8>& data,TVector<int_8>& flag)
+{
+  if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0)
+    throw RangeCheckError("GenWindowTOIProcessor::PutWData : toi out of range !");
+  if(!WOutFlg[numtoi])
+    throw ParmError("GenWindowTOIProcessor::PutWData : toi not connected!");
+  if(data.Size()!=flag.Size())
+    throw ParmError("GenWindowTOIProcessor::PutWData : data.Size()!=flag.Size()!");
+  if(data.Size() == 0)
+    throw ParmError("GenWindowTOIProcessor::PutWData : data.Size()==0 !");
+
+  for(int_4 k=0;k<data.Size(); k++)
+     putData(numtoi,numsample+k,data(k),flag(k));
+}
+
+void GenWindowTOIProcessor::PutWData(int_4 numtoi,int_8 numsample
+                                    ,r_8 data,int_8 flag)
+{
+  if(numtoi<0 || numtoi>=NbOutput || NbOutput<=0)
+    throw RangeCheckError("GenWindowTOIProcessor::PutWData : toi out of range !");
+  if(!WOutFlg[numtoi])
+    throw ParmError("GenWindowTOIProcessor::PutWData : toi not connected!");
+
+  putData(numtoi,numsample,data,flag);
+}
+*********/
+
+////////////////////////////////////////////////////////////////
+void GenWindowTOIProcessor::SetWSizeLCR(int_4 wszl,int_4 wszc,int_4 wszr)
+// Fenetre a gauche, au centre et a droite du pixel central
+// Selon la logique:
+//-----------------------------------------------
+//                     | pixel central
+//                     |
+//                     |
+//          | wszl | wszc | wszr |
+//                     |
+//       |           WSize           |
+//-----------------------------------------------
+// wszc toujours impair SVP.
+// Default: 0,0,0 : WSize/2,1,WSize/2
+{
+ int_4 wsz2 = WSize/2;
+ // Default
+ if(wszl<=0 && wszc<=0 && wszr<=0) {
+   WSizeLeft = WSizeRight = wsz2; WSizeCenter = 1;
+   W0Left = 0; W0Center = wsz2;   W0Right = wsz2+1;
+   return;
+ }
+
+ // Fenetre centrale
+ if(wszc<=0)    wszc = 1;
+ if(wszc%2==0)  wszc++;
+ if(wszc>WSize) wszc = WSize;
+ WSizeCenter = wszc;
+ W0Center = wsz2 - WSizeCenter/2;
+
+ // Fenetre de gauche
+ if(wszl<=0) wszl = WSize;
+ W0Left = W0Center - wszl;
+ if(W0Left<0) W0Left = 0;
+ WSizeLeft = W0Center - W0Left;
+ if(WSizeLeft<=0) WSizeLeft = 1;
+
+ // Fenetre de droite
+ if(wszr<=0) wszr = WSize;
+ W0Right = W0Center + WSizeCenter;
+ if(W0Right>=WSize) W0Right = WSize - 1;
+ int_4 dum = W0Right + wszr; if(dum>WSize) dum = WSize;
+ WSizeRight = dum - W0Right;
+ if(WSizeRight<=0) WSizeRight = 1;
+}
+
+TVector<r_8> GenWindowTOIProcessor::GetWData(char cw,int_4 numtoi)
+// cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout
+{
+ if(numtoi<0 || numtoi>=NbInput)
+    throw RangeCheckError("GenWindowTOIProcessor::GetWData(lcr) : toi out of range !");
+ if(!WInFlg[numtoi])
+   throw ParmError("GenWindowTOIProcessor::GetWData(lcr) : toi not connected!");
+ return (WDataIn[numtoi])(Range(StartWtIndex(cw),0,GetWSize(cw)));
+}
+
+TVector<int_8> GenWindowTOIProcessor::GetWFlag(char cw,int_4 numtoi)
+// cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout
+{
+ if(numtoi<0 || numtoi>=NbInput)
+   throw RangeCheckError("GenWindowTOIProcessor::GetWFlag(lcr) : toi out of range !");
+ if(!WInFlg[numtoi])
+   throw ParmError("GenWindowTOIProcessor::GetWFlag(lcr) : toi not connected!");
+ return (WFlagIn[numtoi])(Range(StartWtIndex(cw),0,GetWSize(cw)));
+}
+
+r_8 * GenWindowTOIProcessor::GetWDataPointer(char cw,int_4 numtoi,int_4& n)
+// cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout
+{
+ if(numtoi<0 || numtoi>=NbInput)
+   throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointe(lcr)r : toi out of range !");
+ if(!WInFlg[numtoi])
+   throw ParmError("GenWindowTOIProcessor::GetWDataPointer(lcr) : toi not connected!");
+ n = GetWSize(cw);
+ return (WDataIn[numtoi].Data()+StartWtIndex(cw));
+
+}
+ 
+int_8 * GenWindowTOIProcessor::GetWFlagPointer(char cw,int_4 numtoi,int_4& n)
+// cr='l' fenetre de gauche, 'c' du centre, 'r' de droite, autre = tout
+{
+ if(numtoi<0 || numtoi>=NbInput)
+   throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer(lcr) : toi out of range !");
+ if(!WInFlg[numtoi])
+   throw ParmError("GenWindowTOIProcessor::GetWFlagPointer(lcr) : toi not connected!");
+ n = GetWSize(cw);
+ return (WFlagIn[numtoi].Data()+StartWtIndex(cw));
+}
+
 ////////////////////////////////////////////////////////////////
 void GenWindowTOIProcessor::UserInit(int_8 kstart)
@@ -181,13 +307,14 @@
   cout << "GenWindowTOIProcessor::init" << endl;
   char buff[64];
-  int k;
+  int_4 k;
   for(k=0; k<NbInput; k++) {
     sprintf(buff,"in%d", k);
     declareInput(buff);
   }
-  for(k=0; k<NbOutput; k++) {
-    sprintf(buff,"out%d",k);
-    declareOutput(buff);
-  }
+  if(NbOutput)
+    for(k=0; k<NbOutput; k++) {
+      sprintf(buff,"out%d",k);
+      declareOutput(buff);
+    }
   name = "GenWindowTOIProcessor";
   // upExtra = 1; $CHECK a quoi ca sert EA?
@@ -197,11 +324,12 @@
 {
   //  TOIManager* mgr = TOIManager::getManager();
-  SNdeb = getMinIn();
-  SNend = getMaxIn();
-  if(SNend-SNdeb<WSize)
+  SNbegin = getMinIn();
+  SNend   = getMaxIn();
+
+  if(SNend-SNbegin<WSize)
     throw ParmError("GenWindowTOIProcessor::run : sne-snb<WSize !");
 
   // Allocation des tailles pour les vecteurs
-  int kc, nc=0;
+  int_4 kc, nc=0;
   for(kc=0;kc<NbInput;kc++) {
     if( !(WInFlg[kc]=checkInputTOIIndex(kc)) ) continue;
@@ -214,25 +342,27 @@
     throw ParmError("GenWindowTOIProcessor::run() No input TOI connected!");
   }
-  for(kc=0;kc<NbOutput;kc++) WOutFlg[kc] = checkOutputTOIIndex(kc);
+  if(NbOutput)
+    for(kc=0;kc<NbOutput;kc++) WOutFlg[kc] = checkOutputTOIIndex(kc);
 
   // Lecture des samples et remplissage des vecteurs
-  cout<<"GenWindowTOIProcessor::run() SNRange="<<SNdeb<<" - "<<SNend<<endl; 
+  cout<<"GenWindowTOIProcessor::run() SNRange="<<SNbegin<<" - "<<SNend<<endl; 
   try {
     Timer tm("GenWindowTOIProcessor::run()");
-    for(int_8 ks=SNdeb;ks<=SNend;ks++) {  // CMV gerer le += step
+    int_4 wsz2=WSize/2;
+    int_8 ksend = SNbegin;
+    for(int_8 ks=SNbegin; ks<=SNend; ks+=WStep) {
+
       Remplissage(ks);
-      if (ks == SNdeb) {
-	UserInit(ks);
-	Ecriture();
-      }
-      if ((ks-SNdeb)%WStep == 0) {
-	UserProc(ks);
-	// Il faut traiter les ecritures en sortie 
-	Ecriture();
-      }
+      if(DbgLevel) test_avec_print(ks);
+
+      if(ks == SNbegin) {UserInit(ks); Ecriture();}
+
+      UserProc(ks);
+      Ecriture();
+
+      ksend = ks;
       TotNsCount++;
     }
-    UserEnd(SNend);
-    Ecriture();
+    UserEnd(ksend); Ecriture();
     cout << " GenWindowTOIProcessor::run() - End of processing " << endl;
 
@@ -249,70 +379,95 @@
 //      samples :   sn-ws/2        sn          sn+ws/2
 //      fenetre :   0              ws/2+1      ws-1
-{
-#ifdef DEBUGGENW
- cout << "GenWindowTOIProcessor::Remplissage(" << ks << ") CurWtIndex=" << CurWtIndex << endl;
-#endif 
-
-if(ks<SNdeb || ks>SNend) {
-  cerr << "GenWindowTOIProcessor::remplissage/Erreur : ks(=" << ks << ") <" 
-       << SNdeb << " || ks>" << SNend << endl; 
-  throw RangeCheckError("GenWindowTOIProcessor::remplissage : ks<SNdeb || ks>SNend !");
- }
-int_8 wsz2=WSize/2;
-
-StartSample = ks - wsz2; // peut etre < snb au debut
-
-// Premier remplissage ???? Gestion de la borne inferieure
+// Cette routine doit etre utilisee dans une boucle:
+//      for(int k=???; k<???; k+=WStep) .....
+// Dans le grand buffer WSizeTot il doit y avoir WSize samples
+//      entre ks1=ks-wsz2 et ks2=ks-wsz2  (ks1<=k<=ks2)
+// En ENTREE de cette routine :
+// - CurWtIndex = c'est l'index du tableau WSizeTot qui doit etre rempli
+//                (le dernier index qui a ete rempli par l'appel precedent
+//                 est donc CurWtIndex-1)
+// - LastFilledSn = c'est le dernier numero de sample qui a ete rempli
+//                  dans le tableau WSizeTot par l'appel precedent
+{
+int_4 wsz2=WSize/2;
+
+// Numero de sample du premier element du tableau WSize
+//   (peut etre < SNbegin au debut)
+StartSample = ks - wsz2;
+
+// on doit avoir les samples [ks1,ks2] dans le buffer
+// (mais selon le step, certain peuvent etre deja remplis)
+int_8 ks1 = ks-wsz2, ks2 = ks+wsz2;
+
+if(DbgLevel>1)
+  cout<<"DBG-GenWindowTOIProcessor::Remplissage("<<ks
+      <<") ["<<ks1<<","<<ks2<<"]"
+      <<" CurWtIndex="<<CurWtIndex<<" LastFilledSn="<<LastFilledSn<<endl;
+
+//--------------------------------------------------------
+// Premier remplissage ????
+// Gestion de la borne inferieure pour le permier sample
+//--------------------------------------------------------
 if(CurWtIndex<0) {
-#ifdef DEBUGGENW
-  cout << "GenWindowTOIProcessor::Remplissage 1ere fois" << endl; 
-#endif 
+  if(DbgLevel>1)
+    cout<<"DBG-GenWindowTOIProcessor::Remplissage 1ere fois"<<endl; 
+  for(int_4 ntoi=0; ntoi<NbInput; ntoi++) {
+    if(!WInFlg[ntoi]) continue;
+    for(int_8 k=ks1, j=0; k<=ks2; k++, j++) {
+      if(k>=SNbegin && k<=SNend) {
+        getData(ntoi,k,(WDataIn[ntoi])(j),(WFlagIn[ntoi])(j));
+      } else {
+        (WDataIn[ntoi])(j) = R8DefVal; (WFlagIn[ntoi])(j) = I8DefVal;
+      }
+    }
+  }
+  CurWtIndex = ks2 - ks1 + 1;
+  LastFilledSn = ks2;
+  return;
+}
+
+//--------------------------------------------------------
+// Faut-il decaler ????
+//--------------------------------------------------------
+if(WStep>=WSize) {
+  // On ne decale pas puisque entre 2 appels a la routine
+  // il faut TOUT recharger (aucun sample deja charge n'est utile)
   CurWtIndex = 0;
-  for(int_8 k=ks-wsz2; k<=ks+wsz2; k++) { // Lecture TOI
-    for(int kc=0; kc<NbInput; kc++) {
-      if(!WInFlg[kc]) continue;
-      if(k>=SNdeb && k<=SNend) {
-        getData(kc,k,(WDataIn[kc])(CurWtIndex), (WFlagIn[kc])(CurWtIndex));
-      } else {
-        (WDataIn[kc])(CurWtIndex) = R8DefVal;
-        (WFlagIn[kc])(CurWtIndex) = I8DefVal;
+} else {
+  // Certains samples deja charges sont utiles
+  int_8 ifin = ks2 - LastFilledSn + CurWtIndex-1;
+  if(ifin >= WSizeTot) { // On decale
+    int_8 ideb = CurWtIndex-1 - LastFilledSn + ks1;
+    if(DbgLevel>1)
+      cout<<"DBG-GenWindowTOIProcessor::Remplissage ... Decalage ideb="<<ideb
+          <<" ifin="<<ifin<< endl; 
+    for(int_4 ntoi=0; ntoi<NbInput; ntoi++) {
+      if(!WInFlg[ntoi]) continue;
+      for(int_4 i=ideb, j=0; i<CurWtIndex; i++, j++) {
+        (WDataIn[ntoi])(j) = (WDataIn[ntoi])(i);
+        (WFlagIn[ntoi])(j) = (WFlagIn[ntoi])(i);
       }
     }
-    CurWtIndex++;
-  }
-  return;
-}
-
-// CMV gere decalage seulement si step < wsize sinon copie.
-// Faut-il decaler ????
-if(CurWtIndex == WSizeTot) { // On decale
-#ifdef DEBUGGENW
-  cout << "GenWindowTOIProcessor::Remplissage Decalage " << endl; 
-#endif 
-  for(int kc=0; kc<NbInput; kc++) {
-    if(!WInFlg[kc]) continue;
-      for(int_8 k=1;k<WSize;k++) { // un en moins car on va remplir apres
-        (WDataIn[kc])(k-1) = (WDataIn[kc])(WSizeTot-WSize+k);
-        (WFlagIn[kc])(k-1) = (WFlagIn[kc])(WSizeTot-WSize+k);
-      }
-  }
-  CurWtIndex = WSize-1;
-}
-
-// Remplissage de ks+wsz2 (dernier element de la fenetre pour ks central)
-int_8 kse = ks+wsz2;
-#ifdef DEBUGGENW
-  cout << "GenWindowTOIProcessor::Normal fill " << endl; 
-#endif 
-for(int kc=0; kc<NbInput; kc++) {
-  if(!WInFlg[kc]) continue;
-  if(kse>=SNdeb && kse<=SNend) {
-    getData(kc,kse,(WDataIn[kc])(CurWtIndex),(WFlagIn[kc])(CurWtIndex));
-  } else {
-    (WDataIn[kc])(CurWtIndex) = R8DefVal;
-    (WFlagIn[kc])(CurWtIndex) = I8DefVal;
-  }
-}
-CurWtIndex++;
+    CurWtIndex = CurWtIndex-ideb;
+    TotDecalCount++;
+  }
+}
+
+// Remplissage des samples utiles pour ks
+if(ks1<=LastFilledSn) ks1 = LastFilledSn+1;
+if(DbgLevel>1)
+  cout<<"DBG-GenWindowTOIProcessor::Normal fill de ["<<ks1<<","<<ks2<<"]"<<endl;
+for(int_4 ntoi=0; ntoi<NbInput; ntoi++) {
+  if(!WInFlg[ntoi]) continue;
+  for(int_4 k=ks1, j=CurWtIndex; k<=ks2; k++, j++) {
+    if(k>=SNbegin && k<=SNend) {
+      getData(ntoi,k,(WDataIn[ntoi])(j),(WFlagIn[ntoi])(j));
+    } else {
+      (WDataIn[ntoi])(j) = R8DefVal; (WFlagIn[ntoi])(j) = I8DefVal;
+    }
+  }
+}
+CurWtIndex += ks2 - ks1 + 1;
+LastFilledSn = ks2;
 
 return;
@@ -337,2 +492,60 @@
   for(kc=0; kc<NbOutput; kc++)  WPutOutFlg[kc] = false;
 }
+
+////////////////////////////////////////////////////////////////
+void  GenWindowTOIProcessor::test_avec_print(int_8 ks)
+{
+if(DbgLevel<=0) return;
+
+int i,ii=0;
+r_8   * datatot = WDataIn[0].Data();
+int_8 * flagtot = WFlagIn[0].Data();
+r_8   * data = GetWDataPointer();
+int_8 * flag = GetWFlagPointer();
+int_4 nl,nc,nr;
+r_8   * datal = GetWDataPointer('l',nl);
+int_8 * flagl = GetWFlagPointer('l',nl);
+r_8   * datac = GetWDataPointer('c',nc);
+int_8 * flagc = GetWFlagPointer('c',nc);
+r_8   * datar = GetWDataPointer('r',nr);
+int_8 * flagr = GetWFlagPointer('r',nr);
+
+cout<<"-------- ks = "<<ks<<endl;
+
+if(DbgLevel>2) {
+  cout<<"datatot = ";
+  for(i=0;i<WSizeTot;i++) {ii=0; cout<<" "<<datatot[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+  cout<<"flagtot = ";
+  for(i=0;i<WSizeTot;i++) {ii=0; cout<<" "<<flagtot[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+}
+
+cout<<"data = ";
+for(i=0;i<GetWSize();i++) {ii=0; cout<<" "<<data[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+cout<<"flag = ";
+for(i=0;i<GetWSize();i++) {ii=0; cout<<" "<<flag[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+
+if(DbgLevel>2) {
+  cout<<"datal = ";
+  for(i=0;i<nl;i++) {ii=0; cout<<" "<<datal[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+  cout<<"flagl = ";
+  for(i=0;i<nl;i++) {ii=0; cout<<" "<<flagl[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+  cout<<"datac = ";
+  for(i=0;i<nc;i++) {ii=0; cout<<" "<<datac[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+  cout<<"flagc = ";
+  for(i=0;i<nc;i++) {ii=0; cout<<" "<<flagc[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+  cout<<"datar = ";
+  for(i=0;i<nr;i++) {ii=0; cout<<" "<<datar[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+  cout<<"flagr = ";
+  for(i=0;i<nr;i++) {ii=0; cout<<" "<<flagr[i]; if(i%10==9) {cout<<endl; ii=1;}}
+        if(ii==0) cout<<endl;
+}
+}
Index: trunk/ArchTOIPipe/ProcWSophya/genwproc.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/genwproc.h	(revision 1501)
+++ trunk/ArchTOIPipe/ProcWSophya/genwproc.h	(revision 1502)
@@ -12,29 +12,52 @@
 class GenWindowTOIProcessor : public TOIProcessor {
 public:
-  GenWindowTOIProcessor(int nbinput,int nboutput,int wsz, int wstep=1, int wsztot=-1);
+  GenWindowTOIProcessor(int_4 nbinput,int_4 nboutput,int_4 wsz, int_4 wstep=1, int_4 wsztot=-1);
   virtual ~GenWindowTOIProcessor();
 
-  inline int_8 GetWSize() const { return WSize; }
-  inline int_8 GetWStep() const { return WStep; }
-  inline int_8 ProcessedSampleCount() const { return TotNsCount; }
+  inline int_4 GetWSize() const { return WSize; }
+  inline int_4 GetWStep() const { return WStep; }
+  inline int_4 ProcessedSampleCount() const { return TotNsCount; }
 
-  inline int_8 GetStartSample()  {return StartSample;}
-  inline int_8 GetCenterSample() {return StartSample + WSize/2;}
-  inline int_8 StartSampleNum() { return SNdeb; }
-  inline int_8 EndSampleNum() { return SNend; }
+  // DbgLevel = 0 : No debug
+  // DbgLevel = 1 : Print fenetre WSize
+  // DbgLevel = 2 : 1 + Print logique remplissage/decalage
+  // DbgLevel = 3 : 2 + Print fenetre WSizeTot et WSizeL,C,R
+  inline void SetDbgLevel(int_2 lp=0) {DbgLevel = (lp>0) ? lp : 0;}
+
+  void SetWSizeLCR(int_4 wszl=0,int_4 wszc=0,int_4 wszr=0);
+  inline int_4 GetWSize(char cw)
+               {if     (cw=='l') return WSizeLeft;
+                else if(cw=='c') return WSizeCenter;
+                else if(cw=='r') return WSizeRight;
+                                 return WSize;}
+
+  inline int_8 GetWStartSample()  {return StartSample;}
+  inline int_8 GetWCenterSample() {return StartSample + WSize/2;}
+  inline int_8 GetWCenterIndex()  {return WSize/2;}
+  inline int_8 StartSampleNum()   {return SNbegin;}
+  inline int_8 EndSampleNum()     {return SNend;}
 
   inline void SetDefaultValue(r_8 r8dval=0., int_8 i8dval=0)
                       {R8DefVal = r8dval; I8DefVal = i8dval;}
 
-  TVector<r_8> GetWData(int numtoi=0);
-  TVector<int_8> GetWFlag(int numtoi=0);
-  r_8 * GetWDataPointer(int numtoi=0);
-  int_8 * GetWFlagPointer(int numtoi=0);
-  void GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag);
+  TVector<r_8> GetWData(int_4 numtoi=0);
+  TVector<int_8> GetWFlag(int_4 numtoi=0);
+  r_8 * GetWDataPointer(int_4 numtoi=0);
+  int_8 * GetWFlagPointer(int_4 numtoi=0);
+  void GetData(int_4 numtoi, int_8 numsample, r_8 & data, int_8 & flag);
   inline void GetData(int_8 numsample, r_8 & data, int_8 & flag)
                       { GetData(0, numsample, data, flag); }
 
-  void PutWData(int numtoi,int_8 numsample,TVector<r_8>& data,TVector<int_8>& flag);
-  void PutWData(int numtoi,int_8 numsample,r_8 data,int_8 flag);
+  TVector<r_8> GetWData(char cw,int_4 numtoi=0);
+  TVector<int_8> GetWFlag(char cw,int_4 numtoi=0);
+  r_8   * GetWDataPointer(char cw,int_4 numtoi,int_4& n);
+  int_8 * GetWFlagPointer(char cw,int_4 numtoi,int_4& n);
+  inline   r_8 * GetWDataPointer(char cw,int_4& n)
+                 {return GetWDataPointer(cw,0,n);}
+  inline int_8 * GetWFlagPointer(char cw,int_4& n)
+                 {return GetWFlagPointer(cw,0,n);}
+
+  void PutWData(int_4 numtoi,int_8 numsample,TVector<r_8>& data,TVector<int_8>& flag);
+  void PutWData(int_4 numtoi,int_8 numsample,r_8 data,int_8 flag);
   inline void PutWData(int_8 numsample,TVector<r_8>& data,TVector<int_8>& flag)
                       {PutWData(0,numsample,data,flag);}
@@ -42,5 +65,5 @@
                       {PutWData(0,numsample,data,flag);}
 
-  virtual void PrintStatus(ostream & os);
+  virtual void PrintStatus(ostream & os,int lp=0);
 
   virtual void UserInit(int_8 kstart);
@@ -54,21 +77,31 @@
   void Remplissage(int_8 ks);
   void Ecriture();
-  inline int_8 StartWtIndex()
-         {if(CurWtIndex<0) return -1; else return CurWtIndex-WSize;}
-  inline int_8 CenterWtIndex()
-         {if(CurWtIndex<0) return -1; else return CurWtIndex-(WSize+1)/2;}
+  void test_avec_print(int_8 ks);
+  inline int_4 StartWtIndex()  {return CurWtIndex-WSize;}
+  inline int_4 CenterWtIndex() {return CurWtIndex-(WSize+1)/2;}
+  inline int_4 StartWtIndex(char cw)
+         {if     (cw=='l') return StartWtIndex()+W0Left;
+          else if(cw=='c') return StartWtIndex()+W0Center;
+          else if(cw=='r') return StartWtIndex()+W0Right;
+                           return StartWtIndex();}
 
-  int NbInput,NbOutput;
-  int_8 WSizeTot,WSize,WStep;
-  int_8 SNdeb,SNend;
-  int_8 StartSample,CurWtIndex;
-  int_8 TotNsCount;
-  r_8 R8DefVal;
+  int_2 DbgLevel;
+  int_4 NbInput,NbOutput;
+  int_4 WSizeTot,WSize,WStep;
+  int_4 WSizeLeft,WSizeCenter,WSizeRight, W0Left,W0Center,W0Right;
+  int_8 SNbegin,SNend;
+  int_8 TotNsCount,TotDecalCount;
+  r_8   R8DefVal;
   int_8 I8DefVal;
+
+  int_4 CurWtIndex;   // Prochain index a remplir dans le buffer WSizeTot
+  int_8 LastFilledSn; // Numero du dernier sample remplie
+  int_8 StartSample;  // Numero de sample du 1er element du buffer WSize
+
   vector< TVector<r_8>   > WDataIn;
   vector< TVector<int_8> > WFlagIn;
+  vector< bool > WInFlg;
   vector< TVector<r_8>   > WDataOut;
   vector< TVector<int_8> > WFlagOut;
-  vector< bool > WInFlg;
   vector< bool > WOutFlg;
   vector< bool > WPutOutFlg;
Index: trunk/ArchTOIPipe/TestPipes/tgenw.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/tgenw.cc	(revision 1501)
+++ trunk/ArchTOIPipe/TestPipes/tgenw.cc	(revision 1502)
@@ -1,11 +1,7 @@
 /*   Test de GenWindowTOIProcessor (generic processor with window)
-
 ----------------   Exemple d'appel  ---------------------
-csh> time ./tgenw -intoi bolo -start 1 -end 50000 -wgen 128,1,256 \
-           bols.fits xx.fits
-// CMV tester wgen 16,64,...
+csh> time ./tgenw -intoi bolo -start 1 -end 50000 -wgen 16,1,64 -wlcr 0,0,0 \
+           -dbg 0 toto.fits xx.fits
 */
-
-
 
 #include "machdefs.h"
@@ -27,14 +23,16 @@
 class TGenWProc : public GenWindowTOIProcessor {
 public:
-  TGenWProc(int wsz, int step, int wt);
+  TGenWProc(int ntoiout, int wsz, int step, int wt);
   virtual void UserInit(int_8 kstart);
   virtual void UserProc(int_8 ks);
   virtual void UserEnd(int_8 kend);
-
+protected:
+  int_8 SNRunning;
 };
 
-TGenWProc::TGenWProc(int wsz, int step, int wt)
-  : GenWindowTOIProcessor(1,1,wsz,step,wt)
-{
+TGenWProc::TGenWProc(int ntoiout,int wsz, int step, int wt)
+  : GenWindowTOIProcessor(1,ntoiout,wsz,step,wt)
+{
+  SNRunning = 1;
 }
 void TGenWProc::UserInit(int_8 kstart)
@@ -49,20 +47,107 @@
 void TGenWProc::UserProc(int_8 ks)
 {
-  if ( (ks == StartSampleNum()) || (ks >= EndSampleNum()-1) || (ks%1000 == 0) )
-    cout << "TGenWProc::UserProc(" << ks << ") CenterSample=" << GetCenterSample() << endl;
-  if (GetWStep() > 1) {
+  if( ks==StartSampleNum() || ks>=EndSampleNum()-1 || ks%1000==0 )
+    cout<<"TGenWProc::UserProc("<<ks<<") CenterSample="<<GetWCenterSample()<<endl;
+
+  // Test pour fichier cmv toto.fits (sn=100000+i, bolo=i)
+  r_8 * datatest = GetWDataPointer();
+  for(int_4 i=0;i<WSize;i++) {
+    int_8 k=ks-WSize/2+i;
+    if(k<SNbegin || k>SNend) continue;
+    if(datatest[i]!=k-100000) {cout<<"PROBLEME ks="<<ks<<endl; break;}
+  }
+
+  if(!NbOutput) return;
+
+  if(GetWStep()==1) {
+    // Cas ou on a un step de 1
+    r_8 data;
+    int_8 flag;
+    GetData(ks,data,flag);
+    PutWData(ks,data,flag);
+
+  } else if(GetWStep()<GetWSize()) {
+    // Cas ou on a un step plus petit que la fenetre:
+    // on peut donc reconstituer le TOI original en sortie
+    // (ca marche aussi pour WStep==1 mais test different)
+    // ATTENTION: l'ordre d'ecriture depend de la taille relative
+    // de WSize et WStep.
+    // Il faut en plus faire attention au premier echantillon et au dernier
+    // Visiblement il faut ecrire autant de donnees en sortie que lues en entree (??)
+    // ===> Conduit a une logique d'une simplicite extreme:
+    // ATTENTION: dans certains cas ca bloque car il peut arriver que
+    // SNend ne soit jamais atteint selon les valeurs de WSize/WStep !
+    // et on ne peut donc pas ecrire autant de valeurs en sortie que lues en entree
     TVector<r_8> data;
     TVector<int_8> flag;
-    data = GetWData()(Range(GetWSize()/2,0,GetWStep()));
-    flag = GetWFlag()(Range(GetWSize()/2,0,GetWStep()));
-    PutWData(GetCenterSample(), data, flag);
-  }
-  else {
-    //    PutWData(GetCenterSample(), GetWData()(GetWSize()/2), GetWFlag()(GetWSize()/2));
-    r_8 data;
-    int_8 flag;
-    GetData(GetCenterSample(), data, flag);
-    PutWData(GetCenterSample(), data, flag);
-  }
+    int_4 ideb,ifin,isndeb;
+    if(GetWStep()<=GetWSize()/2+1) {
+      //  ------|------
+      //      ------|------
+      //        :   :
+      //        WStep
+      //        :  :
+      //        d..f
+      ideb = GetWCenterIndex();
+      isndeb = GetWCenterSample();
+      ifin = ideb + GetWStep()-1;
+    } else {
+      //  ------|------
+      //             ------|------
+      //        :          :
+      //            WStep
+      //  :         :
+      //  d.........f
+      ifin = GetWSize()-1;
+      ideb = ifin - GetWStep()+1;
+      isndeb = GetWStartSample() + ideb;
+    }
+    if(isndeb<StartSampleNum()) {
+      cout<<"........ ideb="<<ideb<<" isndeb="<<isndeb<<endl;
+      ideb = StartSampleNum() - GetWStartSample();
+      isndeb = StartSampleNum();
+    }
+    if(GetWStartSample()+ifin>EndSampleNum()) {
+      cout<<"........ ifin="<<ifin<<endl;
+      ifin = EndSampleNum() - GetWStartSample();
+    }
+    cout<<".... ideb="<<ideb<<" ifin="<<ifin<<" isndeb="<<isndeb<<endl;
+    data = GetWData()(Range(ideb,ifin));
+    flag = GetWFlag()(Range(ideb,ifin));
+    PutWData(isndeb,data,flag);
+  } else {
+    // Cas ou on ne peut reproduire le TOI initial
+    // On renumerote les samples
+    // ATTENTION: faut en mettre autant en sortie que lu en entree (???)
+    // ATTENTION: dans certains cas ca bloque car il peut arriver que
+    // SNend ne soit jamais atteint selon les valeurs de WSize/WStep !
+    // et on ne peut donc pas ecrire autant de valeurs en sortie que lues en entree
+    // CA NE MARCHE PAS DANS CE CAS
+    TVector<r_8> data;
+    TVector<int_8> flag;
+    int_4 ideb=0, ifin=GetWSize()-1;
+    int_8 ilen = EndSampleNum() - StartSampleNum() + 1;
+    if(GetWStartSample()+ideb<StartSampleNum()) {
+      cout<<"........ ideb="<<ideb<<endl;
+      ideb = StartSampleNum() - GetWStartSample();
+    }
+    if(GetWStartSample()+ifin>EndSampleNum()) {
+      cout<<"........ ifin="<<ifin<<endl;
+      ifin = EndSampleNum() - GetWStartSample();
+    }
+    data = GetWData()(Range(ideb,ifin));
+    flag = GetWFlag()(Range(ideb,ifin));
+    cout<<".... ideb="<<ideb<<" ifin="<<ifin<<" SNRunning="<<SNRunning<<endl;
+    PutWData(SNRunning,data,flag);
+    SNRunning += ifin-ideb+1;
+    if(SNRunning<=ilen && GetWStep()-GetWSize()>0) {
+      for(int_4 i=0;i<GetWStep()-GetWSize() && SNRunning<=ilen;i++)
+        {PutWData(SNRunning,0.,0); SNRunning++;}
+      // De toute facon impossible a faire puisque
+      // ce putwdata efface le vecteur du putwdata precedent
+    }
+    cout<<".................... SNRunning="<<SNRunning<<endl;
+  }
+  // Oh que voila une logique simple et utilisable par tout un chacun !!!
 }
 
@@ -75,7 +160,8 @@
   }
   else {
-    cout << "\n Usage : tgenw [-dbg] [-start snb] [-end sne] [-intoi name] \n" 
+    cout << "\n Usage : tgenw [-prt] [-dbg dbg] [-start snb] [-end sne] [-intoi name] \n" 
 	 << "         [-wtoi sz] [-wgen sz,step,szt] inFitsName outFitsName \n"
-	 << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
+	 << "   -prt : sets TOISeqBuffered debug level to 1 \n"
+	 << "   -dbg : debug level for GenWProc \n"
 	 << "   -start snb : sets the start sample num \n"
 	 << "   -end sne : sets the end sample num \n"
@@ -83,4 +169,5 @@
 	 << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
 	 << "   -wgen sz,step,szt : sets GenWProc window size, step total size \n"
+	 << "   -wlcr szl,szc,szr : sets LCR Window \n"
 	 << endl;
     exit(0);
@@ -96,16 +183,18 @@
   bool fgdbg = false;
   bool fgsetstart = false;
+  int dbglevel = 0;
   int wtoi = 8192;
   int wgen = 16;
   int stepgen = 1;
+  int wgl = 0, wgc = 0, wgr = 0;
   int wtotgen = 0;
   int istart = 0;
   int iend = 0;
   string infile;
-  string outfile;
+  string outfile = "";
   string outppfname;
   string intoi = "boloMuV_27";
 
-  if (narg < 3) Usage(true);
+  if (narg < 2) Usage(true);
   int ko=1;
   // decoding arguments 
@@ -128,9 +217,17 @@
       sscanf(arg[ia+1],"%d,%d,%d",&wgen,&stepgen,&wtotgen); ia++;
     }    
+    else if (strcmp(arg[ia],"-wlcr") == 0) {
+      if (ia == narg-1) Usage(true);  
+      sscanf(arg[ia+1],"%d,%d,%d",&wgl,&wgc,&wgr); ia++;
+    }    
     else if (strcmp(arg[ia],"-intoi") == 0) {
       if (ia == narg-1) Usage(true);  
       intoi = arg[ia+1]; ia++;
     }    
-    else if (strcmp(arg[ia],"-dbg") == 0)  fgdbg = true;
+    else if (strcmp(arg[ia],"-dbg") == 0) {
+      if (ia == narg-1) Usage(true);  
+      sscanf(arg[ia+1],"%d",&dbglevel); ia++;
+    }    
+    else if (strcmp(arg[ia],"-prt") == 0)  fgdbg = true;
 
     else { ko = ia; break; }  // Debut des noms
@@ -138,8 +235,8 @@
 
   if (iend < istart) iend = istart+wtoi*10;
-  if ((narg-ko) < 2)  Usage(true); 
+  if ((narg-ko) < 1)  Usage(true); 
   infile = arg[ko];
-  outfile = arg[ko+1];
-  //  outppfname = arg[ko+2];
+  if(ko+1<narg) outfile = arg[ko+1];
+  // outppfname = arg[ko+2];
 
   cout << " Initializing SOPHYA ... " << endl;
@@ -150,5 +247,6 @@
        << outfile << endl; 
   cout << ">>> Window Size WTOI= " << wtoi << " WGenSz= " << wgen
-       << " StepGen=" << stepgen << " WTot=" << wtotgen << endl;
+       << " StepGen=" << stepgen << " WTot=" << wtotgen
+       << " Wglcr=" << wgl << "," << wgc <<  "," << wgr << endl;
   cout << ">>>> InTOIName= " << intoi 
        << "  iStart= " << istart << " iEnd= " << iend << endl;
@@ -159,47 +257,57 @@
     //  mgr->setRequestedSample(11680920,11710584);
     //  mgr->setRequestedSample(104121000, 104946120);
-    if (fgsetstart) 
+    if (fgsetstart)
       mgr->setRequestedSample(istart, iend);
   
     FITSTOIReader r(infile); 
     cout << "reader created" << endl;
-    FITSTOIWriter w(outfile);
-    cout << "fits writer created" << endl;
-
+
+    int ntoiout=0;
+    FITSTOIWriter* w=NULL;
+    if(outfile.size()>0) {
+      ntoiout=1;
+      w = new FITSTOIWriter(outfile);
+      w->setOutFlags(true);
+      cout << "fits writer created" << endl;
+    }
 
     TOISeqBuffered * toiin = new TOISeqBuffered("f2in", wtoi);
     if (fgdbg) toiin->setDebugLevel(1);
-      
+
+    TOISeqBuffered * toiout = NULL;
+    if(w) {
+      toiout = new TOISeqBuffered("genout", wtoi);
+      if (fgdbg) toiout->setDebugLevel(1);
+    }
+
+    TGenWProc tgenp(ntoiout, wgen, stepgen, wtotgen);
+    tgenp.SetWSizeLCR(wgl,wgc,wgr);
+    tgenp.SetDbgLevel(dbglevel);
+
     cout << " Connecting to FitsReader ... " << endl;
     r.addOutput(intoi, toiin);
 
-    TOISeqBuffered * toiout = new TOISeqBuffered("genout", wtoi);
-    if (fgdbg) toiout->setDebugLevel(1);
-    TGenWProc tgenp(wgen, stepgen, wtotgen);
+    if(w && toiout) {
+      cout << " Connecting to FitsWriter ... " << endl;
+      w->addInput("genout",toiout);
+    }
 
     cout << " Connecting  TGenWProc ... " << endl;
     tgenp.addInput("in0",toiin);
-    tgenp.addOutput("out0",toiout);
-    
-    cout << tgenp;
-
-    w.addInput("genout", toiout);
+    if(toiout) tgenp.addOutput("out0",toiout);
+    tgenp.PrintStatus(cout,1);
 
     PrtTim("starting threads");
     r.start();
     tgenp.start();
-    w.start();
-
+    if(w) w->start();
 
     /*       
     for(int jj=0; jj<3; jj++) {
       cout << *toiin; 
-      cout << *toiout; 
+      if(toiout) cout << *toiout; 
       sleep(1);
     }
     */
-    
-    
-    
 
     mgr->joinAll();
@@ -209,12 +317,14 @@
     //    r.PrintStatus(cout);  
     //    cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
-    //    w.PrintStatus(cout);  
+    //    w->PrintStatus(cout);  
 
     cout << " ------ toiin, toiout Status information ------- " << endl;
     cout << *toiin; 
-    cout << *toiout; 
-    
-    cout << tgenp;
-    
+    if(toiout) cout << *toiout;
+    tgenp.PrintStatus(cout);
+
+    // Fermeture du fitswriter
+    if(w) delete w;;
+
   }
   catch (PThrowable & exc) {
