Index: /trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1047)
@@ -33,4 +33,5 @@
   nrows_ = 0;
   nbcols_ = 0;
+  fits_status_ = 0;
   naxisn_.clear();
   repeat_.clear();
@@ -125,5 +126,12 @@
 {
   ReadFInit(flnm, hdunum);
-  /*
+  //  ReadFromFits(*this);
+    ReadFromFits();
+}
+
+
+//FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum) 
+void FitsFile::ReadFInit(char flnm[],int hdunum) 
+{
   InitNull();
   int status = 0;
@@ -163,55 +171,7 @@
       moveToFollowingHeader();
     }
-  */
-  ReadFromFits(*this);
-}
-
-
-FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum) 
-{
-  InitNull();
-  int status = 0;
-  //  hdutype_= 0;
-  
-  fits_open_file(&fptr_,flnm,READONLY,&status);
-  if( status ) printerror( status );
-  //
-  if (hdunum <= 1) 
-    {
-      hdunum_ = 1; 
-      // presence of image ?
-      int naxis= 0;
-      fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
-      if( status ) printerror( status );
-      if (naxis > 0 )       // there is an image
-	{
-	  hdutype_ = IMAGE_HDU;
-	  GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
-	  nbData_ =  1;
-	  int k;
-	  for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
-	  KeywordsIntoDVList(fptr_, dvl_,hdunum_);
-	}
-      else
-	{
-	  throw PException(" first header : no image, probably error in hdunum");
-	}
-  //
-    }
-  else 
-    {
-      hdunum_ = hdunum-1; 
-      int hdutype;
-      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
-      if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
-      moveToFollowingHeader();
-    }
-  return this;
-}
-
-void FitsFile::ReadFFromFits() 
-{
-  ReadFromFits(*this);
-}
+  //  return this;
+}
+
 void FitsFile::moveToFollowingHeader()
 {
@@ -261,5 +221,6 @@
 
     }
-  WriteToFits(*this);
+  //  WriteToFits(*this);
+  WriteToFits();
 }
 void FitsFile::GetSingleColumn(double* map, int nentries) const
@@ -636,5 +597,5 @@
 
 
-void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const
+void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 
 {
   int status= 0;
@@ -656,24 +617,26 @@
 	case 'D' :
 	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
-	  if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne double" );
 	    break;
 	case 'E' :
 	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
-	  if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
 	  break;
 	case 'I' :
 	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
 			&anull,&status);
-	  if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne tint" );
 	  break;
 	case 'S' :
 	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
-	  if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" );
 	  break;
 	}
-    }
-}
-
-void FitsFile::GetBinTabLine(int NoLine, float* fdata) const
+      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;
@@ -685,5 +648,10 @@
     {
       fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
-      if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
+      if (status)
+	{
+	  ResetStatus(status);
+	  break;
+	}
+       //      if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
     }
 }
@@ -1066,31 +1034,4 @@
 
 
-void FitsFile::readheader()
-  //*************************************/
-  //* Print out all the header keywords */
-  //*************************************/
-{
-  // standard string lengths defined in fitsioc.h
-  char card[FLEN_CARD];
-
-  int status = 0;
-
-  // get the number of keywords
-  int nkeys, keypos;
-  if( fits_get_hdrpos(fptr_,&nkeys,&keypos,&status) )
-    printerror( status );
-
-  cout << " Header listing for HDU : " << hdunum_ << endl;
-  int jj;
-  for(jj = 1; jj <= nkeys; jj++)  
-    {
-      if( fits_read_record(fptr_,jj,card,&status) )
-	printerror( status );
-      
-      // print the keyword card
-      cout << card << endl; 
-    }
-  cout << "END" << endl;
-}
 
 
@@ -1143,2 +1084,19 @@
   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 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1047)
@@ -48,55 +48,75 @@
   static int NbBlocks(char flnm[]);
   static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
-/*! return true if the current header  corresponds to a FITS image extension */
-inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
-
-/*! 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);}
-
-/*!
-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 delegated object
-
-*/ 
-  void   ReadF(char flnm[],int hdunum= 0);
-  FitsFile* ReadFInit(char flnm[],int hdunum=0); 
-  void ReadFFromFits(); 
+
+  protected: 
  
 /*!
 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 delegated object
+calls the method 'ReadFromFits' from the inherited  object
 
 */ 
-  void    WriteF(char flnm[], bool OldFile=false); 
-
-
-  /*!
-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;
+  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; 
+
+
+/////////////////////////////////////////////////////////////
+  //       methods for managing FITS IMAGE extension
+  ///////////////////////////////////////////////////
+
+
+  //read
+  //----
+
+/*! 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)
    */
 inline int nbDimOfImage() const {return naxis_;}
-
+/*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
+ */
+ inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
 /*!
  total number of data in the current IMAGE extension
@@ -104,11 +124,47 @@
 inline int nbOfImageData() const { return nbData_; }
 
-/*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc.
- */
- inline const vector<int>& dimOfImageAxes() const { return naxisn_;}
-
+
+//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 
+//-----
+
+/*! 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;
   /*! return a character denoting data type of column number 'nocol' in a BINTABLE :
 
@@ -123,22 +179,27 @@
   */
   char    ColTypeFromFits(int nocol) 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;
-
   /*! name of the column number 'nocol' of the current BINTABLE extension
    */
   string  ColNameFromFits(int nocol) const;
 
-  
   /*! number of characters of each data  for the column number 'nocol' (if char* typed) of the current BINTABLE extension
    */
   int     ColStringLengthFromFits(int nocol) const;
 
-  /*! return a reference on a DVList containing the keywords from FITS file
-   */
-  inline const DVList& DVListFromFits() const { return dvl_;}
+
+
+  /*!
+get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
+  */
+  void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
+** cdata) ;
+
+  /*!
+get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
+  */
+  void GetBinTabLine(int NoLine, float* fdata) ;
+
+
+
 
 
@@ -158,50 +219,8 @@
   // Write elements into the FITS data array
 
-  /*!
-get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
-  */
-  void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
-** cdata) const;
-  /*!
-get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
-  */
-  void GetBinTabLine(int NoLine, float* fdata) const;
-
-
-
-
-  /*! 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;
-
-  /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
-\param <nentries>  number of data to be written
-
-   */
-  void putColToFits(int nocol, int nentries, double* donnees) const;
-
-  /*! same as previous method with float data */
-  void putColToFits(int nocol, int nentries, float* donnees) const;
-
-  /*! same as previous method with int data */
-  void putColToFits(int nocol, int nentries, int* donnees) const;
-
-  /*! same as previous method with char* data */
-  void putColToFits(int nocol, int nentries, char** donnees) const;
-
-  /*! 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
+  //-----
 
   /*! create an BINTABLE header on FITS file.
@@ -216,14 +235,47 @@
   void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname,  vector<int> taille_des_chaines) ;
 
-  void moveToFollowingHeader();
-  void readheader();
-static  void printerror(int&) ;
-static  void printerror(int&,char* texte) ;
-  protected:  
-    virtual void    ReadFromFits(FitsFile& ff)=0;           
-    virtual void    WriteToFits(FitsFile& ff)=0;           
+  /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
+\param <nentries>  number of data to be written
+
+   */
+  void putColToFits(int nocol, int nentries, double* donnees) const;
+
+  /*! same as previous method with float data */
+  void putColToFits(int nocol, int nentries, float* donnees) const;
+
+  /*! same as previous method with int data */
+  void putColToFits(int nocol, int nentries, int* donnees) const;
+
+  /*! same as previous method with char* data */
+  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);
@@ -279,4 +331,8 @@
   DVList dvl_;
 
+
+
+  //! last status returned by fitsio library. updated only by several methods
+  int fits_status_;
 };
 
Index: /trunk/SophyaExt/FitsIOServer/fitsntuple.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsntuple.cc	(revision 1047)
@@ -15,6 +15,6 @@
 {
   dobj_ = new NTuple;
-  column_ = NULL;
-  ownobj=true;
+  InitNull();
+  ownobj_ = true;
 }
 
@@ -22,6 +22,6 @@
 {
   dobj_ = new NTuple;
-  column_ = NULL;
-  ownobj=true; 
+  InitNull();
+  ownobj_ = true; 
 
   ReadF(inputfile,hdunum);
@@ -32,6 +32,12 @@
 { 
   dobj_ = new NTuple(obj);
-  column_ = NULL;
-  ownobj=true; 
+  InitNull();
+  ownobj_ = true; 
+}
+FITS_NTuple::FITS_NTuple(NTuple* obj) 
+{ 
+  dobj_ = obj;
+  InitNull();
+  ownobj_ = false; 
 }
 
@@ -39,8 +45,21 @@
 FITS_NTuple::~FITS_NTuple()
 {
-  if (ownobj && dobj_ != NULL) delete dobj_;
+  if (ownobj_ && dobj_ != NULL) delete dobj_;
   if (column_ != NULL) delete [] column_;
 }
 
+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);
+}
+
+
+
 void FITS_NTuple::Write(char outputfile[], bool OldFile)
 {
@@ -48,15 +67,18 @@
 }
 
-void FITS_NTuple::ReadFromFits(FitsFile& fn)
-{
-  if (!fn.IsFitsTable())
+void FITS_NTuple::ReadFromFits()
+{
+  //  if (!fn.IsFitsTable())
+    if (!IsFitsTable())
     {
       throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
     }
   int nbcols, nbentries;
-  nbcols = fn.NbColsFromFits();
+  //  nbcols = fn.NbColsFromFits();
+  nbcols = 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, fn.NentriesFromFits(k) );
+  for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) );
   
   char ** ColName = new char*[nbcols];
@@ -65,10 +87,12 @@
     {
       ColName[k] = new char[LONNOM1]; 
-      strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM);
+      //      strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM);
+      strncpy(ColName[k], ColNameFromFits(k).c_str(),LONNOM);
       ColName[k][LONNOM] =  '\0';
     }
   for (k=0; k<nbcols;k++)
     {
-      char ss= fn.ColTypeFromFits(k);
+      //      char ss= fn.ColTypeFromFits(k);
+      char ss= ColTypeFromFits(k);
       string type;
       if (ss != 'E') 
@@ -87,5 +111,5 @@
     { 
       dobj_= new NTuple(nbcols,ColName);
-      ownobj= true;      
+      ownobj_ = true;      
     }
   else 
@@ -99,21 +123,47 @@
     }
   delete [] ColName;
-    if (column_ != NULL) delete [] column_;
-    column_ = new float[nbentries];
+  //   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);
+  //  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;
-  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();
-}
-void FITS_NTuple::WriteToFits(FitsFile& fn)
+
+    //%%%%%%%
+
+
+    //  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()
 {
   if(dobj_ == NULL) 
@@ -147,5 +197,6 @@
   type[ncols]='\0';
   vector<int> dummy;
-  fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
+  //  fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
+  makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy);
    for (k=0; k< ncols; k++)
     {
Index: /trunk/SophyaExt/FitsIOServer/fitsntuple.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsntuple.h	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsntuple.h	(revision 1047)
@@ -22,5 +22,13 @@
 FITS_NTuple(char inputfile[],int hdunum=2);
 FITS_NTuple(const NTuple & obj);
+ FITS_NTuple(NTuple* obj); 
 virtual ~FITS_NTuple();
+ void Read(char inputfile[],int hdunum=2);
+/*!
+fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile.
+\param <firstLine>  first line  to be read (the first line of the file is numbered 0)
+\param <numberOfLines>  number of lines to be read
+*/
+ void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
 void Write(char outputfile[], bool OldFile=false);
 inline operator NTuple() { return(*dobj_); }
@@ -29,12 +37,25 @@
 
   // implementation de FitsFile
-virtual void ReadFromFits(FitsFile& fn);
-virtual void WriteToFits(FitsFile& fn);
+//virtual void ReadFromFits(FitsFile& fn);
+virtual void ReadFromFits();
+virtual void WriteToFits();
 
 float*  getColFromObj(int colNr);
 
+ private : 
+
+inline void InitNull()
+   {
+     fistLineToBeRead_= -1;
+     numberOfLinesToBeRead_= -1;
+     column_ = NULL;
+   }
+
+
   // attributs de classe
   NTuple* dobj_;
-  bool ownobj;
+  bool ownobj_;
+  int fistLineToBeRead_;
+  int numberOfLinesToBeRead_;
   float* column_;
 };
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1047)
@@ -80,5 +80,5 @@
 
 template <class T>
-void FITS_SphereHEALPix<T>::WriteToFits(FitsFile& fn)
+void FITS_SphereHEALPix<T>::WriteToFits()
 {
   if(dobj_ == NULL) 
@@ -130,5 +130,6 @@
   Type[1]='\0'; 
   vector<int> dummy;
-  fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
+  //  fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
+  makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
   delete [] Noms[0];
   delete [] Noms;
@@ -137,5 +138,5 @@
 
 template <class T> 
-void FITS_SphereHEALPix<T>::ReadFromFits(FitsFile& fn)
+void FITS_SphereHEALPix<T>::ReadFromFits()
 {
   if(dobj_ == NULL) 
@@ -148,5 +149,6 @@
  
   int nbcols, nbentries;
-  nbcols = fn.NbColsFromFits();
+  //  nbcols = fn.NbColsFromFits();
+  nbcols = NbColsFromFits();
   if (nbcols != 1) 
     {
@@ -154,7 +156,9 @@
     }
   //   const DVList* dvl = &fn.DVListFromFits();
-  DVList dvl=fn.DVListFromFits();
+  //  DVList dvl=fn.DVListFromFits();
+  DVList dvl=DVListFromFits();
   //  dvl.Print();
-   nbentries = fn.NentriesFromFits(0);
+  //   nbentries = fn.NentriesFromFits(0);
+   nbentries = NentriesFromFits(0);
   int lastpix=dvl.GetI("LASTPIX");
   if (lastpix>0)
@@ -207,9 +211,11 @@
   // On lit les DataBlocks;
   dobj_->pixels_.ReSize(nPix);
-  fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
+  //  fn.GetSingleColumn(dobj_->pixels_.Data(),nPix);
+  GetSingleColumn(dobj_->pixels_.Data(),nPix);
 
   // on effectue le decoupage en tranches 
   dobj_->SetThetaSlices();
-  dobj_->Info()=fn.DVListFromFits();
+  //  dobj_->Info()=fn.DVListFromFits();
+  dobj_->Info()=DVListFromFits();
 
 
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h	(revision 1047)
@@ -35,6 +35,7 @@
 protected:
 
-virtual void ReadFromFits(FitsFile& fn);
-virtual void WriteToFits(FitsFile& fn);
+//virtual void ReadFromFits(FitsFile& fn);
+virtual void ReadFromFits();
+virtual void WriteToFits();
 SphereHEALPix<T>* dobj_;
 bool ownobj;
Index: /trunk/SophyaExt/FitsIOServer/fitstarray.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1047)
@@ -60,16 +60,19 @@
 
 template <class T>
-void FITS_TArray<T>::ReadFromFits(FitsFile& fn)
+void FITS_TArray<T>::ReadFromFits()
 {
 
-  if (!fn.IsFitsImage())
+  //  if (!fn.IsFitsImage())
+  if (!IsFitsImage())
     {
       throw PException("ReadFromFits: the fits file seems not to be an image");
     }
-  int dimension = fn.nbDimOfImage();
+  //  int dimension = fn.nbDimOfImage();
+  int dimension = 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] = fn.dimOfImageAxes()[k];
+  for (int k=0; k< dimension; k++) siz[k] = dimOfImageAxes()[k];
   if(dobj_ == NULL)
     dobj_ = new TArray<T>(dimension,siz);
@@ -78,12 +81,14 @@
   
   delete [] siz;
-  if (dobj_->Size() != fn.nbOfImageData() )
+  //  if (dobj_->Size() != fn.nbOfImageData() )
+  if (dobj_->Size() != nbOfImageData() )
   {
     cout << " total size of TArray: " << dobj_->Size() << endl;
-    cout << " total size from fits file: " << fn.nbOfImageData() << endl;
+    cout << " total size from fits file: " << nbOfImageData() << endl;
       throw PException("ReadFromFits: size conflict");
   }
   // On lit le tableau
-  fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
+  //  fn.GetSingleColumn( dobj_->Data(),dobj_->Size());
+  GetSingleColumn( dobj_->Data(),dobj_->Size());
 
 }
@@ -91,5 +96,5 @@
 
   template <class T>
-void FITS_TArray<T>::WriteToFits(FitsFile& fn)  
+void FITS_TArray<T>::WriteToFits()  
 {
   if(dobj_ == NULL) return;
@@ -125,5 +130,6 @@
     }
   cout << " nombre total d'elements a copier " << nbels << endl;
-  fn.makeHeaderImageOnFits(type, nbdim, naxisn);
+  //  fn.makeHeaderImageOnFits(type, nbdim, naxisn);
+  makeHeaderImageOnFits(type, nbdim, naxisn);
   if (!dobj_->IsPacked()) 
     {
@@ -138,5 +144,6 @@
       
     }
-  fn.putImageToFits(nbels, dobj_->Data());
+  //  fn.putImageToFits(nbels, dobj_->Data());
+  putImageToFits(nbels, dobj_->Data());
   
   delete [] naxisn;
Index: /trunk/SophyaExt/FitsIOServer/fitstarray.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.h	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.h	(revision 1047)
@@ -35,6 +35,7 @@
 protected :
 
-void ReadFromFits(FitsFile& fn);
-void WriteToFits(FitsFile& fn);
+  //void ReadFromFits(FitsFile& fn);
+void ReadFromFits();
+void WriteToFits();
 
   TArray<T> * dobj_;
Index: /trunk/SophyaExt/FitsIOServer/fitsxntuple.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsxntuple.cc	(revision 1047)
@@ -13,9 +13,6 @@
 {
   dobj_ = new XNTuple;
-  dcolumn_ = NULL;
-  fcolumn_ = NULL;
-  icolumn_ = NULL;
-  ccolumn_ = NULL;
-  ownobj=true;
+  InitNull();
+  ownobj_ = true;
 }
 
@@ -23,9 +20,6 @@
 {
   dobj_ = new XNTuple;
-  dcolumn_ = NULL;
-  fcolumn_ = NULL;
-  icolumn_ = NULL;
-  ccolumn_ = NULL;
-  ownobj=true; 
+  InitNull();
+  ownobj_ = true; 
 
   ReadF(inputfile,hdunum);
@@ -36,11 +30,19 @@
 { 
   dobj_ = new XNTuple(obj);
-  dcolumn_ = NULL;
-  fcolumn_ = NULL;
-  icolumn_ = NULL;
-  ccolumn_ = NULL;
-  ownobj=true; 
+  InitNull();
+  ownobj_ = true; 
+}
+FITS_XNTuple::FITS_XNTuple(XNTuple* obj) 
+{ 
+  dobj_ = obj;
+  InitNull();
+  ownobj_ = false; 
 }
 FITS_XNTuple::~FITS_XNTuple()
+{
+  Clean();
+}
+
+void FITS_XNTuple::Clean()
 {
   if (dcolumn_ != NULL) delete [] dcolumn_;
@@ -58,6 +60,21 @@
 	  cout << "FITS_XNTuple, destructeur: bizarre, ccolumn non vide, sans objet?" << endl;;  	}
     }
-  if (ownobj && dobj_ != NULL) delete dobj_;
-}
+  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)
+{
+  fistLineToBeRead_ = firstLine;
+  numberOfLinesToBeRead_ = numberOfLines;
+  ReadF(inputfile,hdunum);
+  //  return dobj_;
+}
+
+
 void FITS_XNTuple::Write(char outputfile[], bool OldFile)
 {       
@@ -65,15 +82,18 @@
 } 
  
-void FITS_XNTuple::ReadFromFits(FitsFile& fn)
+void FITS_XNTuple::ReadFromFits()
 {   
-  if (!fn.IsFitsTable())
+  //  if (!fn.IsFitsTable())
+  if (!IsFitsTable())
     {
       throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table");
     }
   int nbcols, nbentries;
-  nbcols = fn.NbColsFromFits();
+  //  nbcols = fn.NbColsFromFits();
+  nbcols = 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, fn.NentriesFromFits(k) );
+  for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) );
 
   //
@@ -91,5 +111,6 @@
   for (k=0; k<nbcols;k++)
     {
-      char ss= fn.ColTypeFromFits(k);
+      //      char ss= fn.ColTypeFromFits(k);
+      char ss= ColTypeFromFits(k);
       if (ss == 'D') DfitsCol.push_back(k);
       else if (ss == 'E') FfitsCol.push_back(k);
@@ -106,5 +127,6 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
+      //      strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][ LONNOM] =  '\0';
     }
@@ -112,5 +134,6 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
+      //      strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][ LONNOM] =  '\0';
     }
@@ -118,5 +141,6 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
+      //      strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][ LONNOM] =  '\0';
     }
@@ -124,19 +148,28 @@
     {
       ColName[compt] = new char[LONNOM+1]; 
-      strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
+      //      strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
+      strncpy(ColName[compt], ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
       ColName[compt++][LONNOM] =  '\0';
     }
-
 
   if(dobj_ == NULL) 
     { 
       dobj_= new XNTuple(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(),ColName);
-      ownobj= true;      
+      ownobj_ = true;      
     }
   else 
     {
-      dobj_->clean();
+      if (ownobj_)
+	{
       (*dobj_)= XNTuple(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(),ColName);
-    }
+	}
+      else
+	{
+	if (DfitsCol.size() != dobj_->NDVar() || FfitsCol.size() != dobj_->NFVar() ||  IfitsCol.size() != dobj_->NIVar() || SfitsCol.size() != dobj_->NSVar())
+
+	  throw  SzMismatchError("FITS_XNTuple : structure incorrecte du ntuple");
+	}
+    }
+
   for (k=0; k<nbcols;k++) 
     {
@@ -145,90 +178,52 @@
   delete [] ColName;
 
-  // j'initialise le NTuple a zero, pour le dimensionner
-  // (SetXVal suppose que le ntuple est deja dimensionne)
-  r_8* dligne;
-  r_4* fligne;
-  int_4* iligne;
-  char** cligne;
-  if (DfitsCol.size()>0) 
-    {
-      if (dcolumn_ != NULL) delete [] dcolumn_;
-      dcolumn_ = new double[nbentries];
-      dligne = new r_8[DfitsCol.size()];
-      for (k=0; k<DfitsCol.size(); k++) dligne[k]=0.;
-    }
+    r_8* dligne;
+    r_4* fligne;
+    int_4* iligne;
+    char** cligne;
+
+  if (DfitsCol.size()>0) dligne = new r_8[DfitsCol.size()];
   else dligne=NULL;
-  if (FfitsCol.size()>0) 
-    {
-      if (fcolumn_ != NULL) delete [] fcolumn_;
-      fcolumn_ = new float[nbentries];
-      fligne = new r_4[FfitsCol.size()];
-      for (k=0; k<FfitsCol.size(); k++) fligne[k]=0.;
-    }
+  if (FfitsCol.size()>0) fligne = new r_4[FfitsCol.size()];
   else fligne=NULL;
-  if (IfitsCol.size()>0) 
-    {
-      if (icolumn_ != NULL) delete [] icolumn_;
-      icolumn_ = new int[nbentries];
-      iligne = new int_4[IfitsCol.size()];
-      for (k=0; k<IfitsCol.size(); k++) iligne[k]=0;
-    } 
+  if (IfitsCol.size()>0) iligne = new int_4[IfitsCol.size()];
   else iligne=NULL;
   if (SfitsCol.size()>0) 
     {
-      if (ccolumn_ != NULL)
-	{
-	  for (k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k];
-	  delete [] ccolumn_;
-	  ccolumn_ = NULL;
-	}
-      ccolumn_ = new char*[nbentries];
+      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<nbentries;k++) ccolumn_[k]= new char[taille_des_chaines+1];
-      cligne = new char*[SfitsCol.size()];
-      for (k=0; k<SfitsCol.size(); k++) cligne[k]=" ";
+      //      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++) cligne[k]=new char[taille_des_chaines+1];
     }
   else cligne=NULL;
-
-  for (k=0; k<nbentries;k++) dobj_->Fill(dligne, fligne, iligne, cligne);
-  delete [] dligne;
-  delete [] fligne;
-  delete [] iligne;
-  for (k=0; k< SfitsCol.size(); k++) delete []  cligne[k];
-  delete [] cligne; 
-   
-  compt=0;
-  for (k=0; k<DfitsCol.size(); k++)
-    {
-      fn.GetBinTabFCol(dcolumn_, nbentries, DfitsCol[k]);
-      for (int nent=0; nent<nbentries; nent++) dobj_->SetDVal(nent,compt, dcolumn_[nent]);
-      compt++;
-    }
-  
-  for (k=0; k<FfitsCol.size(); k++)
-    {
-      fn.GetBinTabFCol(fcolumn_,nbentries, FfitsCol[k]);
-      for (int nent=0; nent<nbentries; nent++) dobj_->SetFVal(nent,compt, fcolumn_[nent]);
-      compt++;
-    }
-              
-  for (k=0; k<IfitsCol.size(); k++)
-    {
-      fn.GetBinTabFCol(icolumn_,nbentries, IfitsCol[k]);
-      for (int nent=0; nent<nbentries; nent++) dobj_->SetIVal(nent,compt, icolumn_[nent]);
-      compt++;
-    }
-  
-  for (k=0; k<SfitsCol.size(); k++)
-    {
-      fn.GetBinTabFCol(ccolumn_,nbentries, SfitsCol[k]);
-            for (int nent=0; nent<nbentries; nent++) dobj_->SetSVal(nent,compt, ccolumn_[nent]);
-      compt++;
-    }
-  dobj_->Info()=fn.DVListFromFits();
-
-}
-void FITS_XNTuple::WriteToFits(FitsFile& fn)
+  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, dligne, fligne, iligne, cligne );
+      GetBinTabLine(numLigne, dligne, fligne, iligne, cligne );
+      dobj_->Fill(dligne, fligne, iligne, cligne);    
+    }
+    delete [] dligne;
+    delete [] fligne;
+    delete [] iligne;
+    for (k=0; k< SfitsCol.size(); k++) delete []  cligne[k];
+    delete [] cligne; 
+    //  dobj_->Info()=fn.DVListFromFits();
+  dobj_->Info()=DVListFromFits();
+
+}
+void FITS_XNTuple::WriteToFits()
 {
   if(dobj_ == NULL) 
@@ -276,5 +271,6 @@
   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); 
+  //    fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 
+    makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 
    for (k=0; k< ncols; k++)
     {
Index: /trunk/SophyaExt/FitsIOServer/fitsxntuple.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsxntuple.h	(revision 1046)
+++ /trunk/SophyaExt/FitsIOServer/fitsxntuple.h	(revision 1047)
@@ -22,5 +22,14 @@
 FITS_XNTuple(char inputfile[],int hdunum=2);
 FITS_XNTuple(const XNTuple & obj);
+FITS_XNTuple(XNTuple* obj);
 ~FITS_XNTuple();
+ void Read(char inputfile[],int hdunum=2);
+
+/*!
+fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile.
+\param <firstLine>  first line  to be read (the first line of the file is numbered 0)
+\param <numberOfLines>  number of lines to be read
+*/
+void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2);
 void Write(char outputfile[], bool OldFile=false);
 inline operator XNTuple() { return(*dobj_); }
@@ -29,6 +38,7 @@
 
   // implementation de FitsFile
-  virtual void  ReadFromFits(FitsFile& fn);
-virtual void    WriteToFits(FitsFile& fn);
+//  virtual void  ReadFromFits(FitsFile& fn);
+ virtual void  ReadFromFits();
+virtual void    WriteToFits();
 void*   getColFromObj(int colNr);
 double* getColDFromObj(int colNr);
@@ -37,7 +47,23 @@
 char**  getColSFromObj(int colNr);
 
+ private :
+
+ void Clean();
+
+inline void InitNull()
+   {
+     fistLineToBeRead_= -1;
+     numberOfLinesToBeRead_= -1;
+     dcolumn_ = NULL;
+     fcolumn_ = NULL;
+     icolumn_ = NULL;
+     ccolumn_ = NULL;
+   }
+
   // attributs de classe
   XNTuple* dobj_;
-  bool    ownobj;
+  bool    ownobj_;
+  int fistLineToBeRead_;
+  int numberOfLinesToBeRead_;
   double* dcolumn_;
   float*  fcolumn_;
