Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1281)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1300)
@@ -104,5 +104,5 @@
 void FitsIOHandler::Read(FitsInFile& is, int hdunum) 
 {
-  is.ReadFInit(hdunum);
+  is.ReadHeader(hdunum);
   ReadFromFits(is);
 }
@@ -224,6 +224,5 @@
 void FitsInFile::InitNull()
 {
-  
-  bitpix_ = 0;
+  imageDataType_ = FitsDataType_NULL;
   naxis_ = 0;
   nbData_ = 0;
@@ -236,5 +235,4 @@
   dvl_.Clear();
   
-  
 }
 
@@ -268,19 +266,5 @@
     {
       typeOfExtension = FitsExtensionType_IMAGE;
-      int bitpix;
-      GetImageParameters (fileptr, bitpix, naxis, naxisn);
-      if(bitpix == DOUBLE_IMG) dataType = FitsDataType_double;
-      else
-	if(bitpix == FLOAT_IMG) dataType = FitsDataType_float;
-	else
-	  if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = FitsDataType_int;
-	  else
-	    if (bitpix == BYTE_IMG) dataType = FitsDataType_char;
-	    else 
-	    {
-	      cout << " bitpix= " << bitpix << endl;
-	      throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
-	    }
-      
+      GetImageParameters (fileptr, dataType, naxis, naxisn);
     }
   else
@@ -289,5 +273,5 @@
 	int nrows = 0;
 	vector<string> noms; 
-	vector<char> types;   
+	vector<FitsDataType> types;   
 	vector<int>  taille_des_chaines;
 	GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines); 
@@ -302,16 +286,5 @@
 	  {
 	    typeOfExtension = FitsExtensionType_BINARY_TBL;
-	    if(types[0] == 'D') dataType = FitsDataType_double;
-	    else
-	      if(types[0] == 'E') dataType = FitsDataType_float;
-	      else
-		if(types[0] == 'I' ) dataType = FitsDataType_int;
-		else
-		  if(types[0] == 'S' ) dataType = FitsDataType_char;
-		  else 
-		    {
-		      cout << " types[0]= " << types[0] << endl;
-		      throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
-	    }
+	    dataType = types[0];
 	  }
       }
@@ -327,7 +300,7 @@
 
 
-void FitsInFile::ReadFInit(int hdunum) 
-{
-  InitNull();
+void FitsInFile::ReadHeader(int hdunum) 
+{
+  //  InitNull();
   int status = 0;
 
@@ -352,5 +325,5 @@
 
 
-void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
+void FitsInFile::GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn)
 {
   int hdunum=0;
@@ -359,6 +332,16 @@
 
   // bits per pixels
+  int bitpix=0;
   fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
   if( status )  printerror( status );
+  if(bitpix == DOUBLE_IMG) dataType = FitsDataType_double;
+  else if(bitpix == FLOAT_IMG) dataType = FitsDataType_float;
+  else if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = FitsDataType_int;
+  else if (bitpix == BYTE_IMG) dataType = FitsDataType_char;
+  else 
+    {
+      cout << " bitpix= " << bitpix << endl;
+      throw PException(" FitsFile::GetImageParameters : unsupported FITS data type");
+    }
 
   // number of dimensions in the FITS array
@@ -401,6 +384,10 @@
 void FitsInFile::getHeader()
 {
+  // si hdunum_ > 1 lit le header correspondant
+  // si hdunum_ = 1 se positionne au (et lit le) premier header qui 
+  //                contient reellement un objet 
   int status=0;
   if (hdunum_ < 1)  throw PException(" attempt to read hdunum < 1");
+   InitNull();
   if (hdunum_ == 1)
     {
@@ -412,5 +399,5 @@
 	{
 	  hdutype_ = IMAGE_HDU;
-	  GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
+	  GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
 	  nbData_ =  1;
 	  int k;
@@ -436,5 +423,5 @@
       if(hdutype_ == IMAGE_HDU) 
 	{
-	  GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
+	  GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
 	  nbData_ =  1;
 	  int k;
@@ -509,5 +496,5 @@
   */
 
-char FitsInFile::ColTypeFromFits(int nocol) const
+FitsFile::FitsDataType FitsInFile::ColTypeFromFits(int nocol) const
 {
   if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
@@ -548,5 +535,5 @@
   for (k=0; k<=nocol; k++) 
     {
-      if (types_[k] == 'S') index++;
+      if (types_[k] == FitsDataType_char) index++;
     }
   return  taille_des_chaines_[index];
@@ -578,15 +565,15 @@
       switch (types_[ncol])
 	{ 
-	case 'D' :
+	case FitsDataType_double :
 	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
 	    break;
-	case 'E' :
+	case FitsDataType_float :
 	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
 	  break;
-	case 'I' :
+	case  FitsDataType_int :
 	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
 			&anull,&status);
 	  break;
-	case 'S' :
+	case FitsDataType_char :
 	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
 	  break;
@@ -621,15 +608,15 @@
       switch (types_[ncol])
 	{ 
-	case 'D' :
+	case FitsDataType_double :
 	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anull,&status);
-	    break;
-	case 'E' :
+	  break;
+	case FitsDataType_float :
 	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anull,&status);
 	  break;
-	case 'I' :
+	case FitsDataType_int :
 	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++],
 			&anull,&status);
 	  break;
-	case 'S' :
+	case FitsDataType_char :
 	  char* chaine = new char[taille_des_chaines_[ccount]];
 	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anull,&status);
@@ -789,7 +776,7 @@
       long repeat,width;
       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TSTRING ) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
+      if( DTYPE != TSTRING &&  DTYPE != TBYTE) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non string");
 	}
       long nels=nentries;
@@ -821,5 +808,5 @@
     {
   
-      if(bitpix_ != DOUBLE_IMG) 
+      if(imageDataType_ != FitsDataType_double) 
 	{
 	  cout << " The data type on fits file is not double...";
@@ -855,5 +842,5 @@
   if(hdutype_ == IMAGE_HDU) 
     {
-      if(bitpix_ != FLOAT_IMG) 
+      if(imageDataType_ != FitsDataType_float) 
 	{
 	  cout << " The data type on fits file is not float ";
@@ -888,5 +875,5 @@
   if(hdutype_ == IMAGE_HDU) 
     {
-      if(bitpix_ != LONG_IMG) 
+      if(imageDataType_ != FitsDataType_int) 
 	{
 	  cout << " The data type on fits file is not int ";
@@ -916,5 +903,5 @@
 				  vector<int>& repeat,
 				  vector<string>& noms, 
-				  vector<char>& types,   
+				  vector<FitsDataType>& types,   
 				  vector<int>&  taille_des_chaines)
 {
@@ -961,40 +948,85 @@
   if( status ) printerror( status,"erreur lecture des noms de colonne");
   int rept=0;
-  for(ii = 0; ii <  nbcols; ii++)
-    {
-      int DTYPE;
-      long width;
-      long repete = 0;
-      fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
-      if( status ) printerror( status,"erreur lecture type de colonne");
-      rept = repete;
-      noms.push_back(string(ttype[ii]));
-      switch (DTYPE)
-	{
-	case TDOUBLE :
-	  types.push_back('D');
-	  break;
-	case TFLOAT :
-	  types.push_back('E');
-	  break;
-	case TLONG :
-	  types.push_back('I');
-	  break;
-	case TINT :
-	  types.push_back('I');
-	  break;
-	case TSHORT :
-	  types.push_back('I');
-	  break;
-	case TSTRING :
-	  types.push_back('S');
-	  taille_des_chaines.push_back(width);
-	  rept/=width;
-	  break;
-	default :
-	  cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
-	  throw IOExc("FitsFile:: unknown type of field");
-	}
-      repeat.push_back(rept);
+  if(hdutype == ASCII_TBL)
+    {
+      for(ii = 0; ii <  nbcols; ii++)
+	{
+	  int DTYPE;
+	  long width;
+	  long repete = 0;
+	  fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
+	  if( status ) printerror( status,"erreur lecture type de colonne");
+	  rept = repete;
+	  noms.push_back(string(ttype[ii]));
+	  switch (DTYPE)
+	    {
+	    case TDOUBLE :
+	      types.push_back(FitsDataType_double);
+	      break;
+	    case TFLOAT :
+	      types.push_back(FitsDataType_float);
+	      break;
+	    case TLONG :
+	      types.push_back(FitsDataType_int);
+	      break;
+	    case TSHORT :
+	      types.push_back(FitsDataType_int);
+	      break;
+	    case TSTRING :
+	      types.push_back(FitsDataType_char);
+	      taille_des_chaines.push_back(width);
+	      rept/=width;
+	      break;
+	    default :
+	      cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
+	      throw IOExc("FitsFile::GetBinTabParameters, unsupported data type of field, for ASCII table");
+	    }
+	  repeat.push_back(rept);
+	}
+    }
+  else 
+    {
+      for(ii = 0; ii <  nbcols; ii++)
+	{
+	  int DTYPE;
+	  long width;
+	  long repete = 0;
+	  fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
+	  if( status ) printerror( status,"erreur lecture type de colonne");
+	  rept = repete;
+	  noms.push_back(string(ttype[ii]));
+	  switch (DTYPE)
+	    {
+	    case TDOUBLE :
+	      types.push_back(FitsDataType_double);
+	      break;
+	    case TFLOAT :
+	      types.push_back(FitsDataType_float);
+	      break;
+	    case TLONG :
+	      types.push_back(FitsDataType_int);
+	      break;
+	    case TINT :
+	      types.push_back(FitsDataType_int);
+	      break;
+	    case TSHORT :
+	      types.push_back(FitsDataType_int);
+	      break;
+	    case TSTRING :
+	      types.push_back(FitsDataType_char);
+	      taille_des_chaines.push_back(width);
+	      rept/=width;
+	      break;
+	    case TBYTE :
+	      types.push_back(FitsDataType_char);
+	      taille_des_chaines.push_back(width);
+	      rept/=width;
+	      break;
+	    default :
+	      cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
+	      throw IOExc("FitsFile::GetBinTabParameters, unsupported data type of field, for BINTABLE");
+	    }
+	  repeat.push_back(rept);
+	}
     }
   for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
@@ -1292,10 +1324,10 @@
 \param <taille_des_chaines> vector containing the number of characters of  data  for each char* typed column, with order of appearance in 'fieldType'
 */
-void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* ptr_dvl, string extname, vector<int> taille_des_chaines) 
+void FitsOutFile::makeHeaderBntblOnFits(string fieldType, vector<string> Noms, int nentries, int tfields, DVList* ptr_dvl, string extname, vector<int> taille_des_chaines) 
 { 
   int k;
   int status = 0;
   long nrows;
-  // verifications de coherence
+  // verifications de coherences
 
   if (fieldType.length() != tfields)
