Index: trunk/ArchTOIPipe/Kernel/fitstoirdr.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1716)
+++ trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1717)
@@ -4,9 +4,10 @@
 
 
-FITSTOIReader::FITSTOIReader(string fn) {
+FITSTOIReader::FITSTOIReader(string fn,int buff_sz) {
   fname = fn;
   allfn.push_back(fn);
-  cout << "FITSTOIReader::FITSTOIReader" << endl;
-  cout << "FITSTOIReader::inited " << inited << endl;
+  Buff_Sz = (buff_sz>0) ? buff_sz: 1000;
+  cout<<"FITSTOIReader::FITSTOIReader"<<endl;
+  cout<<"FITSTOIReader::inited "<<inited<<" bsz="<<Buff_Sz<<endl;
   name = "rdr";
   fptr = NULL;
@@ -42,5 +43,5 @@
     fits_report_error(stderr, fstatus);
     fits_unlock();
-    exit (-1);
+    exit (-1); // $CHECK EA: normallement ca devrait etre un "throw"
   }
   
@@ -116,5 +117,6 @@
   for (vector<string>::iterator i=allfn.begin(); i!=allfn.end(); i++) {
     openFile(*i);
-    run1();
+    //run1();
+    run2();
   }
 }
@@ -128,8 +130,8 @@
        << firstSn << endl;
 
-  double* tabdata = new double[getNOut()];
-  uint_8* tabflag = new uint_8[getNOut()]; 
-
-  for (int i=0; i<nrows; i++) {
+  double* tabdata = new double[getNOut()]; // $CHECK EA: pas terrible le new never deleted
+  uint_8* tabflag = new uint_8[getNOut()]; // $CHECK EA: pas terrible le new never deleted
+
+  for (int i=0; i<nrows; i++) {  // $CHECK EA: vaut mieux mettre long que int
     int anyNul;
     double y;
@@ -137,5 +139,5 @@
     fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
     //fits_unlock();
-    int sn = (int) (y+.1);
+    int sn = (int) (y+.1); // $CHECK EA: vaut mieux mettre long que int SURTOUT POUR SNUM
     TOIManager* mgr = TOIManager::getManager();
     if (sn > mgr->getRequestedEnd()) {fits_unlock(); break;}
@@ -171,2 +173,72 @@
   cout << "reader done reading... " << pthread_self() << endl;
 }
+
+void FITSTOIReader::run2()
+// ---- Version bufferisee (Christophe 20/10/2001)
+{
+ int ncols = outIx.size();
+ cout<<"reader reading... NRows="<<nrows<<" firstSn= " <<firstSn<<endl;
+
+ //////// Prepare buffer, allocate memory
+ double *samplenum = new double[Buff_Sz];
+ vector<double*> colval;
+ vector<long*> colflg;
+ for(int k=0; k<getNOut(); k++) {
+   colval.push_back(NULL);
+   colflg.push_back(NULL);
+   if(!checkOutputTOIIndex(k)) continue;
+   colval[k] = new double[Buff_Sz];
+   if(colsinput[k].second) colflg[k] = new long[Buff_Sz];
+ }
+
+ //////// Read data and put into pipe
+ long ideb=-1,ifin=-1;
+ for(long i=0; i<nrows; i++) {
+
+   // faut-il lire dans le fichier fits ?
+   if(i<ideb || i>ifin) {
+     ideb = i;
+     ifin = ideb+Buff_Sz-1;
+     if(ifin>=nrows) ifin=nrows-1;
+     long n = ifin-ideb+1;
+     int anyNul;
+     fits_lock();
+     fits_read_col_dbl(fptr,1,ideb+1,1,n,0,samplenum,&anyNul,&fstatus);
+     for(int k=0; k<getNOut(); k++) {
+       if(colval[k]==NULL)  continue;
+       int j = colsinput[k].first;
+       fits_read_col_dbl(fptr,j+1,ideb+1,1,n,0,colval[k],&anyNul,&fstatus);
+       if(colflg[k]==NULL)  continue;
+       fits_read_col_lng(fptr,j+2,ideb+1,1,n,0,colflg[k],&anyNul,&fstatus);
+     }
+     if(fstatus!=0) {
+       fits_report_error(stderr,fstatus);
+       // $CHECK EA: attention j'ai mis un throw OK avec ca ?
+       throw RangeCheckError("FITSTOIReader::run2: Error Reading Fits file\n");
+     }
+     fits_unlock();
+   }
+
+   long ip = i-ideb; // pointeurs dans les buffers
+   long sn = (long) (samplenum[ip]+.1);
+   TOIManager* mgr = TOIManager::getManager();
+   if(sn > mgr->getRequestedEnd()) break;
+   if(sn < mgr->getRequestedBegin()) continue;
+   for(int k=0; k<getNOut(); k++) {
+     if(colval[k]==NULL)  continue;
+     uint_8 flg = (colflg[k]==NULL)? 0: colflg[k][ip];
+     putData(k,sn,colval[k][ip],flg);
+   }
+   totnscount++;
+ }
+
+ //////// des-allocate buffers
+ delete [] samplenum;
+ for(int k=0; k<getNOut(); k++) {
+   if(colval[k]!=NULL) delete [] colval[k];
+   if(colflg[k]!=NULL) delete [] colflg[k];
+ }
+ colval.resize(0); colflg.resize(0);
+
+ cout << "reader done reading... " << pthread_self() << endl;
+}
