Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 2129)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 2197)
@@ -26,8 +26,8 @@
     if (dc >0) ddata_ = vector<double>(dc);
     if (fc >0) fdata_ = vector<float>(fc);
-    if (ic >0) idata_ = vector<int>(fc);
-    if (cc >0) cdata_ = vector<string>(fc);
+    if (ic >0) idata_ = vector<int>(ic);
     if (lc >0) ldata_ = vector<long>(lc);
     if (bc >0) bdata_ = vector<unsigned char>(bc);
+    if (cc >0) cdata_ = vector<string>(cc);
    }
 
@@ -66,5 +66,133 @@
    }
 
-
+FitsFile::BufferLine::BufferLine(const vector<FitsFile::FitsDataType>& types)
+{
+
+
+  int dc=0;
+  int fc=0;
+  int shc=0;
+  int ic=0;
+  int lc=0;
+  int cc=0;
+  int bc=0;
+  id_  = vector< pair<FitsFile::FitsDataType, int> >(types.size());
+  for (int k= 0; k < types.size(); k++)
+    {
+      switch( types[k] )
+	{
+	case FitsFile::FitsDataType_double :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_double, dc);
+	    dc++;
+	    break;
+	  }
+	case FitsFile::FitsDataType_float :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_float, fc);
+	    fc++;
+	    break;
+	  }
+	case  FitsFile::FitsDataType_short :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsDataType_short, shc);
+	    shc++;
+	    break;
+	  }
+	case  FitsFile::FitsDataType_int :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsDataType_int, ic);
+	    ic++;
+	    break;
+	  }
+	case  FitsFile::FitsDataType_long :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_long, lc);
+	    lc++;
+	    break;
+	  }
+	case  FitsFile::FitsDataType_byte :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_byte, bc);
+	    bc++;
+	    break;
+	  }
+	case FitsDataType_char :
+	  {
+            id_[k] = pair<FitsFile::FitsDataType, int>(FitsFile::FitsDataType_char, cc);
+	    cc++;
+	    break;
+	  }
+	default:
+	  {
+	    throw PException(" FitsFile::getHeaderWithSophyaObject() : unsupported FITS data type");
+	  }
+	}
+    }
+
+  if (dc >0) ddata_ = vector<r_8>(dc);
+  if (fc >0) fdata_ = vector<r_4>(fc);
+  if (shc >0) shdata_ = vector<int_2>(shc);
+  if (ic >0) idata_ = vector<int_4>(ic);
+  if (lc >0) ldata_ = vector<int_8>(lc);
+  if (cc >0) cdata_ = vector<string>(cc);
+  if (bc >0) bdata_ = vector<unsigned char>(bc);
+}
+
+
+void FitsFile::BufferLine::Print() const
+{
+  cout << " impression de la ligne: " << endl;
+
+  cout << " doubles : " << endl;
+  for (int k=0; k< ddata_.size(); k++)
+    {
+      cout << ddata_[k] << " " ;
+    } 
+  cout << endl;
+
+  cout << " floats : " << endl;
+  for (int k=0; k< fdata_.size(); k++)
+    {
+      cout << fdata_[k] << " " ;
+    } 
+  cout << endl;
+
+  cout << " entiers courts: " << endl;
+  for (int k=0; k< shdata_.size(); k++)
+    {
+      cout << shdata_[k] << " " ;
+    } 
+  cout << endl;
+  cout << " entiers : " << endl;
+  for (int k=0; k< idata_.size(); k++)
+    {
+      cout << idata_[k] << " " ;
+    } 
+  cout << endl;
+
+  cout << " entiers longs : " << endl;
+  for (int k=0; k< ldata_.size(); k++)
+    {
+      cout << ldata_[k] << " " ;
+    } 
+  cout << endl;
+
+  cout << " chaines carac.  : " << endl;
+  for (int k=0; k< cdata_.size(); k++)
+    {
+      cout << cdata_[k] << " " ;
+    } 
+  cout << endl;
+
+  cout << " bytes : " << endl;
+  for (int k=0; k< bdata_.size(); k++)
+    {
+      cout << (char)bdata_[k] << " " ;
+    } 
+  cout << endl;
+
+
+}
 
 /*!
@@ -601,4 +729,6 @@
 	  // printerror( status,":FitsInFile::getHeader : erreur movabs");
 	}
+	
+
       if(hdutype == IMAGE_HDU) 
 	{
@@ -627,4 +757,9 @@
 	  KeywordsIntoDVList(fptr_, dvl_, hdunum_);
 	}
+
+    }
+  if (hdutype_ == FitsExtensionType_BINARY_TBL || hdutype_ == FitsExtensionType_ASCII_TBL)
+    {
+      bfl_ = BufferLine(types_);
     }
 }
@@ -736,4 +871,71 @@
     }
   return  taille_des_chaines_[index];
+}
+
+const FitsFile::BufferLine&   FitsInFile::GetBufferLine(long NoLine) 
+{
+  int status= 0;
+  int    anynul;
+  double dnull= dnull_;
+  float fnull= fnull_;
+  int inull= inull_;
+  char* cnull=  const_cast<char*>(cnull_.c_str());
+  int ncol;
+  long nels=1;
+  double dval;
+  float  fval;
+  int    ival;
+
+  // pas d'entier de longueur superieure a 32 bits, pour cfitsio
+  int    lval;
+
+  unsigned char usval; 
+  int rang = 0;
+  int ccount = 0;
+  for (ncol=0; ncol<nbcols_; ncol++)
+    {
+      rang =  bfl_.identificateur()[ncol].second;
+      //      cout << " fitsfile : relecture col " << ncol << " type " << bfl_.identificateur()[ncol].first << " rang " << rang << endl; 
+      switch (bfl_.identificateur()[ncol].first)
+	{ 
+	case FitsDataType_double :
+	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull, &dval,&anynul,&status);
+	  bfl_.r_8Array(rang) = (r_8)dval;
+	  break;
+	case FitsDataType_float :
+	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fval,&anynul,&status);
+	  bfl_.r_4Array(rang)  = (r_4)fval;
+	  break;
+	case FitsDataType_short :
+	  fits_read_col(fptr_,TSHORT,ncol+1,NoLine+1,1,1,&inull,&ival, &anynul,&status);
+	  bfl_.int_2Array(rang) = (int_2)ival;
+	  break;
+	case FitsDataType_int :
+	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ival, &anynul,&status);
+	  bfl_.int_4Array(rang) = (int_4)ival;
+	  break;
+	case FitsDataType_long :
+	  fits_read_col(fptr_,TLONG,ncol+1,NoLine+1,1,1,&inull,&lval, &anynul,&status);
+	  bfl_.int_8Array(rang) = (int_8)lval;
+	  break;
+	case FitsDataType_byte :
+	  fits_read_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1,&inull, &usval, &anynul,&status);
+	  bfl_.u_charArray(rang) = usval;
+	  break;
+	case FitsDataType_char :
+	  char* chaine = new char[taille_des_chaines_[ccount++]];
+	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anynul,&status);
+	  bfl_.stringArray(rang) = string(chaine);
+	  break;
+	}
+      if (status)
+	{
+	  ResetStatus(status);
+	  break;
+	}
+    }
+  //  cout << " fitsfile : ligne relue " << endl;
+  //  bfl_.Print();
+  return bfl_;
 }
 
@@ -778,14 +980,20 @@
 	    break;
 	  }
-	case FitsDataType_float :	  
-	  fits_read_col(fptr_,TFLOAT,ncol+1,ligneALire,premierElement,1,&fnull,&fdata[fcount++],&anynul,&status);
-	  break;
+	case FitsDataType_float :
+	  {	  
+	    fits_read_col(fptr_,TFLOAT,ncol+1,ligneALire,premierElement,1,&fnull,&fdata[fcount++],&anynul,&status);
+	    break;
+	  }
 	case  FitsDataType_int :
-	  fits_read_col(fptr_,TINT,ncol+1,ligneALire,premierElement,1,&inull,&idata[icount++],
+	  {
+	    fits_read_col(fptr_,TINT,ncol+1,ligneALire,premierElement,1,&inull,&idata[icount++],
 			&anynul,&status);
-	  break;
+	    break;
+	  }
 	case  FitsDataType_long :
-	  fits_read_col(fptr_,TLONG,ncol+1,ligneALire,premierElement,1,&inull,&idata[icount++], &anynul,&status);
-          break;
+	  {
+	    fits_read_col(fptr_,TLONG,ncol+1,ligneALire,premierElement,1,&inull,&idata[icount++], &anynul,&status);
+	    break;
+	  }
 	case  FitsDataType_byte :
 	  {
@@ -793,9 +1001,15 @@
 	    fits_read_col(fptr_,TBYTE,ncol+1,ligneALire,premierElement,1,&inull,&uschar, &anynul,&status);
 	    idata[icount++] = (int)uschar;
-	  }
-	  break;
+	    break;
+	  }
 	case FitsDataType_char :
-	  fits_read_col(fptr_,TSTRING,ncol+1,ligneALire,premierElement,1,cnull,&cdata[ccount++],&anynul,&status);
-	  break;
+	  {
+	    fits_read_col(fptr_,TSTRING,ncol+1,ligneALire,premierElement,1,cnull,&cdata[ccount++],&anynul,&status);
+	    break;
+	  }
+	default:
+	  {
+	    throw PException(" FitsInFile::GetBinTabLine : unsupported FITS data type");
+	  }
 	}
       if (status)
@@ -829,23 +1043,39 @@
 	{ 
 	case FitsDataType_double :
-	  fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anynul,&status);
-	  break;
+	  {
+	    fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anynul,&status);
+	    break;
+	  }
 	case FitsDataType_float :
-	  fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anynul,&status);
-	  break;
+	  {
+	    fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anynul,&status);
+	    break;
+	  }
 	case FitsDataType_int :
-	  fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++], &anynul,&status);
-	  break;
+	  {
+	    fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++], &anynul,&status);
+	    break;
+	  }
 	case FitsDataType_long :
-	  fits_read_col(fptr_,TLONG,ncol+1,NoLine+1,1,1,&inull,&ligne.ldata_[icount++], &anynul,&status);
-	  break;
+	  {
+	    fits_read_col(fptr_,TLONG,ncol+1,NoLine+1,1,1,&inull,&ligne.ldata_[icount++], &anynul,&status);
+	    break;
+	  }
 	case FitsDataType_byte :
-	  fits_read_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1,&inull,&ligne.bdata_[icount++], &anynul,&status);
-	  break;
+	  {
+	    fits_read_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1,&inull,&ligne.bdata_[icount++], &anynul,&status);
+	    break;
+	  }
 	case FitsDataType_char :
-	  char* chaine = new char[taille_des_chaines_[ccount]];
-	  fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anynul,&status);
-	  ligne.cdata_[ccount++] = string(chaine);
-	  break;
+	  {
+	    char* chaine = new char[taille_des_chaines_[ccount]];
+	    fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anynul,&status);
+	    ligne.cdata_[ccount++] = string(chaine);
+	    break;
+	  }
+	default:
+	  {
+	    throw PException(" FitsInFile::GetBinTabLine : unsupported FITS data type");
+	  }
 	}
       if (status)
@@ -856,4 +1086,6 @@
     }
 }
+
+
 
 /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata)
@@ -945,5 +1177,4 @@
       long repeat,width;
       fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
-      cout << " en lecture fits trouve le type " << DTYPE << endl;
       if( DTYPE != TLONG &&  DTYPE != TINT) 
 	{
@@ -1137,41 +1368,4 @@
   int rept=0;
   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_long);
-	      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++)
@@ -1199,5 +1393,45 @@
 	      break;
 	    case TSHORT :
+	      types.push_back(FitsDataType_short);
+	      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_long);
+	      break;
+	    case TINT :
 	      types.push_back(FitsDataType_int);
+	      break;
+	    case TSHORT :
+	      types.push_back(FitsDataType_short);
 	      break;
 	    case TSTRING :
@@ -1718,18 +1952,13 @@
     
 
-// la logique voudrait qu'on distingue TLONG et TINT. Mais si j'ecris 
-// et relis immediatement quelque chose en TLONG l'experience montre 
-// que ca foire. Donc, je fais tout en TINT, d'ailleurs cfitsio n'a pas
-// (apparemment) d'entiers de longueur superieure a 32 bits.
-// En fait, je n'y comprend rien. A suivre (GLM).
-  if (code == TINT || code == TLONG )
-    {
-      cout << " j'ecris des TINT" << endl;
+  
+  if (code == TINT || code == TLONG)
+    {
+      // cfitsio n'a que des entiers de longueur inferieure a 32 bits.
+      // ici, a l'ecriture TLONG impliquerait que le tableau de donnees
+      // soit un tableau int_8. Donc c'est toujours TINT qu;il faut mettre
+      // De plus, j'ai l'impression que TINT va devenir obsolete dans cfitsio
+      // (GLM)
       fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
-    }
-  else if (code == TSHORT) 
-    {
-      cout << " j'ecris des TSHORT " << endl;
-      fits_write_col(fptr_,TSHORT,nocol+1,1,1,nentries, donnees ,&status);
     }
   else
@@ -2211,4 +2440,5 @@
 	{
 	  cout << "FitsKeyword : complex keyword value not supported" << endl;;
+	  break;
 	}
       default :
