Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1044)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1045)
@@ -8,21 +8,34 @@
 FitsFile::FitsFile() 
 {
+  InitNull();
+}
+ 
+FitsFile::~FitsFile()
+{
+  int status = 0;
+  if( fptr_ != NULL)
+    {
+      fits_close_file(fptr_,&status);
+      delete fptr_;
+    }
+  if( status )  printerror( status );
+}
+
+void FitsFile::InitNull()
+{
   fptr_= NULL; 
   hdutype_= 0;
   hdunum_ = 0; 
 
+  bitpix_ = 0;
+  naxis_ = 0;
+  nbData_ = 0;
   nrows_ = 0;
-}
-
- 
-FitsFile::~FitsFile()
-{
-  int status = 0;
-  if( fptr_ != NULL)
-    {
-      fits_close_file(fptr_,&status);
-      delete fptr_;
-    }
-  if( status )  printerror( status );
+  nbcols_ = 0;
+  naxisn_.clear();
+  repeat_.clear();
+  noms_.clear();
+  taille_des_chaines_.clear();
+  dvl_.Clear();
 }
 
@@ -111,6 +124,9 @@
 void FitsFile::ReadF(char flnm[],int hdunum) 
 {
-  int status = 0;
-  hdutype_= 0;
+  ReadFInit(flnm, hdunum);
+  /*
+  InitNull();
+  int status = 0;
+  //  hdutype_= 0;
   
   fits_open_file(&fptr_,flnm,READONLY,&status);
@@ -147,8 +163,55 @@
       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);
+}
 void FitsFile::moveToFollowingHeader()
 {
@@ -296,4 +359,9 @@
   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];
@@ -314,5 +382,5 @@
   hdunum_++;
   delete [] naxes;
-  if( status ) printerror( status );
+  if( status ) printerror( status, "erreur creation HDU IMAGE"  );
 
 }
@@ -322,5 +390,5 @@
   long npix= nbData;
   fits_write_img(fptr_,TDOUBLE,1,npix,map,&status); 
-  if( status ) printerror( status );
+  if( status ) printerror( status, "erreur ecriture putImageToFits" );
   writeSignatureOnFits();
 }
@@ -331,5 +399,5 @@
   long npix= nbData;
   fits_write_img(fptr_,TFLOAT,1,npix, map,&status); 
-  if( status ) printerror( status );
+  if( status ) printerror( status, "erreur ecriture putImageToFits" );
   writeSignatureOnFits();
 
@@ -341,5 +409,5 @@
   long npix= nbData;
   fits_write_img(fptr_,TINT,1,npix,map,&status); 
-  if( status ) printerror( status );
+  if( status ) printerror( status, "erreur ecriture putImageToFits" );
   writeSignatureOnFits();
 }
@@ -454,5 +522,7 @@
       if( DTYPE != TDOUBLE) 
 	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
+	  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;
@@ -485,5 +555,7 @@
       if( DTYPE != TFLOAT) 
 	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
+	  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;
@@ -561,7 +633,69 @@
       if( status ) printerror( status,"erreur lecture de colonne" );
     }
+
+
+
+void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const
+{
+  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);
+	  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
+{
+  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 ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );
+    }
+}
+
+      
+
+
+
+
+
+
 int  FitsFile::NbColsFromFits() const
 {
-  //  int status= 0;
   if(hdutype_ ==  BINARY_TBL) return nbcols_;
   else
@@ -576,5 +710,4 @@
 char FitsFile::ColTypeFromFits(int nocol) const
 {
-  //  int status= 0;
   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     {
@@ -585,5 +718,4 @@
 int FitsFile::NentriesFromFits(int nocol) const
 {
-  //  int status= 0;
   if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
   else
@@ -600,5 +732,4 @@
 string FitsFile::ColNameFromFits(int nocol) const
 {
-  //  int status= 0;
   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     {
@@ -609,5 +740,4 @@
 int FitsFile::ColStringLengthFromFits(int nocol) const
 {
-  //  int status= 0;
   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
     {
@@ -983,5 +1113,5 @@
   fits_write_comment(fptr_, " (C) DAPNIA/CEA     Saclay, FRANCE 2000", &status);
   fits_write_comment(fptr_,"..............................................", &status);
-  if( status ) printerror( status );
+  if( status ) printerror( status, "erreur writeSignatureOnFits"  );
 }
 
Index: trunk/SophyaExt/FitsIOServer/fitsfile.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1044)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1045)
@@ -65,4 +65,6 @@
 */ 
   void   ReadF(char flnm[],int hdunum= 0);
+  FitsFile* ReadFInit(char flnm[],int hdunum=0); 
+  void ReadFFromFits(); 
  
 /*!
@@ -155,4 +157,17 @@
   void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const;
   // 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 
@@ -210,4 +225,6 @@
 private:
 
+   void InitNull();
+
 static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
 static  void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
@@ -261,4 +278,5 @@
   //! DVList for transferring keywords
   DVList dvl_;
+
 };
 
