Index: trunk/SophyaExt/FitsIOServer/fitsswapper.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsswapper.cc	(revision 2846)
+++ trunk/SophyaExt/FitsIOServer/fitsswapper.cc	(revision 2857)
@@ -4,126 +4,4 @@
 #include <iostream>
 
-
-template <class T> 
-FITSDataSwapper<T>::FITSDataSwapper()
-{
-  SetInStream(NULL, 0); 
-  SetOutStream(NULL, 0);
-}
-
-template <class T> 
-FITSDataSwapper<T>::FITSDataSwapper(fitsfile * is, int coli, fitsfile * os, int colo)
-{
-  SetInStream(is, coli);
-  if (os == NULL) SetOutStream(is, coli);
-  else 	SetOutStream(os, colo);
-}
-
-template <class T> 
-void FITSDataSwapper<T>::SetInStream(fitsfile * is, int col)
-{
-  fitsis = is;
-  colis = col;
-  hduis = 0;
-  int status=0, hdutype=0;
-  if (is != NULL)  { 
-    if ( fits_get_hdu_num(fitsis, &hduis) <= 0) 
-      throw IOExc("FITSDataSwapper<T>::SetInStream() fits_get_hdu_num Error");
-    if (fits_get_hdu_type(fitsis, &hdutype, &status)) {
-      fits_report_error(stdout,status); fflush(stdout);
-      throw IOExc("FITSDataSwapper<T>::SetInStream()  fits_get_hdu_type Error");
-    }
-    //    cout << "DBG-SetInStream() :  hduis= " << hduis 
-    //	 << " hdutype=" << hdutype << " BINARY_TBL= " << BINARY_TBL << endl;
-    if ( (hdutype != ASCII_TBL) && (hdutype != BINARY_TBL) )
-      throw IOExc("FITSDataSwapper<T>::SetInStream() current HDU not of BINARY_TBL or ASCII_TBL type");
-  }
-}
-
-template <class T> 
-void FITSDataSwapper<T>::SetOutStream(fitsfile * os, int col)
-{
-  fitsos = os;
-  colos = col;
-  hduos = 0;
-  rowos = 0;
-  int status=0, hdutype=0;
-  if (os != NULL)  { 
-    if ( fits_get_hdu_num(fitsos, &hduos) <= 0 ) 
-      throw IOExc("FITSDataSwapper<T>::SetOutStream() fits_get_hdu_num Error");
-    if (fits_get_hdu_type(fitsos, &hdutype, &status)) {
-      fits_report_error(stdout,status); fflush(stdout);
-      throw IOExc("FITSDataSwapper<T>::SetOutStream()  fits_get_hdu_type Error");
-    }
-    //    cout << "DBG-SetOutStream() :  hduos= " << hduos 
-    //	 << " hdutype=" << hdutype << " BINARY_TBL= " << BINARY_TBL << endl;
-    if ( (hdutype != ASCII_TBL) && (hdutype != BINARY_TBL) )
-      throw IOExc("FITSDataSwapper<T>::SetOutStream() current HDU not of BINARY_TBL or ASCII_TBL type");
-  }
-}
-
-template <class T> 
-FITSDataSwapper<T>& FITSDataSwapper<T>::operator = (FITSDataSwapper<T> const & a)
-{
-  fitsos = a.fitsos;
-  colos = a.colos;
-  hduos = a.hduos;
-  rowos = a.rowos;
-  fitsis = a.fitsis;
-  colis = a.colis;
-  hduis = a.hduis;
-  return *this;
-}
-
-
-static inline int _ConvertToFitsDataType(const r_8 * d) { return TDOUBLE; }
-static inline int _ConvertToFitsDataType(const r_4 * d) { return TFLOAT; }
-static inline int _ConvertToFitsDataType(const uint_2 * d) { return TUSHORT; }
-static inline int _ConvertToFitsDataType(const int_2 * d) { return TSHORT; }
-static inline int _ConvertToFitsDataType(const int_4 * d) { return (sizeof(long)==4) ? TLONG: TINT; }
-#ifdef TLONGLONG
-static inline int _ConvertToFitsDataType(const int_8 * d) { return TLONGLONG; }
-#else
-static inline int _ConvertToFitsDataType(const int_8 * d) { throw NotAvailableOperation("FITSDataSwapper<int_8> ; Unsupported data type ")}
-#endif
-
-template <class T> 
-int_8 FITSDataSwapper<T>::WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp, bool osw)
-{
-  if (fitsos == NULL) throw IOExc("FITSDataSwapper<T>::WriteToSwap() null output stream pointer (fitsos)" );
-  int hdutype=0, status=0;
-  if(fits_movabs_hdu(fitsos,hduos,&hdutype,&status)) {
-    fits_report_error(stdout,status); fflush(stdout);
-    throw IOExc("FITSDataSwapper<T>::WriteToSwap() fits_movabs_hdu  Error");
-  }
-  int ftype = _ConvertToFitsDataType(d);
-  long row;
-  if (osw)  row = oswp;
-  else row = rowos;  
-  T * ncd = const_cast<T *>(d);
-  if( fits_write_col(fitsos, ftype, colos+1, row+1, 1, sz, ncd, &status) ) {
-    fits_report_error(stdout,status); fflush(stdout);
-    throw IOExc("FITSDataSwapper<T>::WriteToSwap()  fits_write_col  Error");
-  }
-  if (!osw)  rowos += sz;  // On met a jour la position d'ecriture courante si pas de reecriture
-  return row;
-}
-
-template <class T> 
-void FITSDataSwapper<T>::ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)
-{
-  if (fitsis == NULL) throw IOExc("FITSDataSwapper<T>::ReadFromSwap() null input stream pointer (fitsis)" );
-  int hdutype=0, status=0;
-  if(fits_movabs_hdu(fitsis,hduos,&hdutype,&status)) {
-      fits_report_error(stdout,status); fflush(stdout);
-      throw IOExc("FITSDataSwapper<T>::ReadFromSwap() fits_movabs_hdu  Error");
-  }
-  int ftype = _ConvertToFitsDataType(d);
-  if( fits_read_col(fitsis, ftype, colis+1, swp+1, 1, sz, NULL, d, NULL, &status) ) {
-    fits_report_error(stdout,status); fflush(stdout);
-    throw IOExc("FITSDataSwapper<T>::ReadFromSwap()  fits_read_col  Error");
-  }
-  return;
-}
 
 
Index: trunk/SophyaExt/FitsIOServer/fitsswapper.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fitsswapper.h	(revision 2846)
+++ trunk/SophyaExt/FitsIOServer/fitsswapper.h	(revision 2857)
@@ -9,5 +9,6 @@
 #include "machdefs.h"
 #include "swsegdb.h"
-#include "FitsIO/fitsio.h"
+#include "fitsinoutfile.h"
+#include "fitsblkrw.h"
 
 namespace SOPHYA {
@@ -15,6 +16,6 @@
   \class SOPHYA::FITSDataSwapper
   \ingroup FitsIOServer
-  Implementation of SOPHYA::DataSwapperInterface interface on FITS streams 
-  (fitsfile *) to be used with SOPHYA::SwSegDataBlock classes.
+  Implementation of SOPHYA::DataSwapperInterface interface on FITS files
+  (FitsInOutFile) to be used with SOPHYA::SwSegDataBlock classes.
 */
 
@@ -22,24 +23,58 @@
 class FITSDataSwapper : public DataSwapperInterface<T> {
 public:
-  FITSDataSwapper();
-  FITSDataSwapper(fitsfile * is, int coli, fitsfile * os=NULL, int colo=0); 
+  FITSDataSwapper() 
+  {
+    SetInOutStream(NULL, 0); 
+  }
+  FITSDataSwapper(FitsInOutFile * ios, int col) 
+  {
+    SetInOutStream(ios, col); 
+  }
 
-  inline fitsfile * InStream() { return fitsis; }
-  inline fitsfile * OutStream() { return fitsos; }
-  void SetInStream(fitsfile * is, int col);
-  void SetOutStream(fitsfile * os, int col);
+  inline FitsInOutFile * InOutStream() { return fios; }
+  void SetInOutStream(FitsInOutFile * ios, int col) 
+  {
+    fios = ios;
+    fcol = col;
+    rowos = 1;
+    if ( fios != NULL) {
+      fhdu = fios->CurrentHDU();
+      if (fios->CurrentHDUType() != BINARY_TBL)
+	throw FitsIOException("FITSDataSwapper<T>::SetInOutStream() CurrHDU not a BINARY_TBL");
+    }
+  }
 
   // Operateur = , on recopie les pointeurs des streams 
-  FITSDataSwapper<T>& operator = (FITSDataSwapper<T> const & a); 
+  FITSDataSwapper<T>& operator = (FITSDataSwapper<T> const & a)
+  {
+    fios = a.fios;
+    fcol = a.fcol;
+    rowos = a.rowos;
+    fhdu = a.fhdu;
+  }
 
-  virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false);
-  virtual void  ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz);
+  virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false)
+  {
+    if (fios == NULL) 
+      FitsIOException("FITSDataSwapper<T>::ReadFromSwap() null InOutFile pointer");
+    fios->MoveAbsToHDU(fhdu);
+    long row = rowos;
+    if (osw)  row = oswp;
+    FitsBlockRW<T>::WriteColumnData(*fios, fcol, row, 1, d, sz);
+    if (!osw) rowos += sz;
+    return row;
+  }
+
+  virtual void  ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)
+  {
+    if (fios == NULL) 
+      FitsIOException("FITSDataSwapper<T>::ReadFromSwap() null InOutFile pointer");
+    FitsBlockRW<T>::ReadColumnData(*fios, fcol, swp, 1, d, sz);
+  }
 
 protected:
-  fitsfile * fitsos;
-  int colos, hduos;
+  FitsInOutFile * fios;
+  int fcol, fhdu;
   long rowos;
-  fitsfile * fitsis;
-  int colis, hduis;
 };
 
