Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1333)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1334)
@@ -250,4 +250,11 @@
   fits_get_num_hdus(fileptr, &nbhdu, &status); 
   fits_close_file(fileptr,&status);
+  return nbhdu;
+}
+int FitsInFile::NbBlocks()
+{
+  int status = 0;
+  int nbhdu = 0; 
+  fits_get_num_hdus(fptr_, &nbhdu, &status); 
   return nbhdu;
 }
@@ -304,5 +311,8 @@
   //  InitNull();
   int status = 0;
-
+  if (hdunum<0) 
+    {
+      throw PException(" FITS_AutoReader::ReadObject : hdu number must be not negative");
+    }
   if (hdunum != 0 ) hdunum_ = hdunum;
 
@@ -321,5 +331,16 @@
     }
   getHeader();
-
+  if ( hdutype_ == FitsExtensionType_NULL )
+    {
+      if (hdunum == 0 && hdunum_ == 1)
+	{
+	  hdunum_++;
+	  getHeader();
+	}
+      else 
+	{
+	  cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
+	}
+    }
 }
 
@@ -328,5 +349,5 @@
 {
   int hdunum=0;
-  cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
+  //    cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
   int status= 0;
 
@@ -398,5 +419,5 @@
       if (naxis > 0 )       // there is an image
 	{
-	  hdutype_ = IMAGE_HDU;
+	  hdutype_ = FitsExtensionType_IMAGE;
 	  GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
 	  nbData_ =  1;
@@ -407,11 +428,6 @@
       else
 	{
-	  cout << " WARNING (FitsInFile::getHeader): attempt to read data on the primary hader, which does not contain any... It may be a consequence of confusion in the HDU numbering of the application." << endl;
-	  cout << " The object to be read is supposed to be a bin or ascii table.. on the first extension" << endl;
-	  cout << " Anyway, some trouble can result... " << endl;
-	  hdunum_++;
-	  getHeader();
-
-	  //	  throw PException(" first header : no image, probably error in hdunum");
+	  hdutype_ = FitsExtensionType_NULL;
+	  KeywordsIntoDVList(fptr_, dvl_,hdunum_);
 	}
     }
@@ -420,8 +436,25 @@
       int hdutype;
       fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
-      if( status ) printerror( status,":FitsInFile::getHeader : erreur movabs");
-      hdutype_= hdutype;
-      if(hdutype_ == IMAGE_HDU) 
-	{
+
+      if( status )
+	{
+	  if (status == END_OF_FILE)
+	    {
+	      hdutype_= FitsExtensionType_EOF;
+	      status =0;
+	      return;
+	    }
+	  else
+	    {
+	      cout << "WARNING (FitsInFile::getHeader) : error during movabs" << endl;
+	      hdutype_= FitsExtensionType_ERROR;
+	      status =0;
+	      return;
+	    }
+	  // printerror( status,":FitsInFile::getHeader : erreur movabs");
+	}
+      if(hdutype == IMAGE_HDU) 
+	{
+	  hdutype_= FitsExtensionType_IMAGE;
 	  GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
 	  nbData_ =  1;
@@ -430,9 +463,21 @@
 	  KeywordsIntoDVList(fptr_, dvl_,hdunum_);
 	}
-      if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
-	{
+      else if(hdutype == ASCII_TBL)
+	{
+	  hdutype_= FitsExtensionType_ASCII_TBL;
 	  GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
 	  KeywordsIntoDVList(fptr_, dvl_, hdunum_);
 	}
+      else if(hdutype == BINARY_TBL)
+	{
+	  hdutype_= FitsExtensionType_BINARY_TBL;
+	  GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
+	  KeywordsIntoDVList(fptr_, dvl_, hdunum_);
+	}
+      else 
+	{
+	  hdutype_= FitsExtensionType_NULL;
+	  KeywordsIntoDVList(fptr_, dvl_, hdunum_);
+	}
     }
 }
@@ -444,4 +489,9 @@
   hdunum_++;
   getHeader();
+  if ( hdutype_ == FitsExtensionType_NULL )
+    {
+      cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
+	
+    }
 }
 
@@ -455,11 +505,11 @@
 int  FitsInFile::NbColsFromFits() const
 {
-  if(hdutype_ ==  BINARY_TBL) return nbcols_;
+  if(hdutype_ == FitsExtensionType_BINARY_TBL) return nbcols_;
   else
-    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
+    if(hdutype_ == FitsExtensionType_ASCII_TBL ||  hdutype_ == FitsExtensionType_IMAGE) return 1;
     else
       {
 	cout << " hdutype= " << hdutype_ << endl;
-	throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
+	throw PException("FitsFile::NbColsFromFits, HDU  not supported");
       }
 }
@@ -471,13 +521,13 @@
 int FitsInFile::NentriesFromFits(int nocol) const
 {
-  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
+  if(hdutype_ == FitsExtensionType_BINARY_TBL)   return nrows_*repeat_[nocol];
   else
-    if(hdutype_ == ASCII_TBL) return nrows_;
+    if(hdutype_ == FitsExtensionType_ASCII_TBL) return nrows_;
     else
-      if(hdutype_ == IMAGE_HDU) return nbData_;
+      if(hdutype_ == FitsExtensionType_IMAGE) return nbData_;
       else
 	{
 	  cout << "hdutype= " << hdutype_ << endl;
-	  throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
+	  throw PException("FitsFile::NentriesFromFits, this HDU is not supported");
 	}
 }
@@ -499,5 +549,5 @@
 FitsFile::FitsDataType FitsInFile::ColTypeFromFits(int nocol) const
 {
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+  if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
     {
       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
@@ -514,5 +564,5 @@
 string FitsInFile::ColNameFromFits(int nocol) const
 {
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+  if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
     {
       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
@@ -528,5 +578,5 @@
 int FitsInFile::ColStringLengthFromFits(int nocol) const
 {
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+  if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
     {
       throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
@@ -806,5 +856,5 @@
 { 
   int status = 0;
-  if(hdutype_ == IMAGE_HDU) 
+  if(hdutype_ == FitsExtensionType_IMAGE) 
     {
   
@@ -824,5 +874,38 @@
     }
   else
-    if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
+    if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
+      {
+	GetBinTabFCol(map,nentries, 0);
+      }
+    else
+      {
+      cout << " hdutype= " << hdutype_ << endl;
+      throw IOExc("FitsFile::GetSingleColumn, this HDU is unknown");
+      }
+}
+
+/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
+same as above with float data 
+*/
+void FitsInFile::GetSingleColumn(float* map, int nentries) const
+{
+  int status = 0;
+  if(hdutype_ == FitsExtensionType_IMAGE) 
+    {
+      if(imageDataType_ != FitsDataType_float) 
+	{
+	  cout << " The data type on fits file is not float ";
+	  cout << " Conversion to float achieved by cfitsio lib" << endl;
+	}
+      // no checking for undefined pixels
+      int   anull;
+      float fnull= 0.;
+      
+      long nels= nentries;
+      fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
+      if( status ) printerror( status );
+    }
+  else
+    if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
       {
 	GetBinTabFCol(map,nentries, 0);
@@ -835,15 +918,15 @@
 }
 
-/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
-same as above with float data 
-*/
-void FitsInFile::GetSingleColumn(float* map, int nentries) const
-{
-  int status = 0;
-  if(hdutype_ == IMAGE_HDU) 
-    {
-      if(imageDataType_ != FitsDataType_float) 
-	{
-	  cout << " The data type on fits file is not float ";
+/*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
+ same as above with int data 
+*/
+void FitsInFile::GetSingleColumn( int* map, int nentries) const
+{
+  int status = 0;
+  if(hdutype_ == FitsExtensionType_IMAGE) 
+    {
+      if(imageDataType_ != FitsDataType_int) 
+	{
+	  cout << " The data type on fits file is not int ";
 	  cout << " Conversion to float achieved by cfitsio lib" << endl;
 	}
@@ -853,9 +936,9 @@
       
       long nels= nentries;
-      fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
+      fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
       if( status ) printerror( status );
     }
   else
-    if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
+    if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
       {
 	GetBinTabFCol(map,nentries, 0);
@@ -868,37 +951,4 @@
 }
 
-/*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
- same as above with int data 
-*/
-void FitsInFile::GetSingleColumn( int* map, int nentries) const
-{
-  int status = 0;
-  if(hdutype_ == IMAGE_HDU) 
-    {
-      if(imageDataType_ != FitsDataType_int) 
-	{
-	  cout << " The data type on fits file is not int ";
-	  cout << " Conversion to float achieved by cfitsio lib" << endl;
-	}
-      // no checking for undefined pixels
-      int   anull;
-      float fnull= 0.;
-      
-      long nels= nentries;
-      fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
-      if( status ) printerror( status );
-    }
-  else
-    if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
-      {
-	GetBinTabFCol(map,nentries, 0);
-      }
-    else
-      {
-      cout << " hdutype= " << hdutype_ << endl;
-      throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
-      }
-}
-
 void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
 				  vector<int>& repeat,
@@ -917,8 +967,8 @@
       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;
+  //  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
