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); }
 };
 
