Index: trunk/SophyaExt/FitsIOServer/fitsxntuple.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1047)
+++ trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1136)
@@ -23,5 +23,5 @@
   ownobj_ = true; 
 
-  ReadF(inputfile,hdunum);
+  Read(inputfile,hdunum);
 }
 
@@ -41,30 +41,7 @@
 FITS_XNTuple::~FITS_XNTuple()
 {
-  Clean();
-}
-
-void FITS_XNTuple::Clean()
-{
-  if (dcolumn_ != NULL) delete [] dcolumn_;
-  if (fcolumn_ != NULL) delete [] fcolumn_;
-  if (icolumn_ != NULL) delete [] icolumn_;
-  if (ccolumn_ != NULL)
-    {
-      if (dobj_ != NULL)
-	{
-	  for (int k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k];
-	  delete [] ccolumn_;
-	}
-      else
-	{
-	  cout << "FITS_XNTuple, destructeur: bizarre, ccolumn non vide, sans objet?" << endl;;  	}
-    }
   if (ownobj_ && dobj_ != NULL) delete dobj_;
 }
 
-void FITS_XNTuple::Read(char inputfile[],int hdunum)
-{
-  ReadF(inputfile,hdunum);
-}
 
 void FITS_XNTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum)
@@ -72,28 +49,20 @@
   fistLineToBeRead_ = firstLine;
   numberOfLinesToBeRead_ = numberOfLines;
-  ReadF(inputfile,hdunum);
-  //  return dobj_;
-}
-
-
-void FITS_XNTuple::Write(char outputfile[], bool OldFile)
-{       
-  WriteF(outputfile, OldFile);
-} 
+  Read(inputfile,hdunum);
+}
+
+
  
-void FITS_XNTuple::ReadFromFits()
+void FITS_XNTuple::ReadFromFits(FitsInFile& is)
 {   
-  //  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) );
 
   //
@@ -111,6 +80,5 @@
   for (k=0; k<nbcols;k++)
     {
-      //      char ss= fn.ColTypeFromFits(k);
-      char ss= ColTypeFromFits(k);
+      char ss= is.ColTypeFromFits(k);
       if (ss == 'D') DfitsCol.push_back(k);
       else if (ss == 'E') FfitsCol.push_back(k);
@@ -127,6 +95,5 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      //      strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
-      strncpy(ColName[compt], ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], is.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][ LONNOM] =  '\0';
     }
@@ -134,6 +101,5 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      //      strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
-      strncpy(ColName[compt], ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], is.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][ LONNOM] =  '\0';
     }
@@ -141,6 +107,5 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      //      strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
-      strncpy(ColName[compt], ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], is.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][ LONNOM] =  '\0';
     }
@@ -148,6 +113,5 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      //      strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
-      strncpy(ColName[compt], ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], is.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][LONNOM] =  '\0';
     }
@@ -193,6 +157,5 @@
       cligne = new char*[SfitsCol.size()];
       int  taille_des_chaines=0;
-      //      for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, fn.ColStringLengthFromFits(SfitsCol[k]) );
-      for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, ColStringLengthFromFits(SfitsCol[k]) );
+      for (k=0; k< SfitsCol.size(); k++)  taille_des_chaines = max( taille_des_chaines, is.ColStringLengthFromFits(SfitsCol[k]) );
       for (k=0; k<SfitsCol.size(); k++) cligne[k]=new char[taille_des_chaines+1];
     }
@@ -212,6 +175,5 @@
   for (numLigne=firstln; numLigne < lastln; numLigne++)
     {
-      //      fn.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
-      GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
+      is.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
       dobj_->Fill(dligne, fligne, iligne, cligne);    
     }
@@ -221,9 +183,8 @@
     for (k=0; k< SfitsCol.size(); k++) delete []  cligne[k];
     delete [] cligne; 
-    //  dobj_->Info()=fn.DVListFromFits();
-  dobj_->Info()=DVListFromFits();
-
-}
-void FITS_XNTuple::WriteToFits()
+  dobj_->Info()=is.DVListFromFits();
+
+}
+void FITS_XNTuple::WriteToFits(FitsOutFile& os) 
 {
   if(dobj_ == NULL) 
@@ -270,7 +231,5 @@
   vector<int> StringSizes(dobj_->NSVar());
   for (k=0; k< StringSizes.size(); k++) StringSizes[k]=dobj_->mStrSz;
-  // la librairie fitsio ecrit colonne par colonne 
-  //    fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 
-    makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 
+  os.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 
    for (k=0; k< ncols; k++)
     {
@@ -279,76 +238,64 @@
    delete [] Noms;
    delete [] types;
+
+   
   compt=0;  
-  for (k=0; k<dobj_->NDVar();k++)
-    {
-      putColToFits(compt, dobj_->NEntry(), getColDFromObj(compt));
-      compt++;
-    }
-  for (k=0; k<dobj_->NFVar();k++)
-    {
-      putColToFits(compt, dobj_->NEntry(), getColFFromObj(compt));
-      compt++;
-    }
-  for (k=0; k<dobj_->NIVar();k++)
-    {
-      putColToFits(compt, dobj_->NEntry(), getColIFromObj(compt));
-      compt++;
-    }
-  for (k=0; k<dobj_->NSVar();k++)
-    {
-      putColToFits(compt, dobj_->NEntry(), getColSFromObj(compt));
-      compt++;
-    }
-}
-double* FITS_XNTuple::getColDFromObj(int colNr)
-{
-  if (dcolumn_ != NULL)
-    {
-      delete [] dcolumn_;
-      dcolumn_ = NULL;
-    }
-  dcolumn_ = new double[dobj_->NEntry()];
-  for(int j = 0; j < dobj_->NEntry(); j++) dcolumn_[j]= dobj_->GetDVal(j,colNr);
-  return dcolumn_;
-}
-
-float* FITS_XNTuple::getColFFromObj(int colNr)
-{
-  if (fcolumn_ != NULL)
-    {
-      delete [] fcolumn_;
-      fcolumn_ = NULL;
-    }
-  fcolumn_ = new float[dobj_->NEntry()];
-  for(int j = 0; j < dobj_->NEntry(); j++) fcolumn_[j]= dobj_->GetFVal(j,colNr);
-  return fcolumn_;
-}
- 
-int* FITS_XNTuple::getColIFromObj(int colNr)
-{
-  if (icolumn_ != NULL)
-    {
-      delete [] icolumn_;
-      icolumn_ = NULL;
-    }
-  icolumn_ = new int[dobj_->NEntry()];
-  for(int j = 0; j < dobj_->NEntry(); j++) icolumn_[j]= dobj_->GetIVal(j,colNr);
-  return icolumn_;
-}
-char** FITS_XNTuple::getColSFromObj(int colNr)
-{
-  if (ccolumn_ != NULL)
-    { 
-      for (int k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k];
-      delete [] ccolumn_;
-      ccolumn_ = NULL;
-    }
-  ccolumn_ = new char*[dobj_->NEntry()];
-  for(int j = 0; j < dobj_->NEntry(); j++)
-    {
-      string s= dobj_->GetSVal(j,colNr);
-      ccolumn_[j] = new char[dobj_->mStrSz+1];
-      strcpy(ccolumn_[j],s.c_str());
-    }
-  return ccolumn_; 
-}
+   if (dobj_->NDVar() > 0) 
+     {
+       double* dcolumn = new double[nrows];
+       for (k=0; k<dobj_->NDVar();k++)
+	 {
+	   for(int j = 0; j < nrows; j++) dcolumn[j]= dobj_->GetDVal(j,compt);
+	   os.putColToFits(compt, nrows, dcolumn);
+	   compt++;
+	 }
+       delete [] dcolumn;
+     }
+
+   if (dobj_->NFVar() > 0)
+     {
+       float* fcolumn = new float[nrows];
+       for (k=0; k<dobj_->NFVar();k++)
+	 {
+	   for(int j = 0; j < nrows; j++) fcolumn[j]= dobj_->GetFVal(j,compt);
+	   os.putColToFits(compt, nrows, fcolumn);
+	   compt++;
+	 }
+       delete [] fcolumn;
+     }
+
+   if (dobj_->NIVar() > 0)
+     { 
+       int* icolumn = new int[nrows];
+       for (k=0; k<dobj_->NIVar();k++)
+	 {
+	   for(int j = 0; j < nrows; j++) icolumn[j]= dobj_->GetIVal(j,compt);
+	   os.putColToFits(compt, nrows, icolumn);
+	   compt++;
+	 }
+       delete [] icolumn;
+     }
+
+   if (dobj_->NSVar() > 0)
+     {
+      char**  ccolumn = new char*[nrows];
+      for (k=0; k<dobj_->NSVar();k++)
+	{
+	  int j;
+	  for(j = 0; j < nrows; j++)
+	    {
+	      string s= dobj_->GetSVal(j,compt);
+	      ccolumn[j] = new char[dobj_->mStrSz+1];
+	      strcpy(ccolumn[j],s.c_str());
+	    }
+	  os.putColToFits(compt, nrows, ccolumn);
+	  compt++;
+	  for(j = 0; j < nrows; j++)
+	    {
+	      delete [] ccolumn[j];
+	      ccolumn[j] = NULL;
+	    }
+	}
+      delete [] ccolumn;
+     }
+}
