Index: /trunk/SophyaExt/FitsIOServer/fitsautoreader.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsautoreader.cc	(revision 1333)
+++ /trunk/SophyaExt/FitsIOServer/fitsautoreader.cc	(revision 1334)
@@ -25,11 +25,24 @@
 }
 
+int FITS_AutoReader::NbBlocks()
+{
+  return inFits_->NbBlocks();
+}
 
 AnyDataObj* FITS_AutoReader::ReadObject(int hdunum) const
 {
+  if (hdunum<=0) 
+    {
+      throw PException(" FITS_AutoReader::ReadObject : hdu number must be positive");
+    }
   inFits_->ReadHeader(hdunum);
+  if (inFits_->IsFitsEOF()) return NULL;
+  if (inFits_->IsFitsERROR())
+    {
+      throw IOExc("FITS_AutoReader::ReadObject: FITSIO error in reading");
+    }
   DVList dvl=inFits_->DVListFromFits();
   string nameObj = dvl.GetS("CONTENT");
-  cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
+  //    cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
   if (nameObj == string("TArray") )
     {
@@ -83,5 +96,6 @@
   else
     {
-      throw IOExc("FITS_AutoReader::ReadObject : object not recognized as a  SOPHYA object");
+      cout << " WARNING ( FITS_AutoReader::ReadObject) : object not recognized as a  SOPHYA object" << endl;
+      return new DVList(dvl);
     }
   
Index: /trunk/SophyaExt/FitsIOServer/fitsautoreader.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsautoreader.h	(revision 1333)
+++ /trunk/SophyaExt/FitsIOServer/fitsautoreader.h	(revision 1334)
@@ -29,5 +29,6 @@
 FITS_AutoReader(string const & inputfile);
 virtual ~FITS_AutoReader();
-AnyDataObj* ReadObject(int hdunum = 0) const;
+ int NbBlocks();
+AnyDataObj* ReadObject(int hdunum) const;
 
 
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
Index: /trunk/SophyaExt/FitsIOServer/fitsfile.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1333)
+++ /trunk/SophyaExt/FitsIOServer/fitsfile.h	(revision 1334)
@@ -55,7 +55,10 @@
 
    enum FitsExtensionType {
+     FitsExtensionType_NULL,
      FitsExtensionType_IMAGE,
      FitsExtensionType_ASCII_TBL,
-     FitsExtensionType_BINARY_TBL
+     FitsExtensionType_BINARY_TBL,
+     FitsExtensionType_EOF,
+     FitsExtensionType_ERROR
    };
    enum FitsDataType {
@@ -81,8 +84,8 @@
    static  void printerror(int&) ;
    static  void printerror(int&,char* texte) ;
-   inline void  InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 0; 
+   inline void  InitNull() {fptr_ = NULL; hdutype_= FitsExtensionType_NULL; hdunum_ = 0; 
    fits_status_ = 0; imageOnPrimary_ = true;}
    fitsfile *fptr_;     /**<  pointer to the FITS file, defined in fitsio.h */
-   int hdutype_;        /**<  image or bintable ? */
+   FitsExtensionType hdutype_;        /**<  image or bintable ? */
    int hdunum_;         /**<   index of header to be read/written */
    int fits_status_;    /**< last status returned by fitsio library. updated only by several methods */
@@ -102,4 +105,5 @@
 
    static int  NbBlocks(char flnm[]);
+   int  NbBlocks();
    static void GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl  );
    void        ReadHeader(int hdunum);
@@ -126,5 +130,5 @@
 
 /*! \return true if the current header  corresponds to a FITS image extension */
-inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);}
+inline bool IsFitsImage() const { return (hdutype_ == FitsExtensionType_IMAGE);}
 
 
@@ -152,5 +156,5 @@
 
 /*! \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);}
+inline bool IsFitsTable() const {return (hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL);}
 
 
@@ -176,4 +180,9 @@
 ////////////////////////////////////////////////////////
 
+/*! \return true if the current header  is beyond the maximum */
+inline bool IsFitsEOF() const {return (hdutype_ == FitsExtensionType_EOF);}
+/*! \return true if the current header  is incorrect, following a cfitsio, movavs error */
+inline bool IsFitsERROR() const {return (hdutype_ == FitsExtensionType_ERROR);}
+
   int     NbColsFromFits() const;
   int     NentriesFromFits(int nocol) const;
Index: /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1333)
+++ /trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc	(revision 1334)
@@ -203,5 +203,4 @@
   //
   dobj_->Info()  = is.DVListFromFits();
-  cout << " end of file reading " << endl;
 }
 
Index: /trunk/SophyaExt/FitsIOServer/fitstarray.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1333)
+++ /trunk/SophyaExt/FitsIOServer/fitstarray.cc	(revision 1334)
@@ -73,6 +73,4 @@
     }
   int dimension = is.nbDimOfImage();
-  cout << " dimension de l'image a lire: " << dimension << endl;
-   
   sa_size_t * siz = new sa_size_t[dimension];
   for (int k=0; k< dimension; k++) siz[k] = is.dimOfImageAxes()[k];
