Index: trunk/SophyaExt/FitsIOServer/fabtwriter.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 1659)
+++ trunk/SophyaExt/FitsIOServer/fabtwriter.cc	(revision 1660)
@@ -15,9 +15,9 @@
   FitsABTWriter fbtw(fitswrit,BINARY_TBL);
   fbtw.SetExtName("MY_OWN_EXTENSION");
-  fbtw.AddCol("vars",TSHORT,"","km");       // col=0
-  fbtw.AddCol("vars2",TSHORT,"","km");      // col=1
-  fbtw.AddCol("varl",TINT32BIT,"","Degre"); // col=2
-  fbtw.AddCol("varf",TFLOAT,"","");         // col=3
-  fbtw.AddCol("vard",TDOUBLE,"","arcmin");  // col=4
+  fbtw.AddCol("vars",NULL,"km",TSHORT);       // col=0
+  fbtw.AddCol("vars2",NULL,"km",TSHORT);      // col=1
+  fbtw.AddCol("varl",NULL,"Degre",TINT32BIT); // col=2
+  fbtw.AddCol("varf",NULL,"",TFLOAT);         // col=3
+  fbtw.AddCol("vard","","arcmin",TDOUBLE);    // col=4
   fbtw.SetDebug(3);
   for(long i=0;i<1000;i++) {
@@ -119,33 +119,45 @@
   Add a new column to the FITS table
   \param label : column label
-  \param datatype : TSHORT TINT32BIT TFLOAT or TDOUBLE
-  \param tform : fits tform definition
-         (can be automatically set if BINARY_TBL and tform="")
+  \param tform : fits tform definition ("1I","1J","1E","1J",...)
+         (can be automatically set as "datatype"
+          if BINARY_TBL and tform="" or tform=NULL)
   \param tunit : fits tunit definition (optional)
+  \param datatype : TBYTE TSHORT TINT32BIT TLONG TFLOAT TDOUBLE
+                    TUSHORT TULONG. That parameter is only use in case
+                    of a BINARY_TBL table when tform is not defined).
   \return The number of the new added column in the table.
   \warning col = [0,ncol-1]
 */
-int FitsABTWriter::addcol(const char* label,int datatype
-                         ,const char* tform,const char* tunit)
+int FitsABTWriter::addcol(const char* label,const char* tform
+                         ,const char* tunit,int datatype)
 {
   if(!FirstTime)
     throw AllocationError("FitsABTWriter::addcol: table already created\n");
-
- if(  datatype!=TSHORT && datatype!=TINT32BIT
-   && 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");
+ // Gestion auto du tform pour les tables binaires avec le datatype (si non-definie)
+ bool tformauto = false;
+ if(HduType==BINARY_TBL) {
+   if(tform==NULL)      tformauto = true;
+   if(strlen(tform)<=0) tformauto = true;
+ }
+ if(tformauto) {
+   char str[8];
+   if(datatype==TBYTE)          strcpy(str,"1B");
+   else if(datatype==TSHORT)    strcpy(str,"1I");
    else if(datatype==TINT32BIT) strcpy(str,"1J");
+   else if(datatype==TLONG)     strcpy(str,"1J");
    else if(datatype==TFLOAT)    strcpy(str,"1E");
    else if(datatype==TDOUBLE)   strcpy(str,"1D");
+   else if(datatype==TUSHORT)   strcpy(str,"1U");
+   else if(datatype==TULONG)    strcpy(str,"1V");
+   else
+     throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
    TForm.push_back(str);
- } else TForm.push_back(tform);
- TUnit.push_back(tunit);
+ } else {
+   if(tform) TForm.push_back(tform); else TForm.push_back("");
+   datatype = 0;
+ }
+ Label.push_back(label);
+ if(tunit) TUnit.push_back(tunit); else TUnit.push_back("");
 
  int n = (int) Label.size() -1;
@@ -153,7 +165,7 @@
  if(DbgLevel)
    cout<<"FitsABTWriter::addcol["<<n<<"] Label="<<Label[n]
-       <<" datatype="<<datatype
        <<" TForm="<<TForm[n]
-       <<" TUnit="<<TUnit[n]<<endl;
+       <<" TUnit="<<TUnit[n]
+       <<" datatype="<<datatype<<endl;
 
  return n;
@@ -220,10 +232,10 @@
   \verbatim
   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
+           and suppose that you wanted to write a double value "val"
+   - If you write dummy.Write(col,row,(short)(val))
+       the Write(int,long,short) routine is called 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 Write(int,long,double) routine is called and
        the cast is performed by the cfistio package.
   \endverbatim
@@ -311,5 +323,5 @@
 
 //////////////////////////////////////////////////////////////
-void FitsABTWriter::printerrorwrite(char* type,int col,long row,int sta)
+void FitsABTWriter::printerrorwrite(const char* type,int col,long row,int sta)
 {
  if(sta==NUM_OVERFLOW) {NOverFlow++; return;}
