Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 867)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 903)
@@ -2,6 +2,6 @@
 #include "pexceptions.h"
 #include "strutil.h"
- 
-
+#include "anydataobj.h" 
+#include "fitsspherehealpix.h"
 FitsFile::FitsFile() 
 {
@@ -17,7 +17,95 @@
 {
   int status = 0;
-  if( fptr_ != NULL) fits_close_file(fptr_,&status);
+  if( fptr_ != NULL)
+    {
+      fits_close_file(fptr_,&status);
+      delete fptr_;
+    }
   if( status )  printerror( status );
 }
+
+
+int FitsFile::NbBlocks(char flnm[])
+{
+  int status = 0;
+  int nbhdu = 0; 
+  fitsfile* fileptr; 
+  fits_open_file(&fileptr,flnm,READONLY,&status);
+  if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" );
+  fits_get_num_hdus(fileptr, &nbhdu, &status); 
+  fits_close_file(fileptr,&status);
+  return nbhdu;
+}
+
+void FitsFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
+{
+  int status = 0;
+  fitsfile* fileptr; 
+  fits_open_file(&fileptr,flnm,READONLY,&status);
+  if( status ) printerror( status, "getBlockType: erreur ouverture fichier" );
+  // move to the specified HDU number
+  int hdutype = 0;
+  fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
+  if( status ) printerror( status,"getBlockType: erreur movabs");
+  if(hdutype == IMAGE_HDU) 
+    {
+      typeOfExtension = "IMAGE";
+      int bitpix;
+      GetImageParameters (fileptr, bitpix, naxis, naxisn);
+      if(bitpix == DOUBLE_IMG) dataType = "double";
+      else
+	if(bitpix == FLOAT_IMG) dataType = "float";
+	else
+	  if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = "int";
+	  else 
+	    {
+	      cout << " bitpix= " << bitpix << endl;
+	      throw PException(" FitsFile::getBlockType : unsupprted FITS data type");
+	    }
+      
+    }
+  else
+    if(hdutype == ASCII_TBL  || hdutype == BINARY_TBL) 
+      {
+	int nrows = 0;
+	vector<string> noms; 
+	vector<char> types;   
+	vector<int>  taille_des_chaines;
+	GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines);  
+	for (int k=0; k< naxisn.size(); k++) naxisn[k] *= nrows;
+	if(hdutype == ASCII_TBL)
+	  {
+	    typeOfExtension = "ASCII_TBL"; 
+	    dataType = "ASCII";
+	  }
+	else
+	  {
+	    typeOfExtension = "BINARY_TBL";
+	    if(types[0] == 'D') dataType = "double";
+	    else
+	      if(types[0] == 'E') dataType = "float";
+	      else
+		if(types[0] == 'I' ) dataType = "int";
+		else
+		  if(types[0] == 'S' ) dataType = "char*";
+		  else 
+		    {
+		      cout << " types[0]= " << types[0] << endl;
+		      throw PException(" FitsFile::getBlockType : unsupprted FITS data type");
+	    }
+	  }
+      }
+    else
+      {
+	cout << " hdutype= " << hdutype << endl;
+	throw IOExc("FitsFile::getBlockType: this HDU type is unknown");
+      }
+  
+  fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
+  if( status ) printerror( status,"getBlockType: erreur movabs, pour dvlist");
+  KeywordsIntoDVList(fileptr, dvl);
+  fits_close_file(fileptr,&status);
+}
+
 void FitsFile::ReadF(char flnm[],int hdunum) 
 {
@@ -37,9 +125,17 @@
   if(hdutype_ == IMAGE_HDU) 
     {
-      read_image();
+      GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
+      nbData_ =  1;
+      for (int k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
+      fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
+      if( status ) printerror( status);
+      KeywordsIntoDVList(fptr_, dvl_);
     }
   if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
     {
-      GetBinTabParameters();
+      GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
+  fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
+  if( status ) printerror( status);
+  KeywordsIntoDVList(fptr_, dvl_);
     }
   ReadFromFits(*this);
@@ -199,261 +295,40 @@
 
 
-void FitsFile::read_image()
-{
-  cout << " Reading a FITS image in HDU : " << hdunum_ << endl;
+
+void FitsFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
+{
+  int hdunum=0;
+  cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum)  << endl;
   int status= 0;
 
   // bits per pixels
-  fits_read_key(fptr_,TINT,"BITPIX",&bitpix_,NULL,&status);
+  fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
   if( status )  printerror( status );
 
   // number of dimensions in the FITS array
-  int naxis= 0;
-  fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
-  if( status ) printerror( status );
-  naxis_ = naxis;
-
-  // read the NAXIS1 and NAXIS2 keyword to get image size
-  long* naxes = new long[naxis_] ;
+  naxis= 0;
+  fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
+  if( status ) printerror( status );
+
+  // read the NAXISn keywords to get image size
+  long* naxes = new long[naxis] ;
   int nfound;
-  fits_read_keys_lng(fptr_,"NAXIS",1,naxis_,naxes,&nfound,&status);
-  if( status ) printerror( status );
-  if (nfound != naxis_ ) 
-    cout << " WARNING : " << nfound << " axes found, expexted naxis= " << naxis_ << endl;
-  int lastSize = naxes[naxis_-1]; 
-  while (lastSize <= 1) 
-    {
-      naxis_--;
-      lastSize = naxes[naxis_-1];
-    }
-
-  nbData_ =  1;
-  for (int k=0; k<naxis_; k++) 
-    {
-      naxisn_.push_back( (int)naxes[k] );
-      if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
-
+  fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
+  if( status ) printerror( status );
+  if (nfound != naxis ) 
+    cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
+  for (int k=0; k<naxis; k++) 
+    {
+      naxisn.push_back( (int)naxes[k] );
     }
   delete [] naxes;
 }
 
- 
-  void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-            fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TDOUBLE) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
-	}
-      long nels=nentries;
-      // no checking for undefined pixels
-      int    anull;
-      float dnull= 0.;
-      fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
-			    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-
-  void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TFLOAT) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
-	}
-      long nels=nentries;
-      // no checking for undefined pixels
-      int    anull;
-      float fnull= 0.;
-      fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
-			    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-  void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      long repeat,width;
-      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT ) 
-	{
-	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
-	}
-      long nels=nentries;
-      // no checking for undefined pixels
-      int    anull;
-      int inull= 0;
-      fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
-			    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-  void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
-    {
-      int status= 0;
-      int DTYPE;
-      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");
-	}
-      long nels=nentries;
-      // no checking for undefined pixels
-      int    anull;
-      char* cnull= " ";
-      long frow=1;
-      long felem=1;
-      fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
-		    &anull,&status);
-      if( status ) printerror( status,"erreur lecture de colonne" );
-    }
-int  FitsFile::NbColsFromFits() const
-{
-  int status= 0;
-  if(hdutype_ ==  BINARY_TBL) return nbcols_;
-  else
-    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
-    else
-      {
-	cout << " hdutype= " << hdutype_ << endl;
-	throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
-      }
-}
-
-char FitsFile::ColTypeFromFits(int nocol) const
-{
-  int status= 0;
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
-    }
-  return types_[nocol];
-}
-int FitsFile::NentriesFromFits(int nocol) const
-{
-  int status= 0;
-  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
-  else
-    if(hdutype_ == ASCII_TBL) return nrows_;
-    else
-      if(hdutype_ == IMAGE_HDU) return nbData_;
-      else
-	{
-	  cout << "hdutype= " << hdutype_ << endl;
-	  throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
-	}
-}
-
-string FitsFile::ColNameFromFits(int nocol) const
-{
-  int status= 0;
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
-    }
-  return noms_[nocol];
-}
-int FitsFile::ColStringLengthFromFits(int nocol) const
-{
-  int status= 0;
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
-    }
-  int index=-1;
-  for (int k=0; k<=nocol; k++) 
-    {
-      if (types_[k] == 'S') index++;
-    }
-  return  taille_des_chaines_[index];
-}
-
-void FitsFile::GetBinTabParameters()
-{
-  int status= 0;
-  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
-    {
-      throw IOExc("FitsFile:: 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;
-
-  // get the number of columns
-  int nbcols = 0;
-  fits_get_num_cols(fptr_, &nbcols,&status);
-  if( status ) printerror( status );
-  nbcols_=nbcols;
-
-  // get the number of rows
-  long naxis2= 0;
-  fits_get_num_rows(fptr_,&naxis2,&status);
-  if( status ) printerror( status );
-  nrows_= (int)naxis2;
-
-  // get the datatype,  names and the repeat count
-  noms_.clear();
-  noms_.reserve(nbcols);
-  types_.clear();
-  types_.reserve(nbcols);
-  repeat_.clear();
-  repeat_.reserve(nbcols);
-  taille_des_chaines_.clear();
-  char **ttype = new char*[nbcols];
-  for (int ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
-  int nfound;
-  fits_read_keys_str(fptr_, "TTYPE",1,nbcols,ttype,&nfound, &status);
-  if( status ) printerror( status,"erreur lecture des noms de colonne");
-  //  int nentries = nrows_;
-  int rept=0;
-  for(int ii = 0; ii <  nbcols; ii++)
-    {
-      int DTYPE;
-      long width;
-      long repeat = 0;
-      fits_get_coltype(fptr_,ii+1,&DTYPE,&repeat,&width,&status);
-      if( status ) printerror( status,"erreur lecture type de colonne");
-      rept = repeat;
-      noms_.push_back(string(ttype[ii]));
-      //      cout << " getparam: nentries= " << nentries << " rept= " << rept << endl;
-      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");
-	}
-      //    nentries = max(nentries, nrows_*rept);
-      repeat_.push_back(rept);
-    } 
+void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl)
+{
   // get number of keywords
   int nkeys,keypos;
-  fits_get_hdrpos(fptr_,&nkeys,&keypos,&status);
+  int status = 0;
+  fits_get_hdrpos(fileptr,&nkeys,&keypos,&status);
   if( status ) printerror( status );
 
@@ -470,5 +345,5 @@
   for(int j = num+1; j <= nkeys; j++)
     {
-      fits_read_keyn(fptr_,j,card,strval,NULL,&status);
+      fits_read_keyn(fileptr,j,card,strval,NULL,&status);
       if(status) printerror(status);
 
@@ -488,10 +363,10 @@
 	    { 
 	    case 'C':
-	      dvl_[keyname]= strval;	  
+	      dvl[keyname]= strval;	  
 	      break;
 	    case 'I':
 	      int ival;
-	      fits_read_key(fptr_,TINT,keyname,&ival,NULL,&status);
-	        dvl_[keyname]= (int_4) ival;		// Portage mac DY
+	      fits_read_key(fileptr,TINT,keyname,&ival,NULL,&status);
+	        dvl[keyname]= (int_4) ival;		// Portage mac DY
 	      break;
 	    case 'L':
@@ -499,10 +374,10 @@
 	      if(strncmp(strval,"T",1) == 0) ilog= 1;
 	      else ilog= 0;
-	      dvl_[keyname]= (int_4) ilog;
+	      dvl[keyname]= (int_4) ilog;
 	      break;
 	    case 'F':
 	      double dval;
-	      fits_read_key(fptr_,TDOUBLE,keyname,&dval,NULL,&status);
-	      dvl_[keyname]= dval;
+	      fits_read_key(fileptr,TDOUBLE,keyname,&dval,NULL,&status);
+	      dvl[keyname]= dval;
 	      break;
 	    }
@@ -511,5 +386,232 @@
     } 
   //  dvl_.Print();
-}
+} 
+
+
+ 
+  void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+            fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TDOUBLE) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
+	}
+      long nels=nentries;
+      // no checking for undefined pixels
+      int    anull;
+      float dnull= 0.;
+      fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
+			    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+
+  void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TFLOAT) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
+	}
+      long nels=nentries;
+      // no checking for undefined pixels
+      int    anull;
+      float fnull= 0.;
+      fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
+			    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+  void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      long repeat,width;
+      fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
+      if( DTYPE != TLONG &&  DTYPE != TINT &&  DTYPE != TSHORT ) 
+	{
+	  throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
+	}
+      long nels=nentries;
+      // no checking for undefined pixels
+      int    anull;
+      int inull= 0;
+      fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
+			    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+  void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
+    {
+      int status= 0;
+      int DTYPE;
+      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");
+	}
+      long nels=nentries;
+      // no checking for undefined pixels
+      int    anull;
+      char* cnull= " ";
+      long frow=1;
+      long felem=1;
+      fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
+		    &anull,&status);
+      if( status ) printerror( status,"erreur lecture de colonne" );
+    }
+int  FitsFile::NbColsFromFits() const
+{
+  int status= 0;
+  if(hdutype_ ==  BINARY_TBL) return nbcols_;
+  else
+    if(hdutype_ == ASCII_TBL ||  hdutype_ == IMAGE_HDU) return 1;
+    else
+      {
+	cout << " hdutype= " << hdutype_ << endl;
+	throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
+      }
+}
+
+char FitsFile::ColTypeFromFits(int nocol) const
+{
+  int status= 0;
+  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
+    }
+  return types_[nocol];
+}
+int FitsFile::NentriesFromFits(int nocol) const
+{
+  int status= 0;
+  if(hdutype_ == BINARY_TBL  )   return nrows_*repeat_[nocol];
+  else
+    if(hdutype_ == ASCII_TBL) return nrows_;
+    else
+      if(hdutype_ == IMAGE_HDU) return nbData_;
+      else
+	{
+	  cout << "hdutype= " << hdutype_ << endl;
+	  throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
+	}
+}
+
+string FitsFile::ColNameFromFits(int nocol) const
+{
+  int status= 0;
+  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
+    }
+  return noms_[nocol];
+}
+int FitsFile::ColStringLengthFromFits(int nocol) const
+{
+  int status= 0;
+  if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
+    {
+      throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
+    }
+  int index=-1;
+  for (int k=0; k<=nocol; k++) 
+    {
+      if (types_[k] == 'S') index++;
+    }
+  return  taille_des_chaines_[index];
+}
+
+
+
+void FitsFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
+				  vector<int>& repeat,
+				  vector<string>& noms, 
+				  vector<char>& types,   
+				  vector<int>&  taille_des_chaines)
+{
+  int status= 0;
+  int hdunum=0;
+  int hdutype=0;
+  fits_get_hdu_num(fileptr,&hdunum);
+  fits_get_hdu_type(fileptr, &hdutype, &status);
+
+  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
+    {
+      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;
+
+  // get the number of columns
+  fits_get_num_cols(fileptr, &nbcols,&status);
+  if( status ) printerror( status );
+
+  // get the number of rows
+  long naxis2= 0;
+  fits_get_num_rows(fileptr,&naxis2,&status);
+  if( status ) printerror( status );
+  nrows = (int)naxis2;
+
+  // get the datatype,  names and the repeat count
+  noms.clear();
+  noms.reserve(nbcols);
+  types.clear();
+  types.reserve(nbcols);
+  repeat.clear();
+  repeat.reserve(nbcols);
+  taille_des_chaines.clear();
+  char **ttype = new char*[nbcols];
+  for (int ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
+  int nfound;
+  fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
+  if( status ) printerror( status,"erreur lecture des noms de colonne");
+  int rept=0;
+  for(int 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);
+    } 
+}
+
+
+
 void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const
 { 
@@ -777,5 +879,8 @@
 }
 
-void FitsFile::printerror(int &status) const
+
+
+
+void FitsFile::printerror(int &status) 
   //*****************************************************/
   //* Print out cfitsio error messages and exit program */
@@ -790,5 +895,5 @@
 }
 
-void FitsFile::printerror(int& status, char* texte) const
+void FitsFile::printerror(int& status, char* texte) 
   //*****************************************************/
   //* Print out cfitsio error messages and exit program */
