Index: /trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.cc	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.cc	(revision 1136)
@@ -20,9 +20,10 @@
 
   //  FitsFile* fn=ReadFInit(inputfile,hdunum);
-  ReadFInit(inputfile,hdunum);
-
+  //  ReadFInit(inputfile,hdunum);
+  inFits_  = new FitsInFile (inputfile);
+  inFits_->ReadFInit(hdunum);
 
   //  if (!fn->IsFitsTable())
-  if (!IsFitsTable())
+  if (!inFits_->IsFitsTable())
     {
       throw PException("FITS_BntblLineReader: the fits file seems not to be a bintable nor ASCII table");
@@ -32,9 +33,9 @@
   int nbcols, nbentries;
   //  nbcols = fn->NbColsFromFits();
-  nbcols = NbColsFromFits();
+  nbcols = inFits_->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, inFits_->NentriesFromFits(k) );
 
   //
@@ -53,5 +54,5 @@
     {
       //      char ss= fn->ColTypeFromFits(k);
-      char ss= ColTypeFromFits(k);
+      char ss= inFits_->ColTypeFromFits(k);
       if (ss == 'D') DfitsCol.push_back(k);
       else if (ss == 'E') FfitsCol.push_back(k);
@@ -69,5 +70,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], inFits_->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
       ColName_[compt++][ LONNOM] =  '\0';
     }
@@ -76,5 +77,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], inFits_->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
       ColName_[compt++][ LONNOM] =  '\0';
     }
@@ -83,5 +84,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], inFits_->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
       ColName_[compt++][ LONNOM] =  '\0';
     }
@@ -90,5 +91,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], inFits_->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
       ColName_[compt++][LONNOM] =  '\0';
     }
@@ -115,5 +116,5 @@
       taille_des_chaines_ = 0;
       //      for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, fn->ColStringLengthFromFits(SfitsCol[k]) );
-      for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, ColStringLengthFromFits(SfitsCol[k]) );
+      for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, inFits_->ColStringLengthFromFits(SfitsCol[k]) );
       for (k=0; k<ccount_; k++) cdata_[k]=new char[taille_des_chaines_+1];
     }
@@ -123,4 +124,5 @@
 FITS_BntblLineReader::~FITS_BntblLineReader()
 {
+  if (inFits_ != NULL) delete inFits_;
   if (ddata_ != NULL) delete [] ddata_;
   if (fdata_ != NULL) delete [] fdata_;
@@ -147,5 +149,5 @@
 XNTuple FITS_BntblLineReader::ReadNextLine()
 {
-  GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );
+  inFits_->GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );
   XNTuple xnt(dcount_, fcount_, icount_,ccount_, ColName_); 
   xnt.Fill(ddata_, fdata_, idata_, cdata_);    
@@ -153,9 +155,9 @@
 }
 
-void  FITS_BntblLineReader::ReadFromFits()
+void  FITS_BntblLineReader::ReadFromFits(FitsInFile&)
 {   
 }
 
-void FITS_BntblLineReader::WriteToFits()
+void FITS_BntblLineReader::WriteToFits(FitsOutFile&)
 {
 }
Index: /trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.h	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.h	(revision 1136)
@@ -13,5 +13,5 @@
 ///////////////////////////////////////////////////////////
 
-class  FITS_BntblLineReader : public FitsFile  
+class  FITS_BntblLineReader : public FitsIOHandler  
 {
 
@@ -25,6 +25,6 @@
  inline  void SetStartingLineIndex(long n)  { nextLineToBeRead_ = n;}
 
- inline int status() const {return statusF();};
- inline string getStatus(int status) const {return getErrStatus(status);}; 
+ inline int status() const {return inFits_->statusF();};
+ inline string getStatus(int status) const {return inFits_->getErrStatus(status);}; 
 
 
@@ -34,6 +34,6 @@
   // implementation de FitsFile
  //  virtual void  ReadFromFits(FitsFile& fn);
-  virtual void  ReadFromFits();
-virtual void    WriteToFits();
+  virtual void  ReadFromFits(FitsInFile& is);
+virtual void    WriteToFits(FitsOutFile& os);
 
  private :
@@ -41,4 +41,5 @@
 inline void InitNull()
    {
+     inFits_ = NULL;
      nextLineToBeRead_= 0;
      dcount_ = 0;
@@ -54,4 +55,6 @@
    }
   // attributs de classe
+
+ FitsInFile* inFits_;
   long nextLineToBeRead_;
   int dcount_;
Index: /trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1136)
@@ -6,11 +6,39 @@
 #include "anydataobj.h" 
 #include "fitsspherehealpix.h"
-FitsFile::FitsFile() 
-{
-  InitNull();
-}
+
+
+void   FitsIOHandler::Read(char flnm[],int hdunum)
+{
+  //  FitsInFile ifts(flnm, hdunum);
+  FitsInFile ifts(flnm);
+  Read(ifts, hdunum);
+}
+void FitsIOHandler::Read(FitsInFile& is, int hdunum) 
+{
+  if (hdunum == 0)  is.moveToFollowingHeader();
+  else is.ReadFInit(hdunum);
+  ReadFromFits(is);
+}
+
+
+void FitsIOHandler::Write(char flnm[], bool OldFile) 
+
+{
+
+  FitsOutFile of(flnm, OldFile);
+  Write(of);
+}
+
+void FitsIOHandler::Write(FitsOutFile& os) 
+{
+  WriteToFits(os);
+}
+
+
+
  
 FitsFile::~FitsFile()
 {
+  cout << " destructeur FitsFile " << endl;
   int status = 0;
   if( fptr_ != NULL)
@@ -22,10 +50,61 @@
 }
 
-void FitsFile::InitNull()
-{
-  fptr_= NULL; 
-  hdutype_= 0;
-  hdunum_ = 0; 
-
+
+void FitsFile::printerror(int &status) 
+  //*****************************************************/
+  //* Print out cfitsio error messages and exit program */
+  //*****************************************************/
+{
+  if( status )
+    {
+      fits_report_error(stderr,status);
+      throw IOExc("FitsFile:: error FITSIO status");
+    }
+  return;
+}
+
+void FitsFile::printerror(int& status, char* texte) 
+  //*****************************************************/
+  //* Print out cfitsio error messages and exit program */
+  //*****************************************************/
+{
+  // print out cfitsio error messages and exit program 
+  // print error report  
+  fits_report_error(stderr, status);
+  cout << " erreur:: " << texte << endl;
+  throw IOExc("FitsFile:: error FITSIO status");
+}
+
+void FitsFile::ResetStatus(int& status) 
+{
+  fits_status_ = status;
+  status = 0;
+}
+
+string FitsFile::getErrStatus(int status) 
+{
+  char text[31];
+  fits_get_errstatus(status, text);
+  return string(text);
+}
+
+FitsInFile::FitsInFile()
+{
+  InitNull();
+}
+//FitsInFile::FitsInFile(char flnm[], int hdunum)
+FitsInFile::FitsInFile(char flnm[])
+{
+  InitNull();
+  int status = 0;
+  fits_open_file(&fptr_,flnm,READONLY,&status);
+  if( status ) printerror( status );
+  //  ReadFInit(flnm, hdunum);
+}
+
+
+void FitsInFile::InitNull()
+{
+  cout << " init FitsInFile " << endl;
   bitpix_ = 0;
   naxis_ = 0;
@@ -33,5 +112,4 @@
   nrows_ = 0;
   nbcols_ = 0;
-  fits_status_ = 0;
   naxisn_.clear();
   repeat_.clear();
@@ -42,5 +120,5 @@
 
 
-int FitsFile::NbBlocks(char flnm[])
+int FitsInFile::NbBlocks(char flnm[])
 {
   int status = 0;
@@ -54,5 +132,5 @@
 }
 
-void FitsFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
+void FitsInFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
 {
   int status = 0;
@@ -123,22 +201,46 @@
 }
 
-void FitsFile::ReadF(char flnm[],int hdunum) 
-{
-  ReadFInit(flnm, hdunum);
-  //  ReadFromFits(*this);
-    ReadFromFits();
-}
-
-
-//FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum) 
-void FitsFile::ReadFInit(char flnm[],int hdunum) 
-{
-  InitNull();
-  int status = 0;
-  //  hdutype_= 0;
+void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
+{
+  int hdunum=0;
+  cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
+  int status= 0;
+
+  // bits per pixels
+  fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
+  if( status )  printerror( status );
+
+  // number of dimensions in the FITS array
+  naxis= 0;
+  fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
+  if( status ) printerror( status );
+  //  cout << " dimension lue " << naxis << endl;
+  // read the NAXISn keywords to get image size
+  long* naxes = new long[naxis] ;
+  int nfound;
+  fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
+  if( status ) printerror( status );
+  if (nfound != naxis ) 
+    cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
+  int k;
+  for (k=0; k<naxis; k++) 
+    {
+      naxisn.push_back( (int)naxes[k] );
+    }
+  delete [] naxes;
+}
+
+
+//void FitsInFile::ReadFInit(char flnm[],int hdunum) 
+void FitsInFile::ReadFInit(int hdunum) 
+{
+  // InitNull();
+  // int status = 0;
   
-  fits_open_file(&fptr_,flnm,READONLY,&status);
-  if( status ) printerror( status );
-  //
+  //  fits_open_file(&fptr_,flnm,READONLY,&status);
+  //  if( status ) printerror( status );
+
+  int status = 0;
+
   if (hdunum <= 1) 
     {
@@ -171,8 +273,9 @@
       moveToFollowingHeader();
     }
-  //  return this;
-}
-
-void FitsFile::moveToFollowingHeader()
+}
+
+
+
+void FitsInFile::moveToFollowingHeader()
 {
   int status = 0;
@@ -197,32 +300,244 @@
 }
 
- 
-void FitsFile::WriteF(char flnm[], bool OldFile)
-{
-  int status = 0; 
-  hdutype_= 0;
-  hdunum_ = 0;
-
- 
-  // create new FITS file
-  if (!OldFile)
-    {
-      fits_create_file(&fptr_,flnm,&status);
-      if( status ) printerror(status,"file already exists");
-    }
+
+int  FitsInFile::NbColsFromFits() const
+{
+  if(hdutype_ ==  BINARY_TBL) return nbcols_;
   else
-    {
-      fits_open_file(&fptr_,flnm,READWRITE,&status);
-      if( status ) printerror(status,"file does not exist");
-      fits_get_num_hdus(fptr_, &hdunum_, &status);
-      int hdutype;
-      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
-      if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
-
-    }
-  //  WriteToFits(*this);
-  WriteToFits();
-}
-void FitsFile::GetSingleColumn(double* map, int nentries) const
+    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
+    else
+      {
+	cout << " hdutype= " << hdutype_ << endl;
+	throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
+      }
+}
+
+int FitsInFile::NentriesFromFits(int nocol) const
+{
+  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
+  else
+    if(hdutype_ == ASCII_TBL) return nrows_;
+    else
+      if(hdutype_ == IMAGE_HDU) return nbData_;
+      else
+	{
+	  cout << "hdutype= " << hdutype_ << endl;
+	  throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
+	}
+}
+
+char FitsInFile::ColTypeFromFits(int nocol) const
+{
+  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
+    }
+  return types_[nocol];
+}
+string FitsInFile::ColNameFromFits(int nocol) const
+{
+  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
+    }
+  return noms_[nocol];
+}
+
+int FitsInFile::ColStringLengthFromFits(int nocol) const
+{
+  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
+    }
+  int index=-1;
+  int k;
+  for (k=0; k<=nocol; k++) 
+    {
+      if (types_[k] == 'S') index++;
+    }
+  return  taille_des_chaines_[index];
+}
+void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 
+{
+  int status= 0;
+  int    anull;
+  double dnull= 0.;
+  float fnull= 0.;
+  int inull= 0;
+  char* cnull= "";
+  int dcount = 0.;
+  int fcount = 0.;
+  int icount = 0;
+  int ccount =0;
+  int ncol;
+  long nels=1;
+  for (ncol=0; ncol<nbcols_; ncol++)
+    {
+      switch (types_[ncol])
+	{ 
+	case 'D' :
+	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
+	    break;
+	case 'E' :
+	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
+	  break;
+	case 'I' :
+	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
+			&anull,&status);
+	  break;
+	case 'S' :
+	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
+	  break;
+	}
+      if (status)
+	{
+	  ResetStatus(status);
+	  break;
+	}
+    }
+}
+
+void FitsInFile::GetBinTabLine(int NoLine, float* fdata) 
+{
+  int status= 0;
+  int    anull;
+  float fnull= 0.;
+  long nels=1;
+  int ncol;
+  for (ncol=0; ncol<nbcols_; ncol++)
+    {
+      fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
+      if (status)
+	{
+	  ResetStatus(status);
+	  break;
+	}
+    }
+}
+
+
+void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+            fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TDOUBLE) 
+	{
+	  if (DTYPE == TFLOAT)  cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
+	  else
+	    throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
+	}
+      long nels=nentries;
+      int    anull;
+      // no checking for undefined pixels
+      double dnull= 0.;
+      //     fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
+      //  if (status != 0) 
+      //	{
+      //	  dnull = -1.6375e30;  // default value
+      //	  status = 0;
+      //	}
+      if (nentries != nrows_*repeat)
+	{
+	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
+	  throw PException(" FitsFile:::GetBinTabFCol ");
+	}
+      fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
+			    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+      
+    }
+
+void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TFLOAT) 
+	{
+	  if (DTYPE == TDOUBLE)  cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
+	  else
+	    throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
+	}
+      long nels=nentries;
+      int    anull;
+      // no checking for undefined pixels
+      float fnull= 0.;
+      //     fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
+      //    if (status != 0) 
+      //	{
+      //	  fnull = -1.6375e30;  // default value
+      //	  status = 0;
+      //	}
+      if (nentries != nrows_*repeat)
+	{
+	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
+	  throw PException(" FitsFile:::GetBinTabFCol ");
+	}
+      fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
+			    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+
+void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
+    {
+      cout <<" entree GetBinTabFCol " << endl;
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT ) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
+	}
+      long nels=nentries;
+      // no checking for undefined pixels
+      int    anull;
+      int inull= 0;
+      //     fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
+      //     if (status != 0) 
+      //	{
+      //	  inull = -999999;  // default value
+      //	  status = 0;
+      //	}
+      if (nentries != nrows_*repeat)
+	{
+	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
+	  throw PException(" FitsFile:::GetBinTabFCol ");
+	}
+      fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
+			    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+
+void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TSTRING ) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
+	}
+      long nels=nentries;
+      // no checking for undefined pixels
+      int    anull;
+      char* cnull= "";
+      if (nentries != nrows_*repeat/width)
+	{
+	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat/width << endl;
+	  throw PException(" FitsFile:::GetBinTabFCol ");
+	}
+      long frow=1;
+      long felem=1;
+      fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
+		    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+
+void FitsInFile::GetSingleColumn(double* map, int nentries) const
 { 
   int status = 0;
@@ -256,5 +571,5 @@
 }
 
-void FitsFile::GetSingleColumn(float* map, int nentries) const
+void FitsInFile::GetSingleColumn(float* map, int nentries) const
 {
   int status = 0;
@@ -286,5 +601,5 @@
 }
 
-void FitsFile::GetSingleColumn( int* map, int nentries) const
+void FitsInFile::GetSingleColumn( int* map, int nentries) const
 {
   int status = 0;
@@ -315,96 +630,93 @@
       }
 }
-void FitsFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn) 
-{
-  int status = 0;
-  long naxis = nbdim;
-  long* naxes = new long[nbdim];
-  if (hdunum_ == 0) 
-    {
-      fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
-      hdunum_ = 1;
-    }
-  int k;
-  for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
-  if (type == 'D')
-    fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
-  else
-    if  (type == 'E')
-      fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
-    else
-      if  (type == 'I')
-	fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
-      else
-	{
-	  cout << " type of data: " << type << endl;
-	  throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
-	}
-
-  hdunum_++;
-  delete [] naxes;
-  if( status ) printerror( status, "erreur creation HDU IMAGE"  );
-
-}
-void FitsFile::putImageToFits(int nbData, double* map) const
-{
-  int status = 0;
-  long npix= nbData;
-  fits_write_img(fptr_,TDOUBLE,1,npix,map,&status); 
-  if( status ) printerror( status, "erreur ecriture putImageToFits" );
-  writeSignatureOnFits();
-}
-
-void FitsFile::putImageToFits(int nbData, float* map) const
-{
-  int status = 0;
-  long npix= nbData;
-  fits_write_img(fptr_,TFLOAT,1,npix, map,&status); 
-  if( status ) printerror( status, "erreur ecriture putImageToFits" );
-  writeSignatureOnFits();
-
-}
-void FitsFile::putImageToFits( int nbData, int* map) const
-{
-  int status = 0;
-
-  long npix= nbData;
-  fits_write_img(fptr_,TINT,1,npix,map,&status); 
-  if( status ) printerror( status, "erreur ecriture putImageToFits" );
-  writeSignatureOnFits();
-}
-
-
-
-void FitsFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
-{
+
+void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
+				  vector<int>& repeat,
+				  vector<string>& noms, 
+				  vector<char>& types,   
+				  vector<int>&  taille_des_chaines)
+{
+  int status= 0;
   int hdunum=0;
-  cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
-  int status= 0;
-
-  // bits per pixels
-  fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
-  if( status )  printerror( status );
-
-  // number of dimensions in the FITS array
-  naxis= 0;
-  fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
+  int hdutype=0;
+  fits_get_hdu_num(fileptr,&hdunum);
+  fits_get_hdu_type(fileptr, &hdutype, &status);
+
+  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
+    }
+  if(hdutype == ASCII_TBL)
+    cout << " Reading a FITS ascii table in HDU : " << hdunum << endl;  
+  if(hdutype == BINARY_TBL)
+    cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
+
+  // get the number of columns
+  fits_get_num_cols(fileptr, &nbcols,&status);
   if( status ) printerror( status );
 
-  // read the NAXISn keywords to get image size
-  long* naxes = new long[naxis] ;
+  // get the number of rows
+  long naxis2= 0;
+  fits_get_num_rows(fileptr,&naxis2,&status);
+  if( status ) printerror( status );
+  nrows = (int)naxis2;
+
+  // get the datatype,  names and the repeat count
+  noms.clear();
+  noms.reserve(nbcols);
+  types.clear();
+  types.reserve(nbcols);
+  repeat.clear();
+  repeat.reserve(nbcols);
+  taille_des_chaines.clear();
+  char **ttype = new char*[nbcols];
+  int ii;
+  for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
   int nfound;
-  fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
-  if( status ) printerror( status );
-  if (nfound != naxis ) 
-    cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
-  int k;
-  for (k=0; k<naxis; k++) 
-    {
-      naxisn.push_back( (int)naxes[k] );
-    }
-  delete [] naxes;
-}
-
-void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
+  fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
+  if( status ) printerror( status,"erreur lecture des noms de colonne");
+  int rept=0;
+  for(ii = 0; ii <  nbcols; ii++)
+    {
+      int DTYPE;
+      long width;
+      long repete = 0;
+      fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
+      if( status ) printerror( status,"erreur lecture type de colonne");
+      rept = repete;
+      noms.push_back(string(ttype[ii]));
+      switch (DTYPE)
+	{
+	case TDOUBLE :
+	  types.push_back('D');
+	  break;
+	case TFLOAT :
+	  types.push_back('E');
+	  break;
+	case TLONG :
+	  types.push_back('I');
+	  break;
+	case TINT :
+	  types.push_back('I');
+	  break;
+	case TSHORT :
+	  types.push_back('I');
+	  break;
+	case TSTRING :
+	  types.push_back('S');
+	  taille_des_chaines.push_back(width);
+	  rept/=width;
+	  break;
+	default :
+	  cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
+	  throw IOExc("FitsFile:: unknown type of field");
+	}
+      repeat.push_back(rept);
+    }
+  for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
+  delete [] ttype;
+}
+
+void FitsInFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
 {
   int status = 0;
@@ -473,342 +785,98 @@
 } 
 
-
- 
-  void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-            fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TDOUBLE) 
-	{
-	  if (DTYPE == TFLOAT)  cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
-	  else
-	    throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
-	}
-      long nels=nentries;
-      int    anull;
-      // no checking for undefined pixels
-      double dnull= 0.;
-      //     fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
-      //  if (status != 0) 
-      //	{
-      //	  dnull = -1.6375e30;  // default value
-      //	  status = 0;
-      //	}
-      if (nentries != nrows_*repeat)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
-      fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
-			    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-      
-    }
-
-  void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TFLOAT) 
-	{
-	  if (DTYPE == TDOUBLE)  cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
-	  else
-	    throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
-	}
-      long nels=nentries;
-      int    anull;
-      // no checking for undefined pixels
-      float fnull= 0.;
-      //     fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
-      //    if (status != 0) 
-      //	{
-      //	  fnull = -1.6375e30;  // default value
-      //	  status = 0;
-      //	}
-      if (nentries != nrows_*repeat)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
-      fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
-			    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-  void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
-    {
-      cout <<" entree GetBinTabFCol " << endl;
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT ) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
-	}
-      long nels=nentries;
-      // no checking for undefined pixels
-      int    anull;
-      int inull= 0;
-      //     fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
-      //     if (status != 0) 
-      //	{
-      //	  inull = -999999;  // default value
-      //	  status = 0;
-      //	}
-      if (nentries != nrows_*repeat)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
-      fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
-			    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-  void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TSTRING ) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
-	}
-      long nels=nentries;
-      // no checking for undefined pixels
-      int    anull;
-      char* cnull= "";
-      if (nentries != nrows_*repeat/width)
-	{
-	  cout << " found " << nentries << " pixels, expected:  " << nrows_*repeat/width << endl;
-	  throw PException(" FitsFile:::GetBinTabFCol ");
-	}
-      long frow=1;
-      long felem=1;
-      fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
-		    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-
-
-
-void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 
-{
-  int status= 0;
-  int    anull;
-  double dnull= 0.;
-  float fnull= 0.;
-  int inull= 0;
-  char* cnull= "";
-  int dcount = 0.;
-  int fcount = 0.;
-  int icount = 0;
-  int ccount =0;
-  int ncol;
-  long nels=1;
-  for (ncol=0; ncol<nbcols_; ncol++)
-    {
-      switch (types_[ncol])
-	{ 
-	case 'D' :
-	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
-	    break;
-	case 'E' :
-	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
-	  break;
-	case 'I' :
-	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
-			&anull,&status);
-	  break;
-	case 'S' :
-	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
-	  break;
-	}
-      if (status)
-	{
-	  ResetStatus(status);
-	  break;
-	}
-      //	  if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" );
-    }
-}
-
-void FitsFile::GetBinTabLine(int NoLine, float* fdata) 
-{
-  int status= 0;
-  int    anull;
-  float fnull= 0.;
-  long nels=1;
-  int ncol;
-  for (ncol=0; ncol<nbcols_; ncol++)
-    {
-      fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
-      if (status)
-	{
-	  ResetStatus(status);
-	  break;
-	}
-       //      if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
-    }
-}
-
-      
-
-
-
-
-
-
-int  FitsFile::NbColsFromFits() const
-{
-  if(hdutype_ ==  BINARY_TBL) return nbcols_;
+FitsOutFile::FitsOutFile()
+{
+  InitNull();
+}
+
+FitsOutFile::FitsOutFile(char flnm[], bool OldFile)
+{
+
+  InitNull();
+  int status = 0; 
+
+  // create new FITS file
+  if (!OldFile)
+    {
+      fits_create_file(&fptr_,flnm,&status);
+      if( status ) printerror(status,"file already exists");
+    }
   else
-    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
+    {
+      fits_open_file(&fptr_,flnm,READWRITE,&status);
+      if( status ) printerror(status,"file does not exist");
+      fits_get_num_hdus(fptr_, &hdunum_, &status);
+      int hdutype;
+      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
+      if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
+
+    }
+
+}
+
+
+
+void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn) 
+{
+  int status = 0;
+  long naxis = nbdim;
+  long* naxes = new long[nbdim];
+  if (hdunum_ == 1)
+    {
+      if (imageOnPrimary_ == false) fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
+      else  hdunum_--;
+    }
+  int k;
+  for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
+  if (type == 'D')
+    fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
+  else
+    if  (type == 'E')
+      fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
     else
-      {
-	cout << " hdutype= " << hdutype_ << endl;
-	throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
-      }
-}
-
-char FitsFile::ColTypeFromFits(int nocol) const
-{
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
-    }
-  return types_[nocol];
-}
-int FitsFile::NentriesFromFits(int nocol) const
-{
-  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
-  else
-    if(hdutype_ == ASCII_TBL) return nrows_;
-    else
-      if(hdutype_ == IMAGE_HDU) return nbData_;
+      if  (type == 'I')
+	fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
       else
 	{
-	  cout << "hdutype= " << hdutype_ << endl;
-	  throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
-	}
-}
-
-string FitsFile::ColNameFromFits(int nocol) const
-{
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
-    }
-  return noms_[nocol];
-}
-int FitsFile::ColStringLengthFromFits(int nocol) const
-{
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
-    }
-  int index=-1;
-  int k;
-  for (k=0; k<=nocol; k++) 
-    {
-      if (types_[k] == 'S') index++;
-    }
-  return  taille_des_chaines_[index];
-}
-
-
-
-void FitsFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
-				  vector<int>& repeat,
-				  vector<string>& noms, 
-				  vector<char>& types,   
-				  vector<int>&  taille_des_chaines)
-{
-  int status= 0;
-  int hdunum=0;
-  int hdutype=0;
-  fits_get_hdu_num(fileptr,&hdunum);
-  fits_get_hdu_type(fileptr, &hdutype, &status);
-
-  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
-    }
-  if(hdutype == ASCII_TBL)
-    cout << " Reading a FITS ascii table in HDU : " << hdunum << endl;  
-  if(hdutype == BINARY_TBL)
-    cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
-
-  // get the number of columns
-  fits_get_num_cols(fileptr, &nbcols,&status);
-  if( status ) printerror( status );
-
-  // get the number of rows
-  long naxis2= 0;
-  fits_get_num_rows(fileptr,&naxis2,&status);
-  if( status ) printerror( status );
-  nrows = (int)naxis2;
-
-  // get the datatype,  names and the repeat count
-  noms.clear();
-  noms.reserve(nbcols);
-  types.clear();
-  types.reserve(nbcols);
-  repeat.clear();
-  repeat.reserve(nbcols);
-  taille_des_chaines.clear();
-  char **ttype = new char*[nbcols];
-  int ii;
-  for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
-  int nfound;
-  fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
-  if( status ) printerror( status,"erreur lecture des noms de colonne");
-  int rept=0;
-  for(ii = 0; ii <  nbcols; ii++)
-    {
-      int DTYPE;
-      long width;
-      long repete = 0;
-      fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
-      if( status ) printerror( status,"erreur lecture type de colonne");
-      rept = repete;
-      noms.push_back(string(ttype[ii]));
-      switch (DTYPE)
-	{
-	case TDOUBLE :
-	  types.push_back('D');
-	  break;
-	case TFLOAT :
-	  types.push_back('E');
-	  break;
-	case TLONG :
-	  types.push_back('I');
-	  break;
-	case TINT :
-	  types.push_back('I');
-	  break;
-	case TSHORT :
-	  types.push_back('I');
-	  break;
-	case TSTRING :
-	  types.push_back('S');
-	  taille_des_chaines.push_back(width);
-	  rept/=width;
-	  break;
-	default :
-	  cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
-	  throw IOExc("FitsFile:: unknown type of field");
-	}
-      repeat.push_back(rept);
-    } 
-}
-
-
-
-void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) 
+	  cout << " type of data: " << type << endl;
+	  throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
+	}
+
+  hdunum_++;
+  delete [] naxes;
+  if( status ) printerror( status, "erreur creation HDU IMAGE"  );
+
+}
+void FitsOutFile::putImageToFits(int nbData, double* map) const
+{
+  int status = 0;
+  long npix= nbData;
+  fits_write_img(fptr_,TDOUBLE,1,npix,map,&status); 
+  if( status ) printerror( status, "erreur ecriture putImageToFits" );
+  writeSignatureOnFits();
+}
+
+void FitsOutFile::putImageToFits(int nbData, float* map) const
+{
+  int status = 0;
+  long npix= nbData;
+  fits_write_img(fptr_,TFLOAT,1,npix, map,&status); 
+  if( status ) printerror( status, "erreur ecriture putImageToFits" );
+  writeSignatureOnFits();
+
+}
+void FitsOutFile::putImageToFits( int nbData, int* map) const
+{
+  int status = 0;
+
+  long npix= nbData;
+  fits_write_img(fptr_,TINT,1,npix,map,&status); 
+  if( status ) printerror( status, "erreur ecriture putImageToFits" );
+  writeSignatureOnFits();
+}
+
+
+
+void FitsOutFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) 
 { 
   int status = 0;
@@ -817,5 +885,5 @@
     {
       cout << " nombre de champs :" << tfields << "nombre de types: " << strlen(fieldType) << endl;
-	      throw ParmError("FitsFile:: fields and types don't match");
+      throw ParmError("FitsFile:: fields and types don't match");
 
     }
@@ -824,6 +892,4 @@
   char largeur[FLEN_VALUE];
   int noColString=0;
-
-
   int k;
   for (k=0; k<tfields;k++)
@@ -847,9 +913,9 @@
 	  if (fieldType[k] == 'A') 
 	    {
-	    char largaux[FLEN_VALUE];
-	    sprintf(largeur,"%d",taille_des_chaines[noColString]);
-	    sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
-	    noColString++;
-	    strcpy(format, largaux);    
+	      char largaux[FLEN_VALUE];
+	      sprintf(largeur,"%d",taille_des_chaines[noColString]);
+	      sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
+	      noColString++;
+	      strcpy(format, largaux);    
 	    }
 	  else strcpy(format,"1024");
@@ -930,5 +996,5 @@
 }
 
-void FitsFile::putColToFits(int nocol, int nentries, double* donnees) const
+void FitsOutFile::putColToFits(int nocol, int nentries, double* donnees) const
 {
   int status = 0;
@@ -952,5 +1018,5 @@
   if( status )  printerror( status,"erreur ecriture du fichier fits" );
 }
-void FitsFile::putColToFits(int nocol, int nentries, float* donnees) const
+void FitsOutFile::putColToFits(int nocol, int nentries, float* donnees) const
 {
   int status = 0;
@@ -978,5 +1044,5 @@
   if( status )  printerror( status,"erreur ecriture du fichier fits" );
 }
-void FitsFile::putColToFits(int nocol, int nentries, int* donnees) const
+void FitsOutFile::putColToFits(int nocol, int nentries, int* donnees) const
 {
   int status = 0;
@@ -1004,5 +1070,5 @@
   if( status )  printerror( status," ecriture du fichier fits" );
 }
-void FitsFile::putColToFits(int nocol, int nentries, char** donnees) const
+void FitsOutFile::putColToFits(int nocol, int nentries, char** donnees) const
 {
   int status = 0;
@@ -1032,9 +1098,5 @@
 
 
-
-
-
-
-void FitsFile::writeSignatureOnFits() const
+void FitsOutFile::writeSignatureOnFits() const
 {
   int status = 0;
@@ -1060,43 +1122,3 @@
 
 
-void FitsFile::printerror(int &status) 
-  //*****************************************************/
-  //* Print out cfitsio error messages and exit program */
-  //*****************************************************/
-{
-  if( status )
-    {
-      fits_report_error(stderr,status);
-      throw IOExc("FitsFile:: error FITSIO status");
-    }
-  return;
-}
-
-void FitsFile::printerror(int& status, char* texte) 
-  //*****************************************************/
-  //* Print out cfitsio error messages and exit program */
-  //*****************************************************/
-{
-  // print out cfitsio error messages and exit program 
-  // print error report  
-  fits_report_error(stderr, status);
-  cout << " erreur:: " << texte << endl;
-  throw IOExc("FitsFile:: error FITSIO status");
-}
-
-int FitsFile::statusF() const
-{
-  return fits_status_;
-}
-void FitsFile::ResetStatus(int& status) 
-{
-  fits_status_ = status;
-  status = 0;
-}
-
-string FitsFile::getErrStatus(int status) 
-{
-  char text[31];
-  fits_get_errstatus(status, text);
-  return string(text);
-}
+
Index: /trunk/SophyaExt/FitsIOServer/fitsfile.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1136)
@@ -12,12 +12,19 @@
 namespace SOPHYA {
 
+ class FitsFile;
+ class FitsInFile;
+ class FitsOutFile;
+
+
+
 //
-//! Virtual Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
+//! Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib)
 
 /*! 
-
+The class structure is analogous to Sophya-PPersist system :
 Each SOPHYA object XXX is associated with a object of class FITS_XXX 
- (inheriting from FitsFile), to which input/output operations with FITS 
- files are delegated. A typical example of use is the following : 
+ (inheriting from FitsFileHandler), to which input/output operations with FITS 
+ files are delegated (through a class Hierarchy : FitsFile (virtual), 
+ FitsInFile, FitsOutFile) . A typical example of use is the following : 
 
 \verbatim
@@ -39,4 +46,62 @@
 
 */
+
+class FitsIOHandler {
+
+
+  public:
+
+virtual ~FitsIOHandler() {}
+/*!
+this method is called from inherited objects : 
+
+opens a file 'flnm' 
+
+gets parameters in header (hdunum)
+
+calls the method 'ReadFromFits' from the inherited  object
+
+
+*/ 
+  void   Read(char flnm[],int hdunum= 2);
+/*!
+this method is called from inherited objects : 
+
+for writing a new object in a new fits-extension, at the end of 
+
+the existing file (flnm), if OldFile=true. 
+
+If OldFile=false, an exception occurs
+ 
+By convention, primary header does not contain fits-image data : i.e. 
+all data are fits-extensions. The first relevant header will have hdunum=2.
+For switching off this convention use the method : 
+
+firstImageOnPrimaryHeader() (see below)
+
+In that case do not forget to precise hdunum=1 when reading data on primary header.
+
+calls the method 'WriteToFits' from the inherited  object
+
+*/ 
+  void   Write(char flnm[], bool OldFile=false) ;
+
+  /*!
+Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. With default value for hdunum, one reads the next extension, with respect to the current position. 
+   */
+  void   Read(FitsInFile& ifts, int hdunum=0);
+  void   Write(FitsOutFile& ofts) ;
+
+
+  protected:  
+  virtual void    ReadFromFits(FitsInFile& is)=0;           
+  virtual void    WriteToFits(FitsOutFile& os) =0;           
+  friend class FitsInFile;
+  friend class FitsOutFile;
+
+  };
+
+
+
 class FitsFile
 {
@@ -44,72 +109,84 @@
 public:
 
-  FitsFile();
+  FitsFile() { InitNull();};
   virtual ~FitsFile();
+
+  static string getErrStatus(int status);
+
+
+
+
+inline  int statusF() const { return fits_status_;}
+ 
+
+protected:
+
+   void ResetStatus(int& status) ; 
+   static  void printerror(int&) ;
+   static  void printerror(int&,char* texte) ;
+   inline void InitNull() { cout << " init fitsfile " << endl; fptr_= NULL; hdutype_= 0; hdunum_ = 1; 
+   fits_status_ = 0;}
+
+  //! pointer to the FITS file, defined in fitsio.h 
+  fitsfile *fptr_; 
+  
+  //!  image or bintable ?
+  int hdutype_;
+
+//! index of header to be read/written
+  int hdunum_;  
+
+  //! last status returned by fitsio library. updated only by several methods
+  int fits_status_;
+
+    
+};
+
+
+ class FitsInFile : public  FitsFile {
+
+ public:
+   FitsInFile();
+   //   FitsInFile(char flnm[], int hdunum=0);
+   FitsInFile(char flnm[]);
+   ~FitsInFile() {  cout << " destructeur FitsInFile " << endl; };
+
+
+//////////////////////////////////////////////////////////
+//     methods with general purpose
+///////////////////////////////////////
+
+
+
   static int NbBlocks(char flnm[]);
   static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
 
-  protected: 
+
+
+  //  void ReadFInit(char flnm[],int hdunum=0);
+  void ReadFInit(int hdunum);
  
-/*!
-this method is called from inherited objects : 
-
-moves to header 'hdunum' on file 'flnm'
-
-gets parameters in header 
-
-calls the method 'ReadFromFits' from the inherited  object
-
-*/ 
-  void   ReadF(char flnm[],int hdunum= 0);
-  //  FitsFile* ReadFInit(char flnm[],int hdunum=0); 
-  void ReadFInit(char flnm[],int hdunum=0); 
- 
-/*!
-this method is called from inherited objects : 
-
-opens a file 'flnm' 
-
-gets parameters in header 
-
-calls the method 'ReadFromFits' from the inherited  object
-
-*/ 
-  void    WriteF(char flnm[], bool OldFile=false);
- //    virtual void    ReadFromFits(FitsFile& ff)=0;           
-
-
-
-  virtual void    ReadFromFits()=0;           
-  virtual void    WriteToFits()=0;           
-
-  static string getErrStatus(int status);
-
-
-  //////////////////////////////////////////////////////////
-  ///////   methods for managing extensions ////////////////
-  //////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////
-    //     methods with general purpose
-    ///////////////////////////////////////
-
   /*! return a reference on a DVList containing the keywords from FITS file
    */
-  inline const DVList& DVListFromFits() const { return dvl_;}
-
-  void moveToFollowingHeader();
-  int statusF() const; 
+inline const DVList& DVListFromFits() const { return dvl_;}
+
+void moveToFollowingHeader();
+
+
+       //////////////////////////////////////////////////////////
+       ///////   methods for managing extensions ////////////////
+       //////////////////////////////////////////////////////////
+
 
 
 /////////////////////////////////////////////////////////////
-  //       methods for managing FITS IMAGE extension
-  ///////////////////////////////////////////////////
-
-
-  //read
-  //----
+//       methods for managing FITS IMAGE extension
+///////////////////////////////////////////////////
+
 
 /*! return true if the current header  corresponds to a FITS image extension */
 inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
+
+
 
   /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations)
@@ -125,46 +202,24 @@
 
 
-//write
-//-----
-
-
-  /*! create an IMAGE header on FITS file.
-\param <type> type of data (see method ColTypeFromFits)
-\param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
-\param <naxisn>  array containind sizes of the different dimensions
-  */
-  void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
-
-  /*! write double data from array 'map'on an IMAGE extension 
-\param <nbData>  number of data to be written
-
-   */
-  void putImageToFits( int nbData, double* map) const;
-
-  /*! same as previous method with float data */
-  void putImageToFits(int nbData, float* map ) const;
-
-  /*! same as previous method with int data */
-  void putImageToFits(int nbData, int* map) const;
-
-
 
 //////////////////////////////////////////////////////////////////////////
-  //       methods for managing FITS BINARY TABLE or ASCII TABLE extension
-  ////////////////////////////////////////////////////////////////////////
-
-
-
-// read 
-//-----
+//       methods for managing FITS BINARY TABLE or ASCII TABLE extension
+////////////////////////////////////////////////////////////////////////
+
+
+
 
 /*! return true if the current header  corresponds to a FITS ASCII or BINTABLE extension */
 inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);}
- /*! return number of columns (return 1 if IMAGE) */
-  int     NbColsFromFits() const;
-  /*! number of data in the current IMAGE extension on FITS file, or number
- of data of column number 'nocol' of the current BINTABLE extension
-  */
-  int     NentriesFromFits(int nocol) const;
+
+
+static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
+				  vector<int>& repeat,
+				  vector<string>& noms, 
+				  vector<char>& types,   
+				  vector<int>&  taille_des_chaines);
+
+
+
   /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
 
@@ -200,9 +255,5 @@
   void GetBinTabLine(int NoLine, float* fdata) ;
 
-
-
-
-
-  /*!
+/*!
 fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
 
@@ -219,8 +270,123 @@
   // Write elements into the FITS data array
 
-
-
-  //write
-  //-----
+/////////////////////////////////////////////////////////////
+//       methods for managing any type of FITS extension
+////////////////////////////////////////////////////////
+
+ /*! return number of columns (return 1 if IMAGE) */
+  int     NbColsFromFits() const;
+  /*! number of data in the current IMAGE extension on FITS file, or number
+ of data of column number 'nocol' of the current BINTABLE extension
+  */
+  int     NentriesFromFits(int nocol) const;
+
+
+/*!
+fill the array 'map' with double data from the current extension on FITS file.
+If the extension is BINTABLE, the first column is provided. 
+
+\param <nentries>  number of data to be read
+  */
+  void    GetSingleColumn(double* map, int nentries) const;
+
+  /*! same as above with float data */
+  void    GetSingleColumn(float*  map, int nentries) const;
+
+  /*! same as above with int data */
+  void    GetSingleColumn(int* map, int nentries) const;
+
+  private :
+
+void InitNull();
+static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum); 
+static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
+
+
+ 
+
+  //! fits-Image parameter 
+  int bitpix_;
+
+  //! fits-Image parameter 
+  int naxis_;
+
+  //! fits-Image parameters : sizes of dimensions
+  vector<int> naxisn_;
+
+  //! fits-Image parameter: number of data 
+  int nbData_;
+
+  //! Bintable parameter
+  int nrows_;
+
+  //! Bintable parameter
+  vector<int> repeat_;
+
+  //! Bintable parameter
+  int nbcols_;
+
+  //! Bintable parameter: column names
+  vector<string> noms_; 
+
+  //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
+  vector<char> types_;   
+
+  //! Bintable parameters:   length of the char* variables                 
+  vector<int>  taille_des_chaines_;
+
+  //! DVList for transferring keywords
+  DVList dvl_;
+
+
+ };
+
+
+ class FitsOutFile : public  FitsFile {
+
+ public:
+   FitsOutFile();
+   FitsOutFile(char flnm[], bool OldFile=false);
+   ~FitsOutFile() {  cout << " destructeur FitsOutFile " << endl;};
+   inline void InitNull() {imageOnPrimary_=false;}
+
+       //////////////////////////////////////////////////////////
+       ///////   methods for managing extensions ////////////////
+       //////////////////////////////////////////////////////////
+
+
+
+/////////////////////////////////////////////////////////////
+//       methods for managing FITS IMAGE extension
+///////////////////////////////////////////////////
+
+
+   inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
+
+  /*! create an IMAGE header on FITS file.
+\param <type> type of data (see method ColTypeFromFits)
+\param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
+\param <naxisn>  array containind sizes of the different dimensions
+  */
+  void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ;
+
+  /*! write double data from array 'map'on an IMAGE extension 
+\param <nbData>  number of data to be written
+
+   */
+  void putImageToFits( int nbData, double* map) const;
+
+  /*! same as previous method with float data */
+  void putImageToFits(int nbData, float* map ) const;
+
+  /*! same as previous method with int data */
+  void putImageToFits(int nbData, int* map) const;
+
+
+
+//////////////////////////////////////////////////////////////////////////
+//       methods for managing FITS BINARY TABLE or ASCII TABLE extension
+////////////////////////////////////////////////////////////////////////
+
+
 
   /*! create an BINTABLE header on FITS file.
@@ -250,90 +416,13 @@
   void putColToFits(int nocol, int nentries, char** donnees) const;
 
-
-/////////////////////////////////////////////////////////////
-  //       methods for managing any type of FITS extension
-  ////////////////////////////////////////////////////////
-
-
-  /*!
-fill the array 'map' with double data from the current extension on FITS file.
-If the extension is BINTABLE, the first column is provided. 
-
-\param <nentries>  number of data to be read
-  */
-  void    GetSingleColumn(double* map, int nentries) const;
-
-  /*! same as above with float data */
-  void    GetSingleColumn(float*  map, int nentries) const;
-
-  /*! same as above with int data */
-  void    GetSingleColumn(int* map, int nentries) const;
-
-
-
-private:
-
-   void InitNull();
-   void ResetStatus(int& status) ; 
-   static  void printerror(int&) ;
-   static  void printerror(int&,char* texte) ;
-
-static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
-static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
-				  vector<int>& repeat,
-				  vector<string>& noms, 
-				  vector<char>& types,   
-				  vector<int>&  taille_des_chaines);
-static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum); 
+  private :
+
   void writeSignatureOnFits() const; 
 
-  //! pointer to the FITS file, defined in fitsio.h 
-  fitsfile *fptr_; 
-  
-  //!  image or bintable ?
-  int hdutype_;
-
-//! index of header to be read/written
-  int hdunum_;  
-
-
-  //! fits-Image parameter 
-  int bitpix_;
-
-  //! fits-Image parameter 
-  int naxis_;
-
-  //! fits-Image parameters : sizes of dimensions
-  vector<int> naxisn_;
-
-  //! fits-Image parameter: number of data 
-  int nbData_;
-
-  //! Bintable parameter
-  int nrows_;
-
-  //! Bintable parameter
-  vector<int> repeat_;
-
-  //! Bintable parameter
-  int nbcols_;
-
-  //! Bintable parameter: column names
-  vector<string> noms_; 
- 
-  //! Bintable parameters: types of columns (D: double, E: float, I: integers,  A: char*)
-  vector<char> types_;   
-    
-  //! Bintable parameters:   length of the char* variables                 
-  vector<int>  taille_des_chaines_;
-
-  //! DVList for transferring keywords
-  DVList dvl_;
-
-
-
-  //! last status returned by fitsio library. updated only by several methods
-  int fits_status_;
-};
+
+  bool imageOnPrimary_;
+
+ };
+
 
 
Index: /trunk/SophyaExt/FitsIOServer/fitsntuple.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1135)
+++ /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_;
-}
Index: /trunk/SophyaExt/FitsIOServer/fitsntuple.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsntuple.h	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsntuple.h	(revision 1136)
@@ -4,4 +4,5 @@
 #ifndef FITSNTuple_SEEN
 #define FITSNTuple_SEEN
+#include "machdefs.h"
 #include "ntuple.h"
 #include "anydataobj.h"
@@ -14,5 +15,5 @@
 // pout NTuple 
 ////////////////////////////////////////////////////////////////
-class  FITS_NTuple : public FitsFile  
+class  FITS_NTuple : public FitsIOHandler  
 {
 
@@ -24,5 +25,16 @@
  FITS_NTuple(NTuple* obj); 
 virtual ~FITS_NTuple();
- void Read(char inputfile[],int hdunum=2);
+
+virtual   AnyDataObj* DataObj() { return(dobj_); }
+virtual   void        SetDataObj(AnyDataObj & o) 
+  {   
+    NTuple* po = dynamic_cast<  NTuple* >(& o); 
+    if (po == NULL) return;
+    if (ownobj_ && dobj_) delete dobj_;  
+    dobj_ = po; 
+    ownobj_ = false; 
+  }    
+
+
 /*!
 fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile.
@@ -31,5 +43,5 @@
 */
  void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
-void Write(char outputfile[], bool OldFile=false);
+
 inline operator NTuple() { return(*dobj_); }
 inline NTuple * getObj() { return(dobj_); }
@@ -38,18 +50,10 @@
 
   // implementation de FitsFile
-//virtual void ReadFromFits(FitsFile& fn);
-virtual void ReadFromFits();
-virtual void WriteToFits();
-
-float*  getColFromObj(int colNr);
+virtual void ReadFromFits(FitsInFile& is);
+virtual void WriteToFits(FitsOutFile& os) ;
 
  private : 
 
-inline void InitNull()
-   {
-     fistLineToBeRead_= -1;
-     numberOfLinesToBeRead_= -1;
-     column_ = NULL;
-   }
+inline void InitNull() { fistLineToBeRead_= -1; numberOfLinesToBeRead_= -1;}
 
 
@@ -59,5 +63,4 @@
   int fistLineToBeRead_;
   int numberOfLinesToBeRead_;
-  float* column_;
 };
 //////////////////////////////////////////////////////////////////
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1136)
@@ -15,5 +15,5 @@
 {
   dobj_= new SphereHEALPix<T>;
-  ownobj= true;
+  ownobj_= true;
 }
   
@@ -22,8 +22,8 @@
 {
   dobj_= new SphereHEALPix<T>;
-  ownobj= true;
-
-  ReadF(inputfile,hdunum);
-  dobj_->SetTemp(true);
+  ownobj_= true;
+
+  Read(inputfile,hdunum);
+  //  dobj_->SetTemp(true);
 }
 
@@ -33,6 +33,6 @@
 {
   dobj_= new SphereHEALPix<T>(obj, true);
-  dobj_->SetTemp(true);
-  ownobj= true;
+  //  dobj_->SetTemp(true);
+  ownobj_= true;
 }
 
@@ -41,5 +41,5 @@
 {
   dobj_= obj;
-  ownobj= false;
+  ownobj_= false;
 }
 
@@ -47,5 +47,5 @@
 FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
 {
-  if (ownobj && dobj_) delete dobj_;
+  if (ownobj_ && dobj_) delete dobj_;
 }
 
@@ -61,24 +61,14 @@
   SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
   if (po == NULL) return;
-  if (ownobj && dobj_) delete dobj_;
+  if (ownobj_ && dobj_) delete dobj_;
   dobj_ = po; 
-  ownobj = false;
+  ownobj_ = false;
 } 
 
 
 
-template <class T>
-void FITS_SphereHEALPix<T>::Write(char outputfile[], bool OldFile)
-{
-  WriteF(outputfile, OldFile);
-}
-template <class T>
-void FITS_SphereHEALPix<T>::Read(char inputfile[],int hdunum)
-{
-  ReadF(inputfile,hdunum);
-}
-
-template <class T>
-void FITS_SphereHEALPix<T>::WriteToFits()
+
+template <class T>
+void FITS_SphereHEALPix<T>::WriteToFits(FitsOutFile& os) 
 {
   if(dobj_ == NULL) 
@@ -130,35 +120,28 @@
   Type[1]='\0'; 
   vector<int> dummy;
-  //  fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
-  makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
+  os.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
   delete [] Noms[0];
   delete [] Noms;
-  putColToFits(0,  nPix, dobj_->pixels_.Data()); 
+  os.putColToFits(0,  nPix, dobj_->pixels_.Data()); 
 } 
 
 template <class T> 
-void FITS_SphereHEALPix<T>::ReadFromFits()
+void FITS_SphereHEALPix<T>::ReadFromFits(FitsInFile& is)
 {
   if(dobj_ == NULL) 
     {
       dobj_= new SphereHEALPix<T>;
-      dobj_->SetTemp(true);
-      ownobj= true;      
+      ownobj_= true;      
     }
 
  
   int nbcols, nbentries;
-  //  nbcols = fn.NbColsFromFits();
-  nbcols = NbColsFromFits();
+  nbcols = is.NbColsFromFits();
   if (nbcols != 1) 
     {
       throw IOExc("le fichier fits n'est pas une sphere Healpix");
     }
-  //   const DVList* dvl = &fn.DVListFromFits();
-  //  DVList dvl=fn.DVListFromFits();
-  DVList dvl=DVListFromFits();
-  //  dvl.Print();
-  //   nbentries = fn.NentriesFromFits(0);
-   nbentries = NentriesFromFits(0);
+  DVList dvl=is.DVListFromFits();
+   nbentries = is.NentriesFromFits(0);
   int lastpix=dvl.GetI("LASTPIX");
   if (lastpix>0)
@@ -211,11 +194,9 @@
   // On lit les DataBlocks;
   dobj_->pixels_.ReSize(nPix);
-  //  fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
-  GetSingleColumn(dobj_->pixels_.Data(),nPix);
+  is.GetSingleColumn(dobj_->pixels_.Data(),nPix);
 
   // on effectue le decoupage en tranches 
   dobj_->SetThetaSlices();
-  //  dobj_->Info()=fn.DVListFromFits();
-  dobj_->Info()=DVListFromFits();
+  dobj_->Info()=is.DVListFromFits();
 
 
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1136)
@@ -17,5 +17,5 @@
 //////////////////////////////////////////////////////////////////////
 template <class T>
-class FITS_SphereHEALPix : public FitsFile  
+class FITS_SphereHEALPix : public FitsIOHandler  
 {
 public:
@@ -30,14 +30,12 @@
 
 inline operator SphereHEALPix<T>() { return(*dobj_); }
- void Read(char inputfile[],int hdunum=2);
-void Write(char outputfile[], bool Oldfile=false);
 
 protected:
 
 //virtual void ReadFromFits(FitsFile& fn);
-virtual void ReadFromFits();
-virtual void WriteToFits();
+virtual void ReadFromFits(FitsInFile& is);
+virtual void WriteToFits(FitsOutFile& os) ;
 SphereHEALPix<T>* dobj_;
-bool ownobj;
+bool ownobj_;
 };
 
Index: /trunk/SophyaExt/FitsIOServer/fitstarray.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1136)
@@ -12,6 +12,6 @@
 FITS_TArray<T>::FITS_TArray()
 {
-  dobj_=new TArray<T>;
-  ownobj=true;
+  dobj_= NULL;
+  ownobj_=false;
 }
 
@@ -19,7 +19,7 @@
 FITS_TArray<T>::FITS_TArray(char inputfile[],int hdunum)
 {
-  dobj_=new TArray<T>;
-  ownobj=true; 
-  ReadF(inputfile,hdunum);
+  dobj_=NULL;
+  ownobj_=false; 
+  Read(inputfile,hdunum);
 }
 
@@ -27,6 +27,6 @@
 FITS_TArray<T>::FITS_TArray(const TArray<T> & obj) 
 { 
-  dobj_ = new TArray<T>(obj);
-  ownobj=true; 
+    dobj_ = new TArray<T>(obj);
+  ownobj_=true; 
 }
 
@@ -35,5 +35,5 @@
 { 
   dobj_ = obj;
-  ownobj=false; 
+  ownobj_=false; 
 }
 
@@ -42,13 +42,6 @@
 FITS_TArray<T>::~FITS_TArray()
 {
-  if (ownobj && dobj_) delete dobj_;
+  if (ownobj_ && dobj_) delete dobj_;
 }
-
-template <class T>
-void FITS_TArray<T>::Write(char outputfile[], bool OldFile)
-{
-  WriteF(outputfile, OldFile);
-}
-
 
 
@@ -59,42 +52,52 @@
 }
 
+
 template <class T>
-void FITS_TArray<T>::ReadFromFits()
+void   FITS_TArray<T>::SetDataObj(AnyDataObj & o) 
+  {   
+    TArray<T>* po = dynamic_cast<  TArray<T>* >(& o); 
+    if (po == NULL) return;
+    if (ownobj_ && dobj_) delete dobj_;  
+    dobj_ = po; 
+    ownobj_ = false; 
+  }    
+
+
+
+template <class T>
+void FITS_TArray<T>::ReadFromFits(FitsInFile& is)
 {
-
-  //  if (!fn.IsFitsImage())
-  if (!IsFitsImage())
+  if (!is.IsFitsImage())
     {
       throw PException("ReadFromFits: the fits file seems not to be an image");
     }
-  //  int dimension = fn.nbDimOfImage();
-  int dimension = nbDimOfImage();
+  int dimension = is.nbDimOfImage();
   cout << " dimension de l'image a lire: " << dimension << endl;
    
   uint_4* siz = new uint_4[dimension];
-  //  for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k];
-  for (int k=0; k< dimension; k++) siz[k] = dimOfImageAxes()[k];
+  for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
   if(dobj_ == NULL)
-    dobj_ = new TArray<T>(dimension,siz);
+    {
+      dobj_ = new TArray<T>(dimension,siz);
+      ownobj_ = true;
+    }
   else
     dobj_->ReSize(dimension,siz);
   
   delete [] siz;
-  //  if (dobj_->Size() != fn.nbOfImageData() )
-  if (dobj_->Size() != nbOfImageData() )
+  if (dobj_->Size() != is.nbOfImageData() )
   {
     cout << " total size of TArray: " << dobj_->Size() << endl;
-    cout << " total size from fits file: " << nbOfImageData() << endl;
+    cout << " total size from fits file: " << is.nbOfImageData() << endl;
       throw PException("ReadFromFits: size conflict");
   }
   // On lit le tableau
-  //  fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
-  GetSingleColumn( dobj_->Data(),dobj_->Size());
+  is.GetSingleColumn( dobj_->Data(),dobj_->Size());
 
 }
 
 
-  template <class T>
-void FITS_TArray<T>::WriteToFits()  
+template <class T>
+void FITS_TArray<T>::WriteToFits(FitsOutFile& os)  
 {
   if(dobj_ == NULL) return;
@@ -130,6 +133,5 @@
     }
   cout << " nombre total d'elements a copier " << nbels << endl;
-  //  fn.makeHeaderImageOnFits(type, nbdim, naxisn);
-  makeHeaderImageOnFits(type, nbdim, naxisn);
+  os.makeHeaderImageOnFits(type, nbdim, naxisn);
   if (!dobj_->IsPacked()) 
     {
@@ -144,6 +146,5 @@
       
     }
-  //  fn.putImageToFits(nbels, dobj_->Data());
-  putImageToFits(nbels, dobj_->Data());
+  os.putImageToFits(nbels, dobj_->Data());
   
   delete [] naxisn;
Index: /trunk/SophyaExt/FitsIOServer/fitstarray.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.h	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.h	(revision 1136)
@@ -20,5 +20,5 @@
 
 template <class T>
-class FITS_TArray : public FitsFile {
+class FITS_TArray : public FitsIOHandler {
 
 public:
@@ -30,15 +30,14 @@
 virtual ~FITS_TArray();
 virtual AnyDataObj* DataObj();
+virtual   void      SetDataObj(AnyDataObj & o); 
 inline operator TArray<T>() { return(*dobj_); }
-void Write(char outputfile[], bool OldFile=false);
 
 protected :
 
-  //void ReadFromFits(FitsFile& fn);
-void ReadFromFits();
-void WriteToFits();
+void ReadFromFits(FitsInFile& is);
+void WriteToFits(FitsOutFile& os) ;
 
   TArray<T> * dobj_;
-  bool ownobj;
+  bool ownobj_;
 };
 //////////////////////////////////////////////////////////////////
Index: /trunk/SophyaExt/FitsIOServer/fitsxntuple.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1135)
+++ /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;
+     }
+}
Index: /trunk/SophyaExt/FitsIOServer/fitsxntuple.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsxntuple.h	(revision 1135)
+++ /trunk/SophyaExt/FitsIOServer/fitsxntuple.h	(revision 1136)
@@ -4,4 +4,5 @@
 #ifndef FITSXNTuple_SEEN
 #define FITSXNTuple_SEEN
+#include "machdefs.h"
 #include "xntuple.h"
 #include "anydataobj.h"
@@ -15,5 +16,5 @@
 ///////////////////////////////////////////////////////////
 
-class  FITS_XNTuple : public FitsFile  
+class  FITS_XNTuple : public FitsIOHandler  
 {
 
@@ -24,5 +25,15 @@
 FITS_XNTuple(XNTuple* obj);
 ~FITS_XNTuple();
- void Read(char inputfile[],int hdunum=2);
+
+virtual   AnyDataObj* DataObj() { return(dobj_); }
+virtual   void        SetDataObj(AnyDataObj & o) 
+  {   
+    XNTuple* po = dynamic_cast<  XNTuple* >(& o); 
+    if (po == NULL) return;
+    if (ownobj_ && dobj_) delete dobj_;  
+    dobj_ = po; 
+    ownobj_ = false; 
+  }    
+
 
 /*!
@@ -32,5 +43,4 @@
 */
 void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
-void Write(char outputfile[], bool OldFile=false);
 inline operator XNTuple() { return(*dobj_); }
 inline XNTuple * getObj() { return(dobj_); }
@@ -39,16 +49,9 @@
 
   // implementation de FitsFile
-//  virtual void  ReadFromFits(FitsFile& fn);
- virtual void  ReadFromFits();
-virtual void    WriteToFits();
-void*   getColFromObj(int colNr);
-double* getColDFromObj(int colNr);
-float*  getColFFromObj(int colNr);
-int*    getColIFromObj(int colNr);
-char**  getColSFromObj(int colNr);
+ virtual void  ReadFromFits(FitsInFile& is);
+virtual void    WriteToFits(FitsOutFile& os) ;
 
  private :
 
- void Clean();
 
 inline void InitNull()
@@ -56,8 +59,4 @@
      fistLineToBeRead_= -1;
      numberOfLinesToBeRead_= -1;
-     dcolumn_ = NULL;
-     fcolumn_ = NULL;
-     icolumn_ = NULL;
-     ccolumn_ = NULL;
    }
 
@@ -67,8 +66,4 @@
   int fistLineToBeRead_;
   int numberOfLinesToBeRead_;
-  double* dcolumn_;
-  float*  fcolumn_;
-  int*    icolumn_;
-  char**  ccolumn_;
 };
 //////////////////////////////////////////////////////////////////
