Index: /trunk/SophyaExt/FitsIOServer/fabtcolread.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fabtcolread.cc	(revision 2448)
+++ /trunk/SophyaExt/FitsIOServer/fabtcolread.cc	(revision 2449)
@@ -5,13 +5,135 @@
 #include "pexceptions.h"
 #include "fabtcolread.h"
+
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+
+//! Class for opening a FITS file for reading
+
+/*!
+  \class SOPHYA::FitsOpenFile
+  \ingroup FitsIOServer
+  Class for opening a FITS file for reading
+*/
+
+/*!
+  Constructor.
+  \param fname : FITS file name to be opened for reading
+*/
+FitsOpenFile::FitsOpenFile(string fname)
+{
+  Init(fname.c_str());
+}
+
+/*!
+  Constructor.
+  \param cfname : FITS file name to be opened for reading
+*/
+FitsOpenFile::FitsOpenFile(const char *cfname)
+{
+  Init(cfname);
+}
+
+/*!
+  Constructor by default.
+*/
+FitsOpenFile::FitsOpenFile()
+{
+  FitsFN = "";
+  NHdu = -1;
+  FitsPtr = NULL;
+}
+
+/*!
+  Constructor by copy.
+*/
+FitsOpenFile::FitsOpenFile(FitsOpenFile& fof)
+{
+  Init(fof.GetFileName().c_str());
+}
+
+/*!
+  Destructor.
+*/
+FitsOpenFile::~FitsOpenFile()
+{
+  Delete();
+  FitsFN = "";
+  NHdu = 0;
+}
+
+/*!
+  Delete routine called by the destructor.
+*/
+void FitsOpenFile::Delete(void)
+{
+  if(FitsPtr != NULL) {
+    int sta = 0;
+    if(fits_close_file(FitsPtr,&sta)) printerror(sta);
+    FitsPtr = NULL;
+  }
+}
+
+/*! Init routine called by the constructor */
+void FitsOpenFile::Init(const char* fname)
+{
+   // Parametres Generaux
+   FitsFN = fname;
+   NHdu = 0;
+   FitsPtr = NULL;
+
+   // Ouverture du fichier
+   if(FitsFN.size() <= 0 )
+      throw ParmError("FitsOpenFile::Init: Fits file name error\n");
+
+   int sta = 0;
+   if(fits_open_file(&FitsPtr,FitsFN.c_str(),READONLY,&sta)) {
+     printerror(sta);
+     FitsPtr = NULL;
+     throw NullPtrError("FitsOpenFile::Init: Error opening Fits file\n");
+   }
+
+   // Get number of hdu
+   if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
+     printerror(sta);
+     NHdu = 0;
+     Delete();
+     throw NotAvailableOperation("FitsOpenFile::Init: Error getting NHdu\n");
+   }
+   if(NHdu<=0) {
+     Delete();
+     throw SzMismatchError("FitsOpenFile::Init: Bad NHdu\n");
+   }
+
+ }
+
+ void FitsOpenFile::printerror(int sta) const
+ {
+  int stat = sta;
+  fits_report_error(stdout,stat);
+  fflush(stdout);
+  return;
+ }
+
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////
 //! Class for reading a column in a FITS ASCII or BINARY table
 
 /*!
-  \class SOPHYA::FitsABTColRead
+  \class SOPHYA::FitsABTColRd
   \ingroup FitsIOServer
   Class for reading a column in a FITS ASCII or BINARY table
   \verbatim
   -- Exemple:
-  FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3);
+  // Open the fits file with FitsOpenFile
+  FitsOpenFile fof = new FitsOpenFile("myfits.fits");
+  // Select the column to be read
+  FitsABTColRd fbt(fof,"BoloMuv_28",0,1000,1,3);
   fbt.SetDebug(3);
   fbt.Print(3);
@@ -28,4 +150,6 @@
   n = fbt.Read(10,-1,data);
     cout<<"Number of values read: "<<n<<endl;
+  // Close the fits file
+  delete fof;
   \endverbatim
 */
@@ -34,5 +158,5 @@
 /*!
   Constructor.
-  \param fname : FITS file name to be read
+  \param fof : Pointer to the Class for opening the FITS file
   \param collabel : label of the column to be read
   \param ihdu : number of the HDU where the column is.
@@ -48,8 +172,8 @@
   \warning ihdu = [1,nhdu]
 */
-FitsABTColRead::FitsABTColRead(string fname,string collabel
-                            ,int ihdu,long blen,long bsens,int lp)
-{
-Init(fname.c_str(),collabel.c_str(),-1,ihdu,blen,bsens,lp);
+FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,string collabel
+                          ,int ihdu,long blen,long bsens,int lp)
+{
+  Init(fof,collabel.c_str(),-1,ihdu,blen,bsens,lp);
 }
 
@@ -60,38 +184,39 @@
   \warning col = [0,ncol[
 */
-FitsABTColRead::FitsABTColRead(string fname,int colnum
-                            ,int ihdu,long blen,long bsens,int lp)
-{
-Init(fname.c_str(),"",colnum,ihdu,blen,bsens,lp);
-}
-
-/*! Constructor. see below */
-FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel
-                            ,int ihdu,long blen,long bsens,int lp)
-{
-Init(cfname,collabel,-1,ihdu,blen,bsens,lp);
-}
-
-/*! Constructor. see below */
-FitsABTColRead::FitsABTColRead(const char * cfname,int colnum
-                            ,int ihdu,long blen,long bsens,int lp)
-{
-Init(cfname,"",colnum,ihdu,blen,bsens,lp);
+FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,int colnum
+                          ,int ihdu,long blen,long bsens,int lp)
+{
+  Init(fof,"",colnum,ihdu,blen,bsens,lp);
 }
 
 /*! Constructor by copy */
-FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt)
-{
-Init(fbt.GetFileName().c_str(),fbt.GetColLabel().c_str()
-    ,fbt.GetColNum(),fbt.GetHDU()
-    ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
+FitsABTColRd::FitsABTColRd(FitsABTColRd& fbt)
+{
+  Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str()
+      ,fbt.GetColNum(),fbt.GetHDU()
+      ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
+}
+
+/*! Constructor by default */
+FitsABTColRd::FitsABTColRd()
+{
+ FitsFN = "";
+ ColLabel = ""; ColTUnit = ""; ColTForm = "";
+ ColNum = -1; ColTypeCode = 0;
+ IHdu = 0; NHdu = 0; HduType = 0;
+ NBcol = 0; NBline = 0;
+ SetNulVal(); SetDebug(0);
+ NFitsRead = 0;
+ FitsOF = NULL; FitsPtr = NULL;
+ LineDeb = LineFin = -1;
+ Buffer = NULL;
 }
 
 /*! Init routine called by the constructor */
-void FitsABTColRead::Init(const char* fname,const char* collabel,int colnum
+void FitsABTColRd::Init(FitsOpenFile* fof,const char* collabel,int colnum
                         ,int ihdu,long blen,long bsens,int lp)
 {
- // Parametres Generaux
- FitsFN = fname;
+ // Initialisation des Parametres Generaux
+ FitsFN = "";
  ColLabel = collabel;
  ColTUnit = "";
@@ -107,4 +232,5 @@
  SetDebug(lp);
  NFitsRead = 0;
+ FitsOF = NULL;
  FitsPtr = NULL;
  LineDeb = LineFin = -1;
@@ -112,31 +238,28 @@
  ChangeBuffer(blen,bsens);
 
- //////////////////////////
- // Ouverture du fichier //
- //////////////////////////
-
- int sta=0;
- if(FitsFN.size() <= 0 ) {
-   IHdu = -1; Delete();
-   throw ParmError("FitsABTColRead::Init: Fits file name error\n");
- }
- const char * cfitsfn = FitsFN.c_str();
-
- // Open fits
- if(fits_open_file(&FitsPtr,cfitsfn,READONLY,&sta)) {
-   printerror(sta); Delete();
-   throw NullPtrError("FitsABTColRead::Init: Error opening Fits file\n");
- }
-
- // Get number of hdu
- if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
-   printerror(sta); Delete();
-   throw NotAvailableOperation("FitsABTColRead::Init: Error getting NHdu\n");
- }
- if(DbgLevel>1) cout<<"FitsABTColRead::Init  NHdu="<<NHdu<<endl;
+ // Caracteristiques du FitsOpenFile
+ FitsOF = fof;
+ if(FitsOF==NULL) {
+   Delete();
+   throw NullPtrError("FitsABTColRd::Init: FitsOpenFile pointer is NULL\n");
+ }
+ FitsPtr = FitsOF->GetFitsPtr();
+ if(FitsPtr==NULL) {
+   Delete();
+   throw NullPtrError("FitsABTColRd::Init: FitsPtr pointer is NULL\n");
+ }
+ NHdu = FitsOF->GetNHdu();
+ if(DbgLevel>1) cout<<"FitsABTColRd::Init  NHdu="<<NHdu<<endl;
  if(NHdu<=0) {
    Delete();
-   throw SzMismatchError("FitsABTColRead::Init: Bad NHdu\n");
- }
+   throw SzMismatchError("FitsABTColRd::Init: Bad NHdu\n");
+ }
+ FitsFN = FitsOF->GetFileName();
+ if(FitsFN.size() <= 0 ) {
+   Delete();
+   throw ParmError("FitsABTColRd::Init: Fits file name error\n");
+ }
+
+ int sta = 0;
 
  // Get HDU for bin/ascii table
@@ -153,13 +276,13 @@
    cout<<"NO BINARY or ASCII hdu found"<<endl;
    IHdu = 0; Delete();
-   throw TypeMismatchExc("FitsABTColRead::Init: NO BINARY or ASCII hdu found\n");
+   throw TypeMismatchExc("FitsABTColRd::Init: NO BINARY or ASCII hdu found\n");
  }
  if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) {
    printerror(sta); Delete();
-   throw RangeCheckError("FitsABTColRead::Init: Error moving to requested HDU\n");
+   throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n");
  }
  if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) {
    Delete();
-   throw TypeMismatchExc("FitsABTColRead::Init: HDU not ASCII/BINARY table\n");
+   throw TypeMismatchExc("FitsABTColRd::Init: HDU not ASCII/BINARY table\n");
  }
 
@@ -167,10 +290,10 @@
  if(fits_get_num_cols(FitsPtr,&NBcol,&sta)) {
    printerror(sta); Delete();
-   throw NotAvailableOperation("FitsABTColRead::Init: Error getting number of columns\n");
+   throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n");
  }
  if(DbgLevel>1) cout<<"...Init  NBcol="<<NBcol<<endl;
  if(NBcol<1) {
    Delete();
-   throw RangeCheckError("FitsABTColRead::Init: Bad number of colums\n");
+   throw RangeCheckError("FitsABTColRd::Init: Bad number of colums\n");
  }
 
@@ -178,10 +301,10 @@
  if(fits_get_num_rows(FitsPtr,&NBline,&sta)) {
    printerror(sta); Delete();
-   throw NotAvailableOperation("FitsABTColRead::Init: Error getting number of rows\n");
+   throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n");
  }
  if(DbgLevel>1) cout<<"...Init  NBline="<<NBline<<endl;
  if(NBline<1) {
    Delete();
-   throw RangeCheckError("FitsABTColRead::Init: Bad number of rows\n");
+   throw RangeCheckError("FitsABTColRd::Init: Bad number of rows\n");
  }
 
@@ -192,5 +315,5 @@
    if(fits_get_colnum(FitsPtr,CASESEN,labelcol,&ColNum,&sta)) {
      printerror(sta); Delete();
-     throw NotAvailableOperation("FitsABTColRead::Init: Error getting column name\n");
+     throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n");
    }
    ColNum--;  // Convention [0,ncol[
@@ -199,5 +322,5 @@
  if(ColNum<0 || ColNum>=NBcol) {
    Delete();
-   throw RangeCheckError("FitsABTColRead::Init: Bad column number\n");
+   throw RangeCheckError("FitsABTColRd::Init: Bad column number\n");
  }
 
@@ -205,5 +328,5 @@
  if(fits_get_coltype(FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) {
    printerror(sta); Delete();
-   throw ParmError("FitsABTColRead::Init: Error getting column type\n");
+   throw ParmError("FitsABTColRd::Init: Error getting column type\n");
  }
  if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl;
@@ -211,5 +334,5 @@
                          || ColTypeCode<0 ) {
    Delete();
-   throw ParmError("FitsABTColRead::Init: Selected column is not Numerical\n");
+   throw ParmError("FitsABTColRd::Init: Selected column is not Numerical\n");
  }
 
@@ -227,5 +350,5 @@
  if(rc) {
    printerror(sta); Delete();
-   throw RangeCheckError("FitsABTColRead::Init: Error getting the column caracteristics\n");
+   throw RangeCheckError("FitsABTColRd::Init: Error getting the column caracteristics\n");
  }
  ColLabel = labelcol;
@@ -234,5 +357,5 @@
 
  if(DbgLevel)
-   cout<<"FitsABTColRead::Init Num="<<ColNum<<" Label="<<ColLabel
+   cout<<"FitsABTColRd::Init Num="<<ColNum<<" Label="<<ColLabel
        <<" TypeCode="<<ColTypeCode<<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl;
  if(DbgLevel>1)
@@ -243,22 +366,20 @@
 
 /*! Destructor. */
-FitsABTColRead::~FitsABTColRead()
+FitsABTColRd::~FitsABTColRd()
 {
  Delete();
 }
 
-//////////////////////////////////////////////////////////////
-double FitsABTColRead::ReadKey(char *keyname)
-{
- if(keyname==NULL) return 0.;
- int sta=0; double val=0.;
- if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta))
-   printerror(sta);
- return val;
+/*! Delete called by the destructor */
+void FitsABTColRd::Delete(void)
+{
+ if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
+ LineDeb = LineFin = -1;
+ //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
 }
 
 //////////////////////////////////////////////////////////////
 /*! Change the buffer caracteristiques (see creator) */
-void FitsABTColRead::ChangeBuffer(long blen,long bsens)
+void FitsABTColRd::ChangeBuffer(long blen,long bsens)
 {
  long oldnbuffer = NBuffer;
@@ -285,12 +406,12 @@
 }
 
-/*! Delete called by the destructor */
-void FitsABTColRead::Delete()
-{
- if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
- LineDeb = LineFin = -1;
- int sta = 0;
- if(fits_close_file(FitsPtr,&sta)) printerror(sta);
- FitsPtr = NULL;
+//////////////////////////////////////////////////////////////
+double FitsABTColRd::ReadKey(char *keyname)
+{
+ if(keyname==NULL) return 0.;
+ int sta=0; double val=0.;
+ if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta))
+   printerror(sta);
+ return val;
 }
 
@@ -307,5 +428,5 @@
   \endverbatim
 */
-double FitsABTColRead::Read(long n,bool usebuffer)
+double FitsABTColRd::Read(long n,bool usebuffer)
 // Attention: n=nline [0,NBline[, cfistio veut [1,NBline]
 // Attention: colnum  [0,NBcol[ , cfistio veut [1,NBcol]
@@ -313,5 +434,5 @@
  int sta=0;
  if(n<0 || n>=NBline)
-   throw RangeCheckError("FitsABTColRead::Read try to read outside line range\n");
+   throw RangeCheckError("FitsABTColRd::Read try to read outside line range\n");
 
  // Pas de bufferisation, on lit betement
@@ -322,5 +443,5 @@
    if(sta) {
      printerror(sta);
-     throw NotAvailableOperation("FitsABTColRead::Read: Error Reading Fits file\n");
+     throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n");
    }
    // On ne remplit Buffer[0] que si on a choisit
@@ -336,5 +457,5 @@
  // Gestion avec bufferisation
  if(!Buffer)
-   throw RangeCheckError("FitsABTColRead::Read: Buffer not allocated\n");
+   throw RangeCheckError("FitsABTColRd::Read: Buffer not allocated\n");
  if(n<LineDeb || n>LineFin) {
    NFitsRead++;
@@ -358,5 +479,5 @@
      printerror(sta);
      LineDeb = LineFin = -1;
-     throw NotAvailableOperation("FitsABTColRead::Read: Error Reading Fits file\n");
+     throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n");
    }
  }
@@ -398,10 +519,10 @@
   \endverbatim
 */
-long FitsABTColRead::Read(long n1,long n2,TVector<double>& data)
+long FitsABTColRd::Read(long n1,long n2,TVector<double>& data)
 {
  if(n1<0 || n1>=NBline)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
  if(data.Size()<=0 && n2<n1)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
  if(n2<0) n2 = n1 + data.Size()-1;
  if(n2>=NBline) n2 = NBline-1;
@@ -415,5 +536,5 @@
  if(sta) {
    printerror(sta);
-   throw NotAvailableOperation("FitsABTColRead::Read_TVector<double>: Error Reading Fits file\n");
+   throw NotAvailableOperation("FitsABTColRd::Read_TVector<double>: Error Reading Fits file\n");
  }
 
@@ -422,10 +543,10 @@
 
 /*! idem before but for TVector of float */
-long FitsABTColRead::Read(long n1,long n2,TVector<float>& data)
+long FitsABTColRd::Read(long n1,long n2,TVector<float>& data)
 {
  if(n1<0 || n1>=NBline)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
  if(data.Size()<=0 && n2<n1)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
  if(n2<0) n2 = n1 + data.Size()-1;
  if(n2>=NBline) n2 = NBline-1;
@@ -439,5 +560,5 @@
  if(sta) {
    printerror(sta);
-   throw NotAvailableOperation("FitsABTColRead::Read_TVector<float>: Error Reading Fits file\n");
+   throw NotAvailableOperation("FitsABTColRd::Read_TVector<float>: Error Reading Fits file\n");
  }
 
@@ -446,10 +567,10 @@
 
 /*! idem before but for TVector of unsigned short */
-long FitsABTColRead::Read(long n1,long n2,TVector<uint_2>& data)
+long FitsABTColRd::Read(long n1,long n2,TVector<uint_2>& data)
 {
  if(n1<0 || n1>=NBline)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
  if(data.Size()<=0 && n2<n1)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
  if(n2<0) n2 = n1 + data.Size()-1;
  if(n2>=NBline) n2 = NBline-1;
@@ -462,5 +583,5 @@
  if(sta) {
    printerror(sta);
-   throw NotAvailableOperation("FitsABTColRead::Read_TVector<uint_2>: Error Reading Fits file\n");
+   throw NotAvailableOperation("FitsABTColRd::Read_TVector<uint_2>: Error Reading Fits file\n");
  }
 
@@ -469,10 +590,10 @@
 
 /*! idem before but for TVector of int_4 */
-long FitsABTColRead::Read(long n1,long n2,TVector<int_4>& data)
+long FitsABTColRd::Read(long n1,long n2,TVector<int_4>& data)
 {
  if(n1<0 || n1>=NBline)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
  if(data.Size()<=0 && n2<n1)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
  if(n2<0) n2 = n1 + data.Size()-1;
  if(n2>=NBline) n2 = NBline-1;
@@ -487,5 +608,5 @@
  if(sta) {
    printerror(sta);
-   throw NotAvailableOperation("FitsABTColRead::Read_TVector<int_4>: Error Reading Fits file\n");
+   throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_4>: Error Reading Fits file\n");
  }
 
@@ -494,11 +615,11 @@
 
 /*! idem before but for TVector of int_8 */
-long FitsABTColRead::Read(long n1,long n2,TVector<int_8>& data)
+long FitsABTColRd::Read(long n1,long n2,TVector<int_8>& data)
 {
 #ifdef TLONGLONG
  if(n1<0 || n1>=NBline)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
  if(data.Size()<=0 && n2<n1)
-   throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
+   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
  if(n2<0) n2 = n1 + data.Size()-1;
  if(n2>=NBline) n2 = NBline-1;
@@ -511,10 +632,10 @@
  if(sta) {
    printerror(sta);
-   throw NotAvailableOperation("FitsABTColRead::Read_TVector<int_8>: Error Reading Fits file\n");
+   throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_8>: Error Reading Fits file\n");
  }
 
  return nread;
 #else
-  throw PException("FitsABTColRead::Read(..,TVector<int_8>&) Not in that cfitsio version");
+  throw PException("FitsABTColRd::Read(..,TVector<int_8>&) Not in that cfitsio version");
 #endif
 }
@@ -531,5 +652,5 @@
   \return <0 means not found
 */
-long FitsABTColRead::FirstRow(double val1,double val2,long rowstart)
+long FitsABTColRd::FirstRow(double val1,double val2,long rowstart)
 {
  long row = -1;
@@ -560,5 +681,5 @@
   \endverbatim
 */
-long FitsABTColRead::LastRow(double val1,double val2,long rowstart)
+long FitsABTColRd::LastRow(double val1,double val2,long rowstart)
 {
  long row = -1;
@@ -579,5 +700,5 @@
 
 /////////////////////////////////////////////////
-void FitsABTColRead::printerror(int sta) const
+void FitsABTColRd::printerror(int sta) const
 {
  int stat = sta;
@@ -588,7 +709,7 @@
 
 /*! Print on stream os */
-void FitsABTColRead::Print(ostream& os,int lp) const
-{
- os<<"FitsABTColRead:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
+void FitsABTColRd::Print(ostream& os,int lp) const
+{
+ os<<"FitsABTColRd:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
    <<" ncols="<<NBcol<<" nrows="<<NBline;
  if(lp>0) os<<" NRead="<<NFitsRead;
@@ -599,2 +720,105 @@
    <<endl;
 }
+
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+
+//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
+
+/*!
+  \class SOPHYA::FitsABTColRead
+  \ingroup FitsIOServer
+  Class for reading a column in a FITS ASCII or BINARY table with fits file opening
+  \verbatim
+  -- Exemple:
+  FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3);
+  fbt.SetDebug(3);
+  fbt.Print(3);
+  // Read element by element
+  for(long i=0;i<fbt.GetNbLine();i++) {
+    double x = fbt.Read(i);
+    if(i%lpmod==0) cout<<i<<": "<<x<<endl;
+  }
+  // Read into a vector
+  TVector<double> data;
+  long n = fbt.Read(32,50,data);
+    cout<<"Number of values read: "<<n<<endl;
+  data.ReSize(100);
+  n = fbt.Read(10,-1,data);
+    cout<<"Number of values read: "<<n<<endl;
+  \endverbatim
+*/
+
+
+//////////////////////////////////////////////////////////////
+/*!
+  Constructor.
+  \param fname : FITS file name to be read
+  \param collabel : label of the column to be read
+  \param ihdu : number of the HDU where the column is.
+  \param blen : read buffer length
+  \param bsens : buffer reading direction
+  \param lp : debug level
+  \verbatim
+  - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken
+  - bsens>0    read forward
+    bsens<0    read backward
+    bsens==0   read centered
+  \endverbatim
+  \warning ihdu = [1,nhdu]
+*/
+FitsABTColRead::FitsABTColRead(string fname,string collabel
+                              ,int ihdu,long blen,long bsens,int lp)
+: FitsABTColRd(new FitsOpenFile(fname),collabel,ihdu,blen,bsens,lp)
+{
+}
+
+/*!
+  Constructor.
+  Same as before but the column is identified by its column number
+  \param colnum : number of the column to be read
+  \warning col = [0,ncol[
+*/
+FitsABTColRead::FitsABTColRead(string fname,int colnum
+                              ,int ihdu,long blen,long bsens,int lp)
+: FitsABTColRd(new FitsOpenFile(fname),colnum,ihdu,blen,bsens,lp)
+{
+}
+
+/*! Constructor. see below */
+FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel
+                              ,int ihdu,long blen,long bsens,int lp)
+: FitsABTColRd(new FitsOpenFile(cfname),collabel,ihdu,blen,bsens,lp)
+{
+}
+
+/*! Constructor. see below */
+FitsABTColRead::FitsABTColRead(const char * cfname,int colnum
+                              ,int ihdu,long blen,long bsens,int lp)
+: FitsABTColRd(new FitsOpenFile(cfname),colnum,ihdu,blen,bsens,lp)
+{
+}
+/*! Constructor by default */
+FitsABTColRead::FitsABTColRead()
+{
+}
+
+/*! Constructor by copy */
+FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt)
+{
+ // --- ATTENTION ---
+ // FitsABTColRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
+ FitsOpenFile* fof = new FitsOpenFile(*fbt.GetFitsOpenFile());
+ Init(fof,fbt.GetColLabel().c_str()
+     ,fbt.GetColNum(),fbt.GetHDU()
+     ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
+}
+
+/*! Destructor. */
+FitsABTColRead::~FitsABTColRead()
+{
+ Delete();
+ if(FitsOF!=NULL) delete FitsOF;
+}
Index: /trunk/SophyaExt/FitsIOServer/fabtcolread.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fabtcolread.h	(revision 2448)
+++ /trunk/SophyaExt/FitsIOServer/fabtcolread.h	(revision 2449)
@@ -14,17 +14,39 @@
 namespace SOPHYA {
 
+///////////////////////////////////////////////////////////////////
+//! Class for opening a FITS file for reading
+class FitsOpenFile : public AnyDataObj {
+public:
+  FitsOpenFile(string fname);
+  FitsOpenFile(const char *cfname);
+  FitsOpenFile();
+  FitsOpenFile(FitsOpenFile& fof);
+  virtual ~FitsOpenFile();
+
+  inline string GetFileName() {return FitsFN;}
+  inline int GetNHdu() {return NHdu;}
+  inline fitsfile* GetFitsPtr() {return FitsPtr;}
+
+protected:
+  void Init(const char *cfname);
+  void Delete(void);
+  void printerror(int sta) const;
+
+  string FitsFN;
+  int NHdu;
+  fitsfile *FitsPtr;
+};
+
+///////////////////////////////////////////////////////////////////
 //! Class for reading a column in a FITS ASCII or BINARY table
-class FitsABTColRead : public AnyDataObj {
+class FitsABTColRd : public AnyDataObj {
 public:
-  FitsABTColRead(string fname,string collabel,int ihdu=0
-                ,long blen=100,long bsens=1,int lp=0);
-  FitsABTColRead(string fname,int colnum,int ihdu=0
-                ,long blen=100,long bsens=1,int lp=0);
-  FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
-                ,long blen=100,long bsens=1,int lp=0);
-  FitsABTColRead(const char *cfname,int colnum,int ihdu=0
-                ,long blen=100,long bsens=1,int lp=0);
-  FitsABTColRead(FitsABTColRead& fbt);
-  virtual ~FitsABTColRead();
+  FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
+              ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
+              ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRd(FitsABTColRd& fbt);
+  FitsABTColRd();
+  virtual ~FitsABTColRd();
 
   void ChangeBuffer(long blen=100,long bsens=1);
@@ -56,4 +78,6 @@
   //! Get the FITS file name
   inline string  GetFileName(void) {return FitsFN;}
+  //! Get the pointer to FitsOpenFile
+  inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;}
   //! Get the FITS file pointer (cfistio pointer)
   inline fitsfile* GetFitsPointer(void) {return FitsPtr;}
@@ -92,5 +116,5 @@
 
 protected:
-  void Init(const char *cfname,const char *collabel,int colnum
+  void Init(FitsOpenFile* fof,const char *collabel,int colnum
            ,int ihdu,long blen,long bsens,int lp);
   void Delete(void);
@@ -106,5 +130,6 @@
 
   unsigned long NFitsRead;
-  fitsfile *FitsPtr;
+  FitsOpenFile* FitsOF;
+  fitsfile* FitsPtr;
   long LineDeb, LineFin;
   double *Buffer;
@@ -112,4 +137,21 @@
 };
 
+///////////////////////////////////////////////////////////////////
+//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
+class FitsABTColRead : public FitsABTColRd {
+public:
+  FitsABTColRead(string fname,string collabel,int ihdu=0
+                ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(string fname,int colnum,int ihdu=0
+                ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
+                ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(const char *cfname,int colnum,int ihdu=0
+                ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(FitsABTColRead& fbt);
+  FitsABTColRead();
+  virtual ~FitsABTColRead();
+};
+
 } // namespace SOPHYA
 #endif    /* FABTCOLREAD_H_SEEN */
