Index: trunk/SophyaExt/FitsIOServer/fitsfile.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1209)
+++ trunk/SophyaExt/FitsIOServer/fitsfile.cc	(revision 1218)
@@ -8,4 +8,89 @@
 
 
+void BnTblLine::setFormat(int dc, int fc, int ic, int cc, vector<string> names)
+   {
+    int nbcols = dc + fc + ic + cc;
+    int maxName = names.size();
+    if (nbcols != maxName)
+      {
+	cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl;
+	maxName = nbcols < maxName ? nbcols : maxName;
+      }
+    ColName_ = vector<string>(nbcols);
+     for (int k=0; k < maxName; k++) ColName_[k] = names[k];
+    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);
+   }
+
+bool BnTblLine::sameFormat(const BnTblLine& btl) const
+   {
+     if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size()) return true;
+     else return false;
+   }
+
+void BnTblLine::Print()
+   {
+     int k;
+     cout << " ********* ligne ************* " << endl;
+     cout << " *** noms de variables  " << endl;
+     for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " ";
+     cout << endl;
+     cout << " *** variables doubles  " << endl;
+     for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " ";
+     cout << endl;
+     cout << " *** variables float  " << endl;
+     for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " ";
+     cout << endl;
+     cout << " *** variables int  " << endl;
+     for (k=0; k < idata_.size(); k++) cout << idata_[k] << " ";
+     cout << endl;
+     cout << " *** variables string  " << endl;
+     for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " ";
+     cout << endl;
+     cout << " ***************************** " << endl;
+   }
+
+
+
+/*!
+  \class SOPHYA::FitsIOHandler
+The class structure is analogous to Sophya-PPersist system :
+Each SOPHYA object XXX is associated with a object of class FITS_XXX 
+ (inheriting from FitsFileHandler), to which input/output operations with FITS 
+ files are delegated (through a class Hierarchy : FitsFile (virtual), 
+ FitsInFile, FitsOutFile) . A typical example of use is the following : 
+
+\verbatim
+  int m=... ;
+  SphereHEALPix<r_8> sphere1(m);           // definition of the SOPHYA object
+  .... fill the sphere ....
+
+  FITS_SphereHEALPix<r_8> fits_sph1(sphere1); 
+                                           // delegated object
+  fits_sph.Write("myfile.fits");           // writing on FITS file
+
+   FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits"); 
+                                           // load a delegated object 
+                                           // from FITS file
+   SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2; 
+                                           // casting the delegated object
+                                           // into a SOPHYA object
+\endverbatim
+  
+
+*/
+
+/*! \fn void  SOPHYA::FitsIOHandler::Read(char flnm[],int hdunum)
+
+this method is called from inherited objects : 
+
+opens a file 'flnm' 
+
+gets parameters in extension-header (hdunum)
+
+calls the method 'ReadFromFits' from the inherited  object
+*/ 
 void   FitsIOHandler::Read(char flnm[],int hdunum)
 {
@@ -13,4 +98,8 @@
   Read(ifts, hdunum);
 }
+
+  /*! \fn void SOPHYA::FitsIOHandler::Read(FitsInFile& is, int hdunum)
+Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. If hdunum is not addressed, , one reads the next extension, with respect to the current position. 
+   */
 void FitsIOHandler::Read(FitsInFile& is, int hdunum) 
 {
@@ -21,4 +110,20 @@
 
 
+/*! \fn void SOPHYA::FitsIOHandler::Write(char flnm[])
+this method is called from inherited objects. 
+
+for writing a new object in a new fits-extension :
+
+\warning By convention, primary header does not contain fits-image data : i.e. 
+all data are fits-extensions. The first relevant header will have hdunum=2.
+For switching off this convention use the method : 
+
+firstImageOnPrimaryHeader() (see below)
+
+In that case do not forget to precise hdunum=1 when reading data on primary header.
+
+calls the method 'WriteToFits' from the inherited  object
+
+*/ 
 void FitsIOHandler::Write(char flnm[]) 
 
@@ -33,4 +138,9 @@
 }
 
+
+/*!
+  \class SOPHYA::FitsIOHandler
+Class (virtual) for managing FITS format files
+*/
 
 
@@ -87,9 +197,15 @@
 }
 
+/*!
+  \class SOPHYA::FitsInFile
+
+class for saving  SOPHYA objects on FITS Format Files (uses cfitsio lib)
+*/
+
 FitsInFile::FitsInFile()
 {
   InitNull();
 }
-//FitsInFile::FitsInFile(char flnm[], int hdunum)
+
 FitsInFile::FitsInFile(char flnm[])
 {
@@ -118,4 +234,7 @@
 }
 
+//////////////////////////////////////////////////////////
+//     methods with general purpose
+/////////////////////////////////////////////////////////
 
 int FitsInFile::NbBlocks(char flnm[])
@@ -200,4 +319,48 @@
 }
 
+
+void FitsInFile::ReadFInit(int hdunum) 
+{
+   InitNull();
+  // int status = 0;
+  
+  //  fits_open_file(&fptr_,flnm,READONLY,&status);
+  //  if( status ) printerror( status );
+
+  int status = 0;
+
+  if (hdunum <= 1) 
+    {
+      hdunum_ = 1; 
+      // presence of image ?
+      int naxis= 0;
+      fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
+      if( status ) printerror( status );
+      if (naxis > 0 )       // there is an image
+	{
+	  hdutype_ = IMAGE_HDU;
+	  GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
+	  nbData_ =  1;
+	  int k;
+	  for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
+	  KeywordsIntoDVList(fptr_, dvl_,hdunum_);
+	}
+      else
+	{
+	  throw PException(" first header : no image, probably error in hdunum");
+	}
+  //
+    }
+  else 
+    {
+      hdunum_ = hdunum-1; 
+      int hdutype;
+      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
+      if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
+      moveToFollowingHeader();
+    }
+}
+
+
 void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
 {
@@ -230,46 +393,11 @@
 
 
-void FitsInFile::ReadFInit(int hdunum) 
-{
-   InitNull();
-  // int status = 0;
-  
-  //  fits_open_file(&fptr_,flnm,READONLY,&status);
-  //  if( status ) printerror( status );
-
-  int status = 0;
-
-  if (hdunum <= 1) 
-    {
-      hdunum_ = 1; 
-      // presence of image ?
-      int naxis= 0;
-      fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
-      if( status ) printerror( status );
-      if (naxis > 0 )       // there is an image
-	{
-	  hdutype_ = IMAGE_HDU;
-	  GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
-	  nbData_ =  1;
-	  int k;
-	  for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
-	  KeywordsIntoDVList(fptr_, dvl_,hdunum_);
-	}
-      else
-	{
-	  throw PException(" first header : no image, probably error in hdunum");
-	}
-  //
-    }
-  else 
-    {
-      hdunum_ = hdunum-1; 
-      int hdutype;
-      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
-      if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
-      moveToFollowingHeader();
-    }
-}
-
+
+
+  /*! \fn DVList SOPHYA::FitsInFile::DVListFromPrimaryHeader() const
+
+   \return the keywords of primary header in a DVList 
+
+*/
 DVList  FitsInFile::DVListFromPrimaryHeader() const
    {
@@ -308,4 +436,10 @@
 
 
+
+
+
+/*! \fn int  SOPHYA::FitsInFile::NbColsFromFits() const
+\return number of columns (return 1 if IMAGE) 
+*/
 int  FitsInFile::NbColsFromFits() const
 {
@@ -320,4 +454,8 @@
 }
 
+/*! \fn  int SOPHYA::FitsInFile::NentriesFromFits(int nocol) const
+\return number of data in the current IMAGE extension on FITS file, or number
+ of data of column number 'nocol' of the current BINTABLE extension
+*/
 int FitsInFile::NentriesFromFits(int nocol) const
 {
@@ -334,4 +472,18 @@
 }
 
+/*! \fn char SOPHYA::FitsInFile::ColTypeFromFits(int nocol) const
+
+return a character denoting data type of column number 'nocol' in a BINTABLE :
+
+D : double
+
+E : float 
+
+I : integer
+    
+S : character string 
+
+  */
+
 char FitsInFile::ColTypeFromFits(int nocol) const
 {
@@ -342,4 +494,11 @@
   return types_[nocol];
 }
+
+
+/*! \fn string SOPHYA::FitsInFile::ColNameFromFits(int nocol) const
+
+\return name of the column number 'nocol' of the current BINTABLE extension
+   */
+
 string FitsInFile::ColNameFromFits(int nocol) const
 {
@@ -350,4 +509,9 @@
   return noms_[nocol];
 }
+
+/*! \fn int DSOPHYA::FitsInFile::ColStringLengthFromFits(int nocol) const
+
+ \return number of characters of each data  for the column number 'nocol' (if char* typed) of the current BINTABLE extension
+*/
 
 int FitsInFile::ColStringLengthFromFits(int nocol) const
@@ -365,4 +529,12 @@
   return  taille_des_chaines_[index];
 }
+
+
+
+/*! \fn void  SOPHYA::FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
+
+Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
+  */
+
 void  FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 
 {
@@ -405,4 +577,7 @@
 }
 
+/*! \fn void   SOPHYA::FitsInFile::GetBinTabLine(long NoLine,  BnTblLine& ligne)
+Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
+*/
 void   FitsInFile::GetBinTabLine(long NoLine,  BnTblLine& ligne) 
 {
@@ -447,4 +622,8 @@
 }
 
+/*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata)
+
+Get the NoLine-th float 'line'  from the current BINTABLE extension on FITS file,
+*/
 void FitsInFile::GetBinTabLine(int NoLine, float* fdata) 
 {
@@ -466,4 +645,10 @@
 
 
+/*! \fn void SPOPHYA::FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
+
+fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
+
+\param <nentries>  number of data to be read
+*/
 void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
     {
@@ -499,4 +684,8 @@
     }
 
+/*! \fn  void SOPHYA::FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
+
+ same as previous method with float data 
+*/
 void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
     {
@@ -531,4 +720,9 @@
     }
 
+/*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
+
+ same as previous method with int data 
+*/
+
 void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
     {
@@ -561,4 +755,9 @@
     }
 
+/*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
+
+ same as previous method with char* data 
+*/
+
 void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
     {
@@ -587,4 +786,10 @@
     }
 
+/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(double* map, int nentries) const
+fill the array 'map' with double data from the current extension on FITS file.
+If the extension is BINTABLE, the first column is provided. 
+
+\param <nentries>  number of data to be read
+*/
 void FitsInFile::GetSingleColumn(double* map, int nentries) const
 { 
@@ -619,4 +824,7 @@
 }
 
+/*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
+same as above with float data 
+*/
 void FitsInFile::GetSingleColumn(float* map, int nentries) const
 {
@@ -649,4 +857,7 @@
 }
 
+/*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
+ same as above with int data 
+*/
 void FitsInFile::GetSingleColumn( int* map, int nentries) const
 {
@@ -866,4 +1077,10 @@
 } 
 
+
+/*!
+  \class SOPHYA::FitsOutFile
+ Class for loading  SOPHYA objects from FITS Format Files (uses cfitsio lib)
+*/
+
 FitsOutFile::FitsOutFile()
 {
@@ -871,4 +1088,9 @@
 }
 
+   /*! \fn SOPHYA::FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
+
+\param <WriteMode>  enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default)
+
+   */
 FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
 {
@@ -929,4 +1151,11 @@
 
 
+/*! \fn void SOPHYA::FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl) 
+
+create an IMAGE header on FITS file.
+\param <type> type of data (see method ColTypeFromFits)
+\param <nbdim>  number of dimensions : 1D, 2D, 3D etc. = NAXIS
+\param <naxisn>  array containind sizes of the different dimensions
+*/
 void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn,  DVList &dvl) 
 {
@@ -968,4 +1197,11 @@
 
 }
+
+
+/*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, double* map) const
+
+write double data from array 'map'on an IMAGE extension 
+\param <nbData>  number of data to be written
+*/
 void FitsOutFile::PutImageToFits(int nbData, double* map) const
 {
@@ -977,4 +1213,8 @@
 }
 
+/*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, float* map) const
+
+same as previous method with float data 
+*/
 void FitsOutFile::PutImageToFits(int nbData, float* map) const
 {
@@ -986,4 +1226,8 @@
 
 }
+
+  /*! \fn void SOPHYA::FitsOutFile::PutImageToFits( int nbData, int* map) const
+
+ same as previous method with int data */
 void FitsOutFile::PutImageToFits( int nbData, int* map) const
 {
@@ -998,4 +1242,16 @@
 
 
+/*! \fn void SOPHYA::FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
+
+create an BINTABLE header on FITS file.
+\param <fieldType> array conta
+ining characters denoting types of the different column (see method ColTypeFromFits)
+\param <Noms>  array of the names of columns
+\param <nentries>  number of data of each column
+\param <tfields> number of columns
+\param <dvl> a SOPHYA DVList containing keywords to be appended
+\param <extname> keyword EXTNAME for FITS file
+\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 &dvl, string extname, vector<int> taille_des_chaines) 
 { 
@@ -1092,4 +1348,9 @@
 }
 
+/*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
+
+write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
+\param <nentries>  number of data to be written
+*/
 void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
 {
@@ -1114,4 +1375,11 @@
   if( status )  printerror( status,"erreur ecriture du fichier fits" );
 }
+
+
+
+  /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
+
+same as previous method with float data 
+*/
 void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
 {
@@ -1140,4 +1408,10 @@
   if( status )  printerror( status,"erreur ecriture du fichier fits" );
 }
+
+
+/*! \fn void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
+
+same as previous method with int data 
+*/
 void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
 {
@@ -1166,4 +1440,9 @@
   if( status )  printerror( status," ecriture du fichier fits" );
 }
+
+
+/*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
+same as previous method with char* data 
+*/
 void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
 {
@@ -1228,4 +1507,8 @@
 
 
+/* \fn void  SOPHYA::FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
+
+Put keywords from a DVList into the primary header of the fits-file 
+*/
 void  FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
 {
