Index: trunk/SophyaExt/FitsIOServer/fitsntuple.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1047)
+++ trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1136)
@@ -25,5 +25,5 @@
   ownobj_ = true; 
 
-  ReadF(inputfile,hdunum);
+  Read(inputfile,hdunum);
 }
 
@@ -46,39 +46,36 @@
 {
   if (ownobj_ && dobj_ != NULL) delete dobj_;
-  if (column_ != NULL) delete [] column_;
+  //  if (column_ != NULL) delete [] column_;
 }
 
-void FITS_NTuple::Read(char inputfile[],int hdunum)
-{
-  ReadF(inputfile,hdunum);
-}
+//void FITS_NTuple::Read(char inputfile[],int hdunum)
+//{
+//  ReadF(inputfile,hdunum);
+//}
 void FITS_NTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
 {
   fistLineToBeRead_ = firstLine;
   numberOfLinesToBeRead_ = numberOfLines;
-  ReadF(inputfile,hdunum);
+  Read(inputfile,hdunum);
 }
 
 
 
-void FITS_NTuple::Write(char outputfile[], bool OldFile)
+//void FITS_NTuple::Write(char outputfile[], bool OldFile)
+//{
+//  WriteF(outputfile, OldFile);
+//}
+
+void FITS_NTuple::ReadFromFits(FitsInFile& is)
 {
-  WriteF(outputfile, OldFile);
-}
-
-void FITS_NTuple::ReadFromFits()
-{
-  //  if (!fn.IsFitsTable())
-    if (!IsFitsTable())
+  if (!is.IsFitsTable())
     {
       throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
     }
   int nbcols, nbentries;
-  //  nbcols = fn.NbColsFromFits();
-  nbcols = NbColsFromFits();
+  nbcols = is.NbColsFromFits();
   nbentries = 0;
   int k;
-  //  for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) );
-  for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) );
+  for (k=0; k<nbcols; k++) nbentries=max( nbentries, is.NentriesFromFits(k) );
   
   char ** ColName = new char*[nbcols];
@@ -87,12 +84,10 @@
     {
       ColName[k] = new char[LONNOM1]; 
-      //      strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM);
-      strncpy(ColName[k], ColNameFromFits(k).c_str(),LONNOM);
+      strncpy(ColName[k], is.ColNameFromFits(k).c_str(),LONNOM);
       ColName[k][LONNOM] =  '\0';
     }
   for (k=0; k<nbcols;k++)
     {
-      //      char ss= fn.ColTypeFromFits(k);
-      char ss= ColTypeFromFits(k);
+      char ss= is.ColTypeFromFits(k);
       string type;
       if (ss != 'E') 
@@ -123,47 +118,30 @@
     }
   delete [] ColName;
-  //   if (column_ != NULL) delete [] column_;
-  //  column_ = new float[nbentries];
 
-  // j'initialise le NTuple a zero, pour le dimensionner
-  // (SetVal suppose que le ntuple est deja dimensionne)
   r_4* ligne = new r_4[nbcols];
-  //  for (k=0; k<nbcols; k++) ligne[k]=0.;
-  //  for (k=0; k<nbentries;k++) dobj_->Fill(ligne);
-  //  delete [] ligne;
 
-  //%%%%%%
-    int firstln, lastln;
-    if (numberOfLinesToBeRead_ > 0) 
-      {
-	firstln = fistLineToBeRead_;
-	lastln = firstln + numberOfLinesToBeRead_;
-      }
-    else
-      {
-	firstln = 0;
-	lastln  = nbentries;
-      }
-    int numLigne;
-    for (numLigne=firstln; numLigne < lastln; numLigne++)
-      {
-	//	fn.GetBinTabLine(numLigne, ligne);
-	GetBinTabLine(numLigne, ligne);
-	dobj_->Fill(ligne);
-      }
-    delete [] ligne;
+  int firstln, lastln;
+  if (numberOfLinesToBeRead_ > 0) 
+    {
+      firstln = fistLineToBeRead_;
+      lastln = firstln + numberOfLinesToBeRead_;
+    }
+  else
+    {
+      firstln = 0;
+      lastln  = nbentries;
+    }
+  int numLigne;
+  for (numLigne=firstln; numLigne < lastln; numLigne++)
+    {
+      is.GetBinTabLine(numLigne, ligne);
+      dobj_->Fill(ligne);
+    }
+  delete [] ligne;
 
-    //%%%%%%%
+  dobj_->Info()=is.DVListFromFits();
+}
 
-
-    //  for (k=0; k<nbcols;k++) 
-    //    {
-    //     fn.GetBinTabFCol(column_, nbentries, k);
-    //     for (int nent=0; nent<nbentries; nent++) dobj_->SetVal(nent,k, column_[nent]);
-    //   }
-    //  dobj_->Info()=fn.DVListFromFits();
-  dobj_->Info()=DVListFromFits();
-}
-void FITS_NTuple::WriteToFits()
+void FITS_NTuple::WriteToFits(FitsOutFile& os) 
 {
   if(dobj_ == NULL) 
@@ -192,11 +170,11 @@
       strncpy(Noms[k],dobj_->NomIndex(k),LONNOM1);
     }
-  // la librairie fitsio ecrit colonne par colonne 
+
   char* type= new char[ncols+1];
   for (k=0;k<ncols+1;k++) type[k]='E';
   type[ncols]='\0';
   vector<int> dummy;
-  //  fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
-  makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
+
+  os.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
    for (k=0; k< ncols; k++)
     {
@@ -205,17 +183,12 @@
    delete [] Noms;
    delete [] type;
-   for (k=0; k<ncols;k++) putColToFits(k, nentries, getColFromObj(k));
+   float* column =  new float[nentries];
+   for (k=0; k<ncols;k++)
+     {
+       for(int j = 0; j < nentries; j++) column[j]= dobj_->GetVal(j,k);
+       os.putColToFits(k, nentries, column);
+     }
+   delete [] column;
 
 }
 
-float* FITS_NTuple::getColFromObj(int colNr)
-{
-  if (column_ != NULL)
-    {
-      delete [] column_;
-      column_ = NULL;
-    }
-  column_ = new float[dobj_->NEntry()];
-  for(int j = 0; j < dobj_->NEntry(); j++) column_[j]= dobj_->GetVal(j,colNr);
-  return column_;
-}
