Index: trunk/SophyaExt/FitsIOServer/Makefile
===================================================================
--- trunk/SophyaExt/FitsIOServer/Makefile	(revision 1646)
+++ trunk/SophyaExt/FitsIOServer/Makefile	(revision 1654)
@@ -3,7 +3,7 @@
 all: $(LIB)libFitsIOServer.a
 clean:
-	rm -f $(OBJ)fbtntintf.o $(OBJ)fitsautoreader.o $(OBJ)fitsbntbllineRW.o $(OBJ)fitsfile.o $(OBJ)fitslocalmap.o $(OBJ)fitsntuple.o $(OBJ)fitsspherehealpix.o $(OBJ)fitstarray.o $(OBJ)fitsxntuple.o
+	rm -f $(OBJ)fabtcolread.o $(OBJ)fabtwriter.o $(OBJ)fbtntintf.o $(OBJ)fitsautoreader.o $(OBJ)fitsbntbllineRW.o $(OBJ)fitsfile.o $(OBJ)fitslocalmap.o $(OBJ)fitsntuple.o $(OBJ)fitsspherehealpix.o $(OBJ)fitstarray.o $(OBJ)fitsxntuple.o
 	rm -f $(LIB)libFitsIOServer.a
-$(LIB)libFitsIOServer.a : $(OBJ)fbtntintf.o $(OBJ)fitsautoreader.o $(OBJ)fitsbntbllineRW.o $(OBJ)fitsfile.o $(OBJ)fitslocalmap.o $(OBJ)fitsntuple.o $(OBJ)fitsspherehealpix.o $(OBJ)fitstarray.o $(OBJ)fitsxntuple.o
+$(LIB)libFitsIOServer.a : $(OBJ)fabtcolread.o $(OBJ)fabtwriter.o $(OBJ)fbtntintf.o $(OBJ)fitsautoreader.o $(OBJ)fitsbntbllineRW.o $(OBJ)fitsfile.o $(OBJ)fitslocalmap.o $(OBJ)fitsntuple.o $(OBJ)fitsspherehealpix.o $(OBJ)fitstarray.o $(OBJ)fitsxntuple.o
 	$(ARCXX) $(ARCXXFLAGS) $@ $?
 ifeq ($(CXX),cxx)
@@ -11,5 +11,40 @@
 endif 
  
-$(OBJ)fbtntintf.o: fbtntintf.cc $(INC)machdefs.h \
+$(OBJ)fabtcolread.o: fabtcolread.cc \
+ $(INC)machdefs.h \
+ $(INC)pexceptions.h \
+ fabtcolread.h $(INC)anydataobj.h \
+ $(INC)tvector.h \
+ $(INC)tmatrix.h \
+ $(INC)tarray.h \
+ $(INC)basarr.h \
+ $(INC)mutyv.h \
+ $(INC)dvlist.h \
+ $(INC)objfio.h \
+ $(INC)ppersist.h \
+ $(INC)gnumd5.h \
+ $(INC)ndatablock.h \
+ $(INC)utilarr.h \
+ $(EXTINCPATH)FitsIO/fitsio.h \
+ $(EXTINCPATH)FitsIO/longnam.h
+$(OBJ)fabtwriter.o: fabtwriter.cc \
+ $(INC)machdefs.h \
+ $(INC)pexceptions.h fabtwriter.h \
+ $(INC)anydataobj.h \
+ $(INC)tvector.h \
+ $(INC)tmatrix.h \
+ $(INC)tarray.h \
+ $(INC)basarr.h \
+ $(INC)mutyv.h \
+ $(INC)dvlist.h \
+ $(INC)objfio.h \
+ $(INC)ppersist.h \
+ $(INC)gnumd5.h \
+ $(INC)ndatablock.h \
+ $(INC)utilarr.h \
+ $(EXTINCPATH)FitsIO/fitsio.h \
+ $(EXTINCPATH)FitsIO/longnam.h
+$(OBJ)fbtntintf.o: fbtntintf.cc \
+ $(INC)machdefs.h \
  $(INC)pexceptions.h fbtntintf.h \
  $(INC)anydataobj.h \
@@ -19,5 +54,6 @@
 $(OBJ)fitsautoreader.o: fitsautoreader.cc \
  $(INC)pexceptions.h \
- $(INC)machdefs.h fitsautoreader.h \
+ $(INC)machdefs.h \
+ fitsautoreader.h \
  $(INC)anydataobj.h fitsfile.h \
  $(INC)ndatablock.h \
@@ -31,5 +67,6 @@
  $(INC)tarray.h \
  $(INC)basarr.h \
- $(INC)utilarr.h fitsspherehealpix.h \
+ $(INC)utilarr.h \
+ fitsspherehealpix.h \
  $(INC)spherehealpix.h \
  $(INC)sphericalmap.h \
@@ -43,6 +80,6 @@
  $(INC)tvector.h \
  $(INC)tmatrix.h \
- $(INC)HEALPixUtils.h fitsntuple.h \
- $(INC)ntuple.h \
+ $(INC)HEALPixUtils.h \
+ fitsntuple.h $(INC)ntuple.h \
  $(INC)ntupintf.h fitsxntuple.h \
  $(INC)xntuple.h fitslocalmap.h \
@@ -50,6 +87,6 @@
 $(OBJ)fitsbntbllineRW.o: fitsbntbllineRW.cc \
  $(INC)pexceptions.h \
- $(INC)machdefs.h fitsbntbllineRW.h \
- $(INC)dvlist.h \
+ $(INC)machdefs.h \
+ fitsbntbllineRW.h $(INC)dvlist.h \
  $(INC)objfio.h \
  $(INC)anydataobj.h \
@@ -61,6 +98,7 @@
  $(EXTINCPATH)FitsIO/longnam.h \
  $(INC)utils.h
-$(OBJ)fitsfile.o: fitsfile.cc $(INC)machdefs.h \
- fitsfile.h $(INC)ndatablock.h \
+$(OBJ)fitsfile.o: fitsfile.cc \
+ $(INC)machdefs.h fitsfile.h \
+ $(INC)ndatablock.h \
  $(INC)anydataobj.h \
  $(INC)dvlist.h \
@@ -72,5 +110,6 @@
  $(EXTINCPATH)FitsIO/fitsio.h \
  $(EXTINCPATH)FitsIO/longnam.h \
- $(INC)strutil.h fitsspherehealpix.h \
+ $(INC)strutil.h \
+ fitsspherehealpix.h \
  $(INC)spherehealpix.h \
  $(INC)sphericalmap.h \
@@ -130,5 +169,6 @@
 $(OBJ)fitsspherehealpix.o: fitsspherehealpix.cc \
  $(INC)pexceptions.h \
- $(INC)machdefs.h fitsspherehealpix.h \
+ $(INC)machdefs.h \
+ fitsspherehealpix.h \
  $(INC)spherehealpix.h \
  $(INC)sphericalmap.h \
@@ -155,5 +195,6 @@
  $(EXTINCPATH)FitsIO/fitsio.h \
  $(EXTINCPATH)FitsIO/longnam.h fitstarray.h
-$(OBJ)fitstarray.o: fitstarray.cc $(INC)machdefs.h \
+$(OBJ)fitstarray.o: fitstarray.cc \
+ $(INC)machdefs.h \
  $(INC)pexceptions.h fitstarray.h \
  $(INC)tarray.h \
Index: trunk/SophyaExt/FitsIOServer/fabtcolread.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtcolread.cc	(revision 1654)
+++ trunk/SophyaExt/FitsIOServer/fabtcolread.cc	(revision 1654)
@@ -0,0 +1,372 @@
+/* Lecteur de colonne de table Fits (binaire ou ASCII) avec buffer */
+#include "machdefs.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include "pexceptions.h"
+#include "fabtcolread.h"
+//! Class for reading a column in a FITS ASCII or BINARY table
+
+/*!
+  \class SOPHYA::FitsABTColRead
+  \ingroup FitsIOServer
+  Class for reading a column in a FITS ASCII or BINARY table
+  \verbatim
+  Exemple:
+  FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3);
+  fbt.SetDebug(3);
+  fbt.Print(3);
+  for(long i=0;i<fbt.GetNbLine();i++) {
+    double x = fbt.Read(i);
+    if(i%lpmod==0) cout<<i<<": "<<x<<endl;
+  }
+  \endverbatim
+*/
+
+//////////////////////////////////////////////////////////////
+/*!
+  Constructor.
+  \verbatim
+  fname : FITS file name to be read
+  collabel : label of the column to be read
+  ihdu : number of the HDU where the column is.
+     if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken
+     Warning: ihdu = [1,nhdu]
+  blen : read buffer length
+  bsens : read buffer reading direction
+          (bsens>0 forward, bsens<0 backward, bsens==0 centered)
+  lp : debug level
+  \endverbatim
+*/
+FitsABTColRead::FitsABTColRead(string fname,string collabel
+                            ,int ihdu,long blen,long bsens,int lp)
+{
+Init(fname.c_str(),collabel.c_str(),-1,ihdu,blen,bsens,lp);
+}
+
+/*!
+  Constructor.
+  \verbatim
+  Same as before but the column is identified by its number
+  colnum : number of the column to be read
+  WARNING: col = [0,ncol[
+  \endverbatim
+*/
+FitsABTColRead::FitsABTColRead(string fname,int colnum
+                            ,int ihdu,long blen,long bsens,int lp)
+{
+Init(fname.c_str(),"",colnum,ihdu,blen,bsens,lp);
+}
+
+/*! Constructor. see below */
+FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel
+                            ,int ihdu,long blen,long bsens,int lp)
+{
+Init(cfname,collabel,-1,ihdu,blen,bsens,lp);
+}
+
+/*! Constructor. see below */
+FitsABTColRead::FitsABTColRead(const char * cfname,int colnum
+                            ,int ihdu,long blen,long bsens,int lp)
+{
+Init(cfname,"",colnum,ihdu,blen,bsens,lp);
+}
+
+/*! Constructor by copy */
+FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt)
+{
+Init(fbt.GetFileName().c_str(),fbt.GetColLabel().c_str()
+    ,fbt.GetColNum(),fbt.GetHDU()
+    ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
+}
+
+/*! Init routine called by the constructor */
+void FitsABTColRead::Init(const char* fname,const char* collabel,int colnum
+                        ,int ihdu,long blen,long bsens,int lp)
+{
+ // Parametres Generaux
+ FitsFN = fname;
+ ColLabel = collabel;
+ ColTUnit = "";
+ ColTForm = "";
+ ColNum = colnum;
+ ColTypeCode = 0;
+ IHdu = ihdu;
+ NHdu = 0;
+ HduType = 0;
+ NBcol = 0;
+ NBline = 0;
+ SetNulVal();
+ SetDebug(lp);
+ BuffLen = (blen<=0) ? 1: blen;
+ BuffSens = bsens;
+ NFitsRead = 0;
+ FitsPtr = NULL;
+ LineDeb = LineFin = -1;
+ Buffer = NULL;
+ NBuffer = 0;
+
+ //////////////////////////
+ // Ouverture du fichier //
+ //////////////////////////
+
+ int sta=0;
+ if(FitsFN.size() <= 0 ) {
+   IHdu = -1;
+   throw ParmError("FitsABTColRead::Init: Fits file name error\n");
+ }
+ const char * cfitsfn = FitsFN.c_str();
+
+ // Open fits
+ if(fits_open_file(&FitsPtr,cfitsfn,READONLY,&sta)) {
+   printerror(sta); Delete();
+   throw NullPtrError("FitsABTColRead::Init: Error opening Fits file\n");
+ }
+
+ // Get number of hdu
+ if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
+   printerror(sta); Delete();
+   throw NotAvailableOperation("FitsABTColRead::Init: Error getting NHdu\n");
+ }
+ if(DbgLevel>1) cout<<"FitsABTColRead::Init  NHdu="<<NHdu<<endl;
+ if(NHdu<=0) {
+   Delete();
+   throw SzMismatchError("FitsABTColRead::Init: Bad NHdu\n");
+ }
+
+ // Get HDU for bin/ascii table
+ // si IHdu <=0 || >NHdu on cherche la 1ere bin/ascii table
+ // sinon on se positionne sur IHdu
+ if(IHdu<=0 || IHdu>NHdu)
+   for(int ihdu=1;ihdu<=NHdu;ihdu++) {
+     if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) printerror(sta);
+     if(DbgLevel>1) cout<<"...Init ihdu="
+                        <<ihdu<<" HduType="<<HduType<<endl;
+     if(HduType==BINARY_TBL || HduType==ASCII_TBL) {IHdu = ihdu; break;}
+   }
+ if(IHdu<=0 || IHdu>NHdu) {
+   IHdu = 0;
+   cout<<"NO BINARY or ASCII hdu found"<<endl;
+   Delete();
+   throw TypeMismatchExc("FitsABTColRead::Init: NO BINARY or ASCII hdu found\n");
+ }
+ if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) {
+   printerror(sta); Delete();
+   throw RangeCheckError("FitsABTColRead::Init: Error moving to requested HDU\n");
+ }
+ if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) {
+   Delete();
+   throw TypeMismatchExc("FitsABTColRead::Init: HDU not ASCII/BINARY table\n");
+ }
+
+ // Get number of columns
+ if(fits_get_num_cols(FitsPtr,&NBcol,&sta)) {
+   printerror(sta); Delete();
+   throw NotAvailableOperation("FitsABTColRead::Init: Error getting number of columns\n");
+ }
+ if(DbgLevel>1) cout<<"...Init  NBcol="<<NBcol<<endl;
+ if(NBcol<1) {
+   Delete();
+   throw RangeCheckError("FitsABTColRead::Init: Bad number of colums\n");
+ }
+
+ // Get number of rows
+ if(fits_get_num_rows(FitsPtr,&NBline,&sta)) {
+   printerror(sta); Delete();
+   throw NotAvailableOperation("FitsABTColRead::Init: Error getting number of rows\n");
+ }
+ if(DbgLevel>1) cout<<"...Init  NBline="<<NBline<<endl;
+ if(NBline<1) {
+   Delete();
+   throw RangeCheckError("FitsABTColRead::Init: Bad number of rows\n");
+ }
+
+ // Get column number
+ char labelcol[256];
+ if(ColLabel.size() > 0) {
+   strcpy(labelcol,ColLabel.c_str());
+   if(fits_get_colnum(FitsPtr,CASESEN,labelcol,&ColNum,&sta)) {
+     printerror(sta); Delete();
+     throw NotAvailableOperation("FitsABTColRead::Init: Error getting column name\n");
+   }
+   ColNum--;  // Convention [0,ncol[
+ }
+ if(DbgLevel>1) cout<<"...Init  ColNum="<<ColNum<<endl;
+ if(ColNum<0 || ColNum>=NBcol) {
+   Delete();
+   throw RangeCheckError("FitsABTColRead::Init: Bad column number\n");
+ }
+
+ // Get column type
+ int ColTypeCode;
+ if(fits_get_coltype(FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) {
+   printerror(sta); Delete();
+   throw ParmError("FitsABTColRead::Init: Error getting column type\n");
+ }
+ if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl;
+ if(ColTypeCode==TSTRING || ColTypeCode==TCOMPLEX ||  ColTypeCode==TDBLCOMPLEX) {
+   Delete();
+   throw ParmError("FitsABTColRead::Init: Selected column is not Numerical\n");
+ }
+
+ // Get column name back, tunit, tform
+ char tunit[64], tform[64];
+ int rc=0;
+ if(HduType==BINARY_TBL) {
+   fits_get_bcolparms(FitsPtr,ColNum+1,labelcol,tunit,tform,NULL,NULL,NULL,NULL,NULL,&sta);
+ } else {
+   fits_get_acolparms(FitsPtr,ColNum+1,labelcol,NULL,tunit,tform,NULL,NULL,NULL,NULL,&sta);
+ }
+ if(rc) {
+   printerror(sta); Delete();
+   throw RangeCheckError("FitsABTColRead::Init: Error getting the column caracteristics\n");
+ }
+ ColLabel = labelcol;
+ ColTUnit = tunit;
+ ColTForm = tform;
+
+ if(DbgLevel)
+   cout<<"FitsABTColRead::Init Num="<<ColNum<<" Label="<<ColLabel
+       <<" TypeCode="<<ColTypeCode
+       <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl;
+
+ // Prepare buffer
+ NBuffer = (BuffSens==0) ? BuffLen+1: BuffLen;
+ Buffer = new double[NBuffer];
+}
+
+/*! Destructor. */
+FitsABTColRead::~FitsABTColRead()
+{
+ Delete();
+}
+
+
+//////////////////////////////////////////////////////////////
+/*! Change the buffer caracteristiques (see creator)  */
+void FitsABTColRead::ChangeBuffer(long blen,long bsens)
+{
+ BuffLen = (blen<=0)? 1: blen;
+ BuffSens = bsens;
+
+ // De-allocate
+ if(Buffer==NULL) return;
+ delete [] Buffer; Buffer=NULL;
+
+ // Tell program that nothing is into buffer
+ LineDeb = LineFin = -1;
+
+ // Re-allocate
+ NBuffer = (BuffSens==0) ? BuffLen+1: BuffLen;
+ Buffer = new double[NBuffer];
+}
+
+/*! Delete called by the destructor */
+void FitsABTColRead::Delete()
+{
+ if(Buffer==NULL) return;
+ delete [] Buffer; Buffer=NULL;
+ LineDeb = LineFin = -1;
+ int sta = 0;
+ if(fits_close_file(FitsPtr,&sta)) printerror(sta);
+ FitsPtr = NULL;
+}
+
+/////////////////////////////////////////////////
+/*!
+  Read row "n" and return the value cats into double
+  \verbatim
+  WARNING: row = [0,NRows[
+  \endverbatim
+*/
+r_8 FitsABTColRead::Read(long n)
+// Attention: n=nline [0,NBline[, cfistio veut [1,NBline]
+// Attention: colnum  [0,NBcol[ , cfistio veut [1,NBcol]
+{
+ int sta=0,anynul;
+ if(n<0 || n>=NBline)
+   throw RangeCheckError("FitsABTColRead::Read try to read outside line range\n");
+
+ // Pas de bufferisation, on lit betement
+ if(BuffLen==1) {
+   NFitsRead++;
+   fits_read_col_dbl(FitsPtr,ColNum+1,n+1,1,1,NulVal,Buffer,&anynul,&sta);
+   if(sta) {
+     printerror(sta);
+     throw NotAvailableOperation("FitsABTColRead::Read: Error Reading Fits file\n");
+   }
+   return Buffer[0];
+ }
+
+ // Gestion avec bufferisation
+ if(!Buffer) {
+   cout<<"FitsABTNtuIntf::Read Buffer not allocated"<<endl;
+   return 0;
+ }
+ if(n<LineDeb || n>LineFin) {
+   NFitsRead++;
+   long row1,row2,nrow;
+   if(BuffSens>0) { // Cas remplissage forward
+     row1 = n+1;
+     row2 = row1+BuffLen-1; if(row2>NBline) row2 = NBline;
+   } else if(BuffSens<0) { // Cas remplissage backward
+     row2 = n+1;
+     row1 = row2-BuffLen+1; if(row1<1) row1 = 1;
+   } else { // Cas remplissage centre
+     row1 = n+1 - BuffLen/2; if(row1<1) row1 = 1;
+     row2 = n+1 + BuffLen/2; if(row2>NBline) row2 = NBline;
+   }
+   nrow = row2 - row1 + 1;
+   LineDeb = row1-1; LineFin = row2-1;
+   //cout<<"DBG-FitsRead: row1="<<row1<<" row2="<<row2<<" nrow="<<nrow
+   //    <<" LineDeb,Fin="<<LineDeb<<","<<LineFin<<endl;
+   fits_read_col_dbl(FitsPtr,ColNum+1,row1,1,nrow,NulVal,Buffer,&anynul,&sta);
+   if(sta) {
+     printerror(sta);
+     LineDeb = LineFin = -1;
+     throw NotAvailableOperation("FitsABTColRead::Read: Error Reading Fits file\n");
+   }
+ }
+
+ long ibuf = n-LineDeb;
+ return Buffer[ibuf];
+}
+
+/*!
+  Read rows from "n1" to "n2" and return the values cats in a TVector of double
+  \verbatim
+  There are n2-n1+1 values returned
+  WARNING: row = [0,NRows[
+  \endverbatim
+*/
+void FitsABTColRead::Read(long n1,long n2,TVector<r_8>& data)
+{
+ if(n1<0 || n1>=NBline || n2<0 || n2>=NBline || n1>n2)
+   throw RangeCheckError("FitsABTColRead::Read TVector bad requested line range\n");
+
+ sa_size_t n = n2-n1+1;
+ if(data.Size()<n) data.SetSize(n);
+ // Il faut faire mieux mais comment ????
+ for(long i=n1;i<=n2;i++) data(i-n1) = Read(i);
+}
+
+/////////////////////////////////////////////////
+void FitsABTColRead::printerror(int sta) const
+{
+ int stat = sta;
+ fits_report_error(stdout,stat);
+ fflush(stdout);
+ return;
+}
+
+/*! Print on stream os */
+void FitsABTColRead::Print(ostream& os,int lp) const
+{
+ os<<"FitsABTColRead:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
+   <<" ncols="<<NBcol<<" nrows="<<NBline;
+ if(lp>0) os<<" NRead="<<NFitsRead;
+ os<<"\n... "<<FitsFN<<"["<<IHdu<<"/"<<NHdu<<"]"
+   <<"\n... Label["<<ColNum<<"]="<<ColLabel
+   <<" TypeCode="<<ColTypeCode
+   <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm
+   <<endl;
+}
Index: trunk/SophyaExt/FitsIOServer/fabtcolread.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtcolread.h	(revision 1654)
+++ trunk/SophyaExt/FitsIOServer/fabtcolread.h	(revision 1654)
@@ -0,0 +1,96 @@
+/* Interface Fits BINARY/ASCII Table Column Reader    cmv 26/09/2001 */
+#ifndef FABTCOLREAD_H_SEEN
+#define FABTCOLREAD_H_SEEN
+
+#include "machdefs.h"
+#include <iostream.h>
+#include <string.h>
+#include <string>
+
+#include "anydataobj.h"
+#include "tvector.h"
+#include "FitsIO/fitsio.h"
+
+namespace SOPHYA {
+
+//! Class for reading a column in a FITS ASCII or BINARY table
+class FitsABTColRead : public AnyDataObj {
+public:
+  FitsABTColRead(string fname,string collabel,int ihdu=0
+               ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(string fname,int colnum,int ihdu=0
+               ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
+               ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(const char *cfname,int colnum,int ihdu=0
+               ,long blen=100,long bsens=1,int lp=0);
+  FitsABTColRead(FitsABTColRead& fbt);
+  virtual ~FitsABTColRead();
+
+  void ChangeBuffer(long blen=100,long bsens=1);
+
+  r_8 Read(long n);
+  void Read(long n1,long n2,TVector<r_8>& data);
+
+  //! Set debug level
+  inline void    SetDebug(int lp=0) {DbgLevel = (uint_2) lp;}
+  //! Set null value to be return when reading null data (0=return the data)
+  inline void    SetNulVal(r_8 nulval=0.) {NulVal = nulval;}
+  //! Get the FITS file name
+  inline string  GetFileName(void) {return FitsFN;}
+  //! Get the number of HDU in the FITS file
+  inline int     GetNHDU(void) {return NHdu;}
+  //! Get the number of the HDU read
+  inline int     GetHDU(void) {return IHdu;}
+  //! Get the HDU type
+  inline int     GetHDUType(void) {return HduType;}
+  //! Get the number of rows in the FITS HDU to be read
+  inline long    GetNbLine(void) {return NBline;}
+  //! Get the number of columns in the FITS HDU to be read
+  inline int     GetNbCol(void) {return NBcol;}
+  //! Get the columns number that is read
+  inline int     GetColNum(void) {return ColNum;}
+  //! Get the columns label that is read
+  inline string  GetColLabel(void) {return ColLabel;}
+  //! Get the columns type code that is read
+  inline int     GetColTypeCode(void) {return ColTypeCode;}
+  //! Get the columns fits tunit that is read
+  inline string  GetColTUnit(void) {return ColTUnit;}
+  //! Get the columns fits tform that is read
+  inline string  GetColTForm(void) {return ColTForm;}
+  //! Get the read buffer length
+  inline long    GetBLen(void) {return BuffLen;}
+  //! Get the read buffer direction
+  inline long    GetBSens(void) {return BuffSens;}
+  //! Print to os
+  virtual void   Print(ostream& os,int lp=1) const;
+  //! Print to stdout
+  inline  void   Print(int lp=1) const {Print(cout,lp);}
+  //! Get the read buffer effective length
+  inline long    GetBufferLen(void) {return NBuffer;}
+  //! Get the read bufferpointer
+  inline double* GetBuffer(void) {return Buffer;}
+
+protected:
+  void Init(const char *cfname,const char *collabel,int colnum
+           ,int ihdu,long blen,long bsens,int lp);
+  void Delete(void);
+  void printerror(int sta) const;
+
+  string FitsFN,ColLabel,ColTUnit,ColTForm;
+  int ColNum,ColTypeCode,IHdu,NHdu,HduType,NBcol;
+  long NBline;
+
+  r_8 NulVal;
+  uint_2 DbgLevel;
+  long BuffLen, BuffSens;
+
+  uint_4 NFitsRead;
+  fitsfile *FitsPtr;
+  long LineDeb, LineFin;
+  double *Buffer;
+  long NBuffer;
+};
+
+} // namespace SOPHYA
+#endif    /* FABTCOLREAD_H_SEEN */
Index: trunk/SophyaExt/FitsIOServer/fabtwriter.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 1654)
+++ trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 1654)
@@ -0,0 +1,272 @@
+/* Writer de table Fits (binaire ou ASCII) */
+#include "machdefs.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include "pexceptions.h"
+#include "fabtwriter.h"
+
+/*!
+  \class SOPHYA::FitsABTWriter
+  \ingroup FitsIOServer
+  Class for writing a FITS ASCII or BINARY table
+  \verbatim\
+  Exemple:
+  FitsABTWriter fbtw("myfits.fits",BINARY_TBL,3);
+  fbtw.SetExtName("MY_OWN_EXTENSION");
+  fbtw.AddCol("vars",TSHORT,"","km");      // col=0
+  fbtw.AddCol("vars2",TSHORT,"","km");     // col=1
+  fbtw.AddCol("varl",TLONG,"","Degre");    // col=2
+  fbtw.AddCol("varf",TFLOAT,"","");        // col=3
+  fbtw.AddCol("vard",TDOUBLE,"","arcmin"); // col=4
+  fbtw.SetDebug(3);
+  for(long i=0;i<1000;i++) {
+    double x = i;
+    fbtw.Write(0,i,1000.*x); // if overflow, managed by cfitsio
+                             // Write(int,long,double) is called
+    fbtw.Write(1,i,(short)(1000.*x));
+                             // if overflow, managed by language
+                             // Write(int,long,short) is called
+    fbtw.Write(2,i,x);
+    fbtw.Write(3,i,x);
+    fbtw.Write(4,i,x);
+  }
+  cout<<"Number of Overflows when writing: "
+      <<fbtw.GetNOverFlow()<<endl;
+  \endverbatim
+*/
+
+//////////////////////////////////////////////////////////////
+/*!
+  Constructor.
+  \verbatim
+  fname : FITS file name to be written
+  hdutype : type of extension to be created (BINARY_TBL or ASCII_TBL)
+  lp : debug level
+  \endverbatim
+*/
+FitsABTWriter::FitsABTWriter(string fname,int hdutype,int lp)
+{
+  createfits(fname.c_str(),hdutype,lp);
+}
+
+/*! See FitsABTWriter() */
+FitsABTWriter::FitsABTWriter(const char* cfname,int hdutype,int lp)
+{
+  createfits(cfname,hdutype,lp);
+}
+
+/*! See FitsABTWriter() */
+void FitsABTWriter::createfits(const char *cfname,int hdutype,int lp)
+{
+ FirstTime = true;
+ FitsPtr = NULL;
+ HduType = hdutype;
+ SetDebug(lp);
+ FitsFN = cfname;
+ NOverFlow = 0;
+
+ if(DbgLevel)
+   cout<<"FitsABTWriter::createfits FitsFN="<<FitsFN
+       <<" HduType="<<HduType<<endl;
+
+ if(FitsFN.size() <= 0 )
+   throw ParmError("FitsABTWriter::createfits: Fits file name error\n");
+
+ if(HduType!=BINARY_TBL && HduType!=ASCII_TBL)
+   throw TypeMismatchExc("FitsABTWriter::createfits: Only BINARY or ASCII table permitted\n");
+
+ // create new FITS file
+ int sta=0;
+ if(fits_create_file(&FitsPtr,FitsFN.c_str(),&sta)) {
+   printerror(sta);
+   throw NullPtrError("FitsABTWriter::createfits: Error creating Fits file\n");
+ }
+
+ // create d'un Primary HDU */
+ //long naxes[1] = {0};
+ //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
+ //  printerror(sta);
+ //  throw NullPtrError("FitsABTWriter::createfits: Error creating Primary extension\n");
+ //}
+
+}
+
+/*! Destructor */
+FitsABTWriter::~FitsABTWriter()
+{
+ int sta = 0;
+ if(fits_close_file(FitsPtr,&sta)) printerror(sta);
+ FitsPtr = NULL;
+}
+
+//////////////////////////////////////////////////////////////
+/*!
+  Add a new column to the FITS table
+  \verbatim
+  label : column label
+  datatype : TSHORT TLONG TFLOAT or TDOUBLE
+  tform : fits tform definition
+          (can be automatically set if BINARY_TBL and tform="")
+  tunit : fits tunit definition (optional)
+  \endverbatim
+*/
+int FitsABTWriter::addcol(const char* label,int datatype
+                         ,const char* tform,const char* tunit)
+{
+  if(!FirstTime)
+    throw AllocationError("FitsABTWriter::addcol: table already created\n");
+
+ if(  datatype!=TSHORT && datatype!=TLONG
+   && datatype!=TFLOAT && datatype!=TDOUBLE )
+   throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
+ 
+ Label.push_back(label);
+ DataType.push_back(datatype);
+ // Gestion auto du tform par defaut pour les tables binaires
+ if(HduType==BINARY_TBL && strlen(tform)<=0) {
+   char str[16];
+   if(datatype==TSHORT)       strcpy(str,"1I");
+   else if(datatype==TLONG)   strcpy(str,"1J");
+   else if(datatype==TFLOAT)  strcpy(str,"1E");
+   else if(datatype==TDOUBLE) strcpy(str,"1D");
+   TForm.push_back(str);
+ } else TForm.push_back(tform);
+ TUnit.push_back(tunit);
+
+ int n = (int) Label.size() -1;
+
+ if(DbgLevel)
+   cout<<"FitsABTWriter::addcol["<<n<<"] Label="<<Label[n]
+       <<" datatype="<<datatype
+       <<" TForm="<<TForm[n]
+       <<" TUnit="<<TUnit[n]<<endl;
+
+ return n;
+}
+
+/*! Create the table. Done at the first write request. */
+void FitsABTWriter::createtbl(void)
+{
+  if(!FirstTime) return;
+
+ int tfields = Label.size();
+ if(tfields<=0)
+   throw ParmError("FitsABTWriter::createtbl: Zero column asked !\n");
+
+ long nrows = 0;
+ char *extname = NULL;
+ char **ttype   = (char **) malloc(tfields*sizeof(char *));
+ char **tform   = (char **) malloc(tfields*sizeof(char *));
+ char **tunit   = (char **) malloc(tfields*sizeof(char *));
+
+ if(ExtName.size()>0) {
+   extname = (char *) malloc((strlen(ExtName.c_str())+1)*sizeof(char));
+   strcpy(extname,ExtName.c_str());
+ }
+ for(int i=0;i<tfields;i++) {
+   ttype[i] = (char *) malloc((strlen(Label[i].c_str())+1)*sizeof(char));
+     strcpy(ttype[i],Label[i].c_str());
+   tform[i] = (char *) malloc((strlen(TForm[i].c_str())+1)*sizeof(char));
+     strcpy(tform[i],TForm[i].c_str());
+   tunit[i] = (char *) malloc((strlen(TUnit[i].c_str())+1)*sizeof(char));
+     strcpy(tunit[i],TUnit[i].c_str());
+ }
+
+ // append a new empty binary/ascii table onto the FITS file
+ int sta=0;
+ if(fits_create_tbl(FitsPtr,HduType,nrows,tfields,ttype,tform,tunit,extname,&sta)) {
+   printerror(sta);
+   throw NullPtrError("FitsABTWriter::createtbl: Error creating Table extension\n");
+ }
+
+ // menage
+ if(extname) delete [] extname;
+ for(int i=0;i<tfields;i++) {
+   if(ttype[i]) delete [] ttype[i];
+   if(tform[i]) delete [] tform[i];
+   if(tunit[i]) delete [] tunit[i];
+ }
+ if(ttype) delete [] ttype;
+ if(tform) delete [] tform;
+ if(tunit) delete [] tunit;
+
+ FirstTime = false;
+}
+
+//////////////////////////////////////////////////////////////
+/*!
+  Write a short data to FITS file.
+  \verbatim
+  col : column number [0,ncol[
+  row : row number    [0,nrow[
+  val : value to be written
+  WARNING: that routine write a SHORT value into column "col"
+           which could have been defined with an other type.
+           Cast is performed by the cfitsio package.
+  WARNING: suppose that the column has be defined to be TSHORT
+           and suppose that you wanted to write a double value
+   - If you write dummy.Write(col,row,(short(val))
+       you call the Write(int,long,short) routine and
+       the cast is performed by the C++ language.
+   - If you write dummy.Write(col,row,val) where val is double
+       you call theWrite(int,long,double) routine and
+       the cast is performed by the cfistio package.
+  \endverbatim
+*/
+void FitsABTWriter::Write(int col,long row,short val)
+{
+  if(FirstTime) createtbl();
+  short x[1] = {val};
+  int sta=0;
+  if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,x,&sta))
+    printerrorwrite("short",col,row,sta);
+}
+
+/*! Write long data to FITS file (see below) */
+void FitsABTWriter::Write(int col,long row,long val)
+{
+  if(FirstTime) createtbl();
+  long x[1] = {val};
+  int sta=0;
+  if(fits_write_col(FitsPtr,TLONG,col+1,row+1,1,1,x,&sta))
+    printerrorwrite("long",col,row,sta);
+}
+
+/*! Write float data to FITS file (see below) */
+void FitsABTWriter::Write(int col,long row,float val)
+{
+  if(FirstTime) createtbl();
+  float x[1] = {val};
+  int sta=0;
+  if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,x,&sta))
+    printerrorwrite("float",col,row,sta);
+}
+
+/*! Write double data to FITS file (see below) */
+void FitsABTWriter::Write(int col,long row,double val)
+{
+  if(FirstTime) createtbl();
+  double x[1] = {val};
+  int sta=0;
+  if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,x,&sta))
+    printerrorwrite("double",col,row,sta);
+}
+
+void FitsABTWriter::printerrorwrite(char* type,int col,long row,int sta)
+{
+ if(sta==NUM_OVERFLOW) {NOverFlow++; return;}
+ printerror(sta);
+ char str[256];
+ sprintf(str,"FitsABTWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d"
+        ,type,col,row,sta);
+ throw NotAvailableOperation(str);
+}
+
+/////////////////////////////////////////////////
+void FitsABTWriter::printerror(int sta) const
+{
+ int stat = sta;
+ fits_report_error(stdout,stat);
+ fflush(stdout);
+ return;
+}
Index: trunk/SophyaExt/FitsIOServer/fabtwriter.h
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtwriter.h	(revision 1654)
+++ trunk/SophyaExt/FitsIOServer/fabtwriter.h	(revision 1654)
@@ -0,0 +1,69 @@
+/* Interface Fits BINARY/ASCII Table Writer    cmv 26/09/2001 */
+#ifndef FABTWRITER_H_SEEN
+#define FABTWRITER_H_SEEN
+
+#include "machdefs.h"
+#include <iostream.h>
+#include <string.h>
+#include <string>
+
+#include "anydataobj.h"
+#include "tvector.h"
+#include "FitsIO/fitsio.h"
+
+#include <vector>
+
+namespace SOPHYA {
+
+//! Class for writing a FITS ASCII or BINARY table
+class FitsABTWriter : public AnyDataObj {
+public:
+  FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0);
+  FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0);
+  virtual ~FitsABTWriter();
+
+  //! Add a new column to the FITS table and return its number (see addcol).
+  inline int AddCol(string label,int datatype=TDOUBLE
+                   ,string tform=string(""),string tunit=string(""))
+     {return addcol(label.c_str(),datatype,tform.c_str(),tunit.c_str());}
+  //! Add a new column to the FITS table and return its number (see addcol).
+  inline int AddCol(const char* label,int datatype=TDOUBLE
+                   ,const char* tform="",const char* tunit="")
+     {return addcol(label,datatype,tform,tunit);}
+
+  //! Set the FITS table extension name
+  inline void SetExtName(string extname=string("")) {ExtName = extname;}
+  //! Set the FITS table extension name
+  inline void SetExtName(char* extname="") {ExtName = extname;}
+  //! Set debug level
+  inline void SetDebug(int lp=0) {DbgLevel = (uint_2) lp;}
+
+  void Write(int col,long row,short  val);
+  void Write(int col,long row,long   val);
+  void Write(int col,long row,float  val);
+  void Write(int col,long row,double val);
+  //! Return the number of overflows managed by cfitsio
+  inline uint_4 GetNOverFlow(void) {return NOverFlow;}
+
+protected:
+  void createfits(const char *cfname,int hdutype,int lp);
+  int addcol(const char* label,int datatype
+            ,const char* tform,const char* tunit);
+  void createtbl(void);
+  void printerrorwrite(char* type,int col,long row,int sta);
+  void printerror(int sta) const;
+
+  string FitsFN,ExtName;
+  int HduType;
+  uint_2 DbgLevel;
+  fitsfile *FitsPtr;
+  bool FirstTime;
+  vector<string> Label;
+  vector<int> DataType;
+  vector<string> TForm;
+  vector<string> TUnit;
+  uint_4 NOverFlow;
+};
+
+} // namespace SOPHYA
+#endif    /* FABTWRITER_H_SEEN */
Index: trunk/SophyaExt/FitsIOServer/objlist.list
===================================================================
--- trunk/SophyaExt/FitsIOServer/objlist.list	(revision 1646)
+++ trunk/SophyaExt/FitsIOServer/objlist.list	(revision 1654)
@@ -1,2 +1,4 @@
+fabtcolread.o
+fabtwriter.o
 fbtntintf.o
 fitsautoreader.o
