Index: trunk/SophyaExt/FitsIOServer/swfitsdtable.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/swfitsdtable.cc	(revision 2865)
+++ trunk/SophyaExt/FitsIOServer/swfitsdtable.cc	(revision 2889)
@@ -1,3 +1,4 @@
 #include "swfitsdtable.h"
+#include "fitshdtable.h"
 #include "sopnamsp.h"
 #include "pexceptions.h"
@@ -19,4 +20,7 @@
    - It is not possible to make a complete (deep) copy of a SwFitsDataTable
    Copy constructor and equal operator shares the data.
+   - The min/max values for column data are not updated when reading from a fits file.
+   In this case, the Show() method (or ostream& << operator) will compute min/max 
+   values. This operation will take some time for large tables.
 
    \sa SOPHYA::MuTyV
@@ -26,11 +30,11 @@
 
    \code
-   #include "swppfdtable.h"
+   #include "swfitsdtable.h"
    // ...
    {
    // ---- Creation of the table
    // Create the swap stream 
-   POutPersist so("myswtable.ppf");
-   SwFitsDataTable dt(so, 64);
+   FitsInOutFile so("myswtable.fits", FitsInOutFile::Fits_Create);
+   SwFitsDataTable dt(so, 16);
    // define table columns
    dt.AddFloatColumn("X0_f");
@@ -38,5 +42,5 @@
    dt.AddDoubleColumn("X0X0pX1X1_d");
    // Fill the table
-   MuTyV x[5];
+   r_8 x[5];
    for(int i=0; i<63; i++) {
      x[0] = (i%9)-4.;  x[1] = (i/9)-3.;  x[2] = x[0]*x[0]+x[1]*x[1];
@@ -45,14 +49,15 @@
    // Printing table info
    cout << dt ;
-   // Swap out all data and write the table structure to the PPF stream 
-   so << dt ;
-   // ....
+   // The destructor will Swap out  data still in memory 
    }
    {
    // ---- Accessing information from a previously created table
    SwFitsDataTable dt;
-   PInPersist si("myswtable.ppf");
+   FitsInOutFile si("myswtable.fits", FitsInOutFile::Fits_ReadOnly);
+   // Position the fits file on the first extension (BinTable)
+   si.MoveAbsToHDU(2);  
+   // Reading in the table (initialisation) 
    si >> dt;
-   // Printing table info
+   // Printing table info 
    cout << dt ;   
    }
@@ -72,4 +77,8 @@
     mSwF(os) , mFgCreate(fgcreate)
 {
+  if (!fgcreate) {   // Lecture de la table 
+    FitsHandler<BaseDataTable> fio(*this);
+    fio.Read(os);
+  }
 }
 //! copy constructor - shares the data
@@ -83,5 +92,13 @@
 SwFitsDataTable::~SwFitsDataTable()
 {
-  if (mFgCreate) SwapOutAll();
+  if (mFgCreate) { 
+    SwapOutAll();
+    // Ecriture de SegmentSize et autre elements de DVList  
+    mSwF.WriteHeaderRecords(Info());
+    MuTyV mtv = SegmentSize();
+    mSwF.WriteKey("SEGMSIZE",mtv," SOPHYA::DataTable SegmentSize");
+    mtv = "SOPHYA::SwFitsDataTable";
+    mSwF.WriteKey("SOPCLSNM",mtv," Object class name "); 
+  }
 }
 
@@ -213,13 +230,4 @@
   mSCols.clear();
 
-  /*
-  mISwapper.clear();
-  mLSwapper.clear();
-  mFSwapper.clear();
-  mDSwapper.clear();
-  mYSwapper.clear();
-  mZSwapper.clear();
-  mSSwapper.clear();
-  */
 }
 
@@ -232,5 +240,5 @@
 sa_size_t SwFitsDataTable::AddColumn(FieldType ft, string const & cnom)
 {
-  return AddColRd(ft, cnom, NULL);
+  return AddColRd(ft, cnom, -1, NULL);
 }
 /*! 
@@ -240,5 +248,5 @@
 */
 sa_size_t SwFitsDataTable::AddColRd(FieldType ft, string const & cnom, 
-				    vector<int_8> const * swpos)
+				    int colidx, vector<int_8> const * swpos)
 {
   if (NEntry() > 0) 
@@ -247,9 +255,11 @@
   sa_size_t ser; 
   sa_size_t idx = NVar(); 
+  if (colidx < 1) colidx = idx+1; 
+
   switch (ft) {
   case IntegerField :
   {
     ser = mICols.size();
-    FITSDataSwapper<int_4> ISwapper(mSwF, idx+1);
+    FITSDataSwapper<int_4> ISwapper(mSwF, colidx);
     if (swpos)
       mICols.push_back(SwSegDataBlock<int_4>(ISwapper, *swpos, mSegSz));
@@ -265,5 +275,5 @@
   {
     ser = mLCols.size();
-    FITSDataSwapper<int_8> LSwapper(mSwF, idx+1);
+    FITSDataSwapper<int_8> LSwapper(mSwF, colidx);
     if (swpos)    
       mLCols.push_back(SwSegDataBlock<int_8>(LSwapper, *swpos, mSegSz));
@@ -279,5 +289,5 @@
   {
     ser = mFCols.size();
-    FITSDataSwapper<r_4> FSwapper(mSwF, idx+1);
+    FITSDataSwapper<r_4> FSwapper(mSwF, colidx);
     if (swpos)    
       mFCols.push_back(SwSegDataBlock<r_4>(FSwapper, *swpos, mSegSz));
@@ -294,5 +304,5 @@
   {
     ser = mDCols.size();
-    FITSDataSwapper<r_8> DSwapper(mSwF, idx+1);
+    FITSDataSwapper<r_8> DSwapper(mSwF, colidx);
     if (swpos)    
       mDCols.push_back(SwSegDataBlock<r_8>(DSwapper, *swpos, mSegSz));
@@ -308,5 +318,5 @@
   {
     ser = mYCols.size();
-    FITSDataSwapper< complex<r_4> > YSwapper(mSwF, idx+1);
+    FITSDataSwapper< complex<r_4> > YSwapper(mSwF, colidx);
     if (swpos)    
       mYCols.push_back(SwSegDataBlock< complex<r_4> >(YSwapper, *swpos, mSegSz));
@@ -322,5 +332,5 @@
   {
     ser = mZCols.size();
-    FITSDataSwapper< complex<r_8> > ZSwapper(mSwF, idx+1);
+    FITSDataSwapper< complex<r_8> > ZSwapper(mSwF, colidx);
     if (swpos)    
       mZCols.push_back(SwSegDataBlock< complex<r_8> >(ZSwapper, *swpos, mSegSz));
@@ -336,5 +346,5 @@
   {
     ser = mSCols.size();
-    FITSDataSwapper< string > SSwapper(mSwF, idx+1);
+    FITSDataSwapper< string > SSwapper(mSwF, colidx);
     if (swpos)    
       mSCols.push_back(SwSegDataBlock< string >(SSwapper, *swpos, mSegSz));
@@ -368,8 +378,12 @@
 /*! 
   The min/max values for each column is updated, in addition 
-  to the actions performed by the base class AddLine()
-*/
-sa_size_t SwFitsDataTable::AddLine(const r_8* data)
-{
+  to the actions performed by the base class AddRow()
+*/
+sa_size_t SwFitsDataTable::AddRow(const r_8* data)
+{
+  if (NRows() == 0) {  // On cree la definition de la table FITS au premier appel
+    FitsHandler<BaseDataTable> fio(*this);
+    fio.Write(mSwF);
+  }
   // On est oblige de calculer les min-max lors du remplissage
   // On ne peut pas en effet 'relire' le swap pendant l'ecriture
@@ -380,14 +394,18 @@
     mMinMaxNEnt[k]++;
   }
-  return BaseDataTable::AddLine(data);
-}
-
-//! Adds a line (or row to the table) with input data as an array of MuTyV
+  return BaseDataTable::AddRow(data);
+}
+
+//! Adds a row (or line to the table) with input data as an array of MuTyV
 /*! 
   The min/max values for each column is updated, in addition 
-  to the actions performed by the base class AddLine()
-*/
-sa_size_t SwFitsDataTable::AddLine(const MuTyV * data)
-{
+  to the actions performed by the base class AddRow()
+*/
+sa_size_t SwFitsDataTable::AddRow(const MuTyV * data)
+{
+  if (NRows() == 0) {  // On cree la definition de la table FITS au premier appel
+    FitsHandler<BaseDataTable> fio(*this);
+    fio.Write(mSwF);
+  }
   // On est oblige de calculer les min-max lors du remplissage
   // On ne peut pas en effet 'relire' le swap pendant l'ecriture
@@ -398,5 +416,5 @@
     mMinMaxNEnt[k]++;
   }
-  return BaseDataTable::AddLine(data);
-}
-
+  return BaseDataTable::AddRow(data);
+}
+
