Index: trunk/SophyaExt/FitsIOServer/fabtcolread.cc
===================================================================
--- trunk/SophyaExt/FitsIOServer/fabtcolread.cc	(revision 4023)
+++ trunk/SophyaExt/FitsIOServer/fabtcolread.cc	(revision 4025)
@@ -349,5 +349,6 @@
 {
  ColLabel = ""; ColTUnit = ""; ColTForm = "";
- ColNum = -1; ColTypeCode = 0; ColRepeat=0;
+ ColNum = -1; ColTypeCode = 0; ColRepeat=0; ColDispWidth=0;
+ StrBuff = NULL;
  NBcol = 0; NBline = 0;
  SetNulVal(); SetDebug(0);
@@ -363,5 +364,7 @@
 {
  // Initialisation des Parametres Generaux
- ColLabel=collabel; ColTUnit=""; ColTForm=""; ColNum=colnum; ColTypeCode=0; ColRepeat=0;
+ ColLabel=collabel; ColTUnit=""; ColTForm="";
+ ColNum=colnum; ColTypeCode=0; ColRepeat=0; ColDispWidth=0;
+ StrBuff = NULL;
  NBcol = 0; NBline = 0;
  SetNulVal(); SetDebug(lp);
@@ -445,7 +448,6 @@
  }
  if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl;
- if(ColTypeCode==TSTRING || ColTypeCode==TCOMPLEX ||  ColTypeCode==TDBLCOMPLEX
-                         || ColTypeCode<0 )
-   throw ParmError("FitsABTColRd::Init: Selected column is not Numerical\n");
+ if(ColTypeCode<0 )
+   throw ParmError("FitsABTColRd::Init: Selected column type decoding not implemented\n");
 
  // Get column name back, tunit, tform
@@ -454,10 +456,10 @@
  int rc=0;
  if(HDUType()==BINARY_TBL) {
-   fits_get_bcolparmsll(GetFitsPtr(),ColNum+1,labelcol,tunit,tform
-                     ,&repeat,&tscale,&tzero,NULL,tdisp,&sta);
+   rc = fits_get_bcolparmsll(GetFitsPtr(),ColNum+1,labelcol,tunit,tform
+                            ,&repeat,&tscale,&tzero,NULL,tdisp,&sta);
  } else {
    long repeatlng;
-   fits_get_acolparms(GetFitsPtr(),ColNum+1,labelcol,&repeatlng,tunit,tform
-                     ,&tscale,&tzero,NULL,tdisp,&sta);
+   rc = fits_get_acolparms(GetFitsPtr(),ColNum+1,labelcol,&repeatlng,tunit,tform
+                          ,&tscale,&tzero,NULL,tdisp,&sta);
    repeat = repeatlng;
  }
@@ -471,4 +473,6 @@
  ColRepeat = repeat;
 
+ fits_get_col_display_width(GetFitsPtr(),ColNum+1,&ColDispWidth,&sta);
+
  // Set the buffer for reading
  ChangeBuffer(blen,bsens);
@@ -476,5 +480,6 @@
  if(DbgLevel)
    cout<<"FitsABTColRd::Init Num="<<ColNum<<" Label="<<ColLabel
-       <<" TypeCode="<<ColTypeCode<<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<" Repeat="<<ColRepeat<<endl;
+       <<" TypeCode="<<ColTypeCode<<" TUnit="<<ColTUnit<<" TForm="<<ColTForm
+       <<" Repeat="<<ColRepeat<<" DispWidth="<<ColDispWidth<<endl;
  if(DbgLevel>1)
    cout<<"      (tscale="<<tscale<<",tzero="<<tzero<<",tdisp="<<tdisp<<")"<<endl;
@@ -491,4 +496,5 @@
 void FitsABTColRd::Delete(void)
 {
+ if(StrBuff!=NULL) {delete [] StrBuff; StrBuff=NULL;}
  if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
  LineDeb = LineFin = -1;
@@ -639,4 +645,48 @@
 
 /*!
+  Read row "n" element "nfirstel" and return a complex value
+*/
+complex<r_8> FitsABTColRd::ReadComplex(LONGLONG n,long nfirstel)
+{
+ int sta=0;
+ if(n<0 || n>=NBline)
+   throw RangeCheckError("FitsABTColRd::ReadComplex try to read outside line range\n");
+ if(nfirstel<0 || nfirstel>=ColRepeat)
+   throw RangeCheckError("FitsABTColRd::ReadComplex try to read outside element range: nfirstel>repeat\n");
+
+ r_8 val[2];
+ fits_read_col(GetFitsPtr(),TDBLCOMPLEX,ColNum+1,n+1,nfirstel+1,1,NULL,val,NULL,&sta);
+ if(sta) {
+   FitsOpenFile::printerror(sta);
+   throw NotAvailableOperation("FitsABTColRd::ReadComplex: Error Reading Fits file\n");
+ }
+ return complex<r_8>(val[0],val[1]);
+}
+
+/*!
+  Read row "n" element "nfirstel" and return in string (internal pointer)
+*/
+char* FitsABTColRd::ReadInStr(LONGLONG n,long nfirstel)
+{
+ int sta=0;
+ if(n<0 || n>=NBline)
+   throw RangeCheckError("FitsABTColRd::ReadInStr try to read outside line range\n");
+ if(nfirstel<0 || nfirstel>=ColRepeat)
+   throw RangeCheckError("FitsABTColRd::ReadInStr try to read outside element range: nfirstel>repeat\n");
+
+ if(StrBuff==NULL) StrBuff= new char[ColDispWidth+5];
+ char nullstr[]="";
+
+ NFitsRead++;
+ fits_read_col(GetFitsPtr(),TSTRING,ColNum+1,n+1,nfirstel+1,1,nullstr,&StrBuff,NULL,&sta);
+ if(sta) {
+   FitsOpenFile::printerror(sta);
+   throw NotAvailableOperation("FitsABTColRd::ReadInStr: Error Reading Fits file\n");
+ }
+
+ return StrBuff;
+}
+
+/*!
   Read rows from "n1" to "n2" and return the values into TVector of double
   \return NREAD the number of values read (n2-n1+1).
@@ -875,4 +925,5 @@
    <<"\n... Label["<<ColNum<<"]="<<ColLabel<<" TypeCode="<<ColTypeCode
    <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<" Repeat="<<ColRepeat
+   <<" DispWidth="<<ColDispWidth
    <<endl;
 }
@@ -993,19 +1044,19 @@
 ///////////////////////////////////////////////////////////////////
 
-FitsABTColRd1F::FitsABTColRd1F(FitsOpenFile* fof,int ihdu,long blen,long bsens,int lp)
-{
-  Init(fof,ihdu,blen,bsens,lp);
+FitsABTColRd1F::FitsABTColRd1F(FitsOpenFile* fof,int ihdu,int lp)
+{
+  Init(fof,ihdu,lp);
 }
 
 /*! Init routine called by the constructor */
-void FitsABTColRd1F::Init(FitsOpenFile* fof,int ihdu,long blen,long bsens,int lp)
+void FitsABTColRd1F::Init(FitsOpenFile* fof,int ihdu,int lp)
 {
  // Initialisation des Parametres Generaux
- ColLabel.resize(0); ColTUnit.resize(0); ColTForm.resize(0); ColTypeCode.resize(0); ColRepeat.resize(0);
+ ColLabel.resize(0); ColTUnit.resize(0); ColTForm.resize(0);
+ ColTypeCode.resize(0); ColRepeat.resize(0); ColDispWidth.resize(0);
+ StrBuff.resize(0);
  NBcol = 0; NBline = 0;
  SetNulVal(); SetDebug(lp);
  FitsOF = NULL;
- LineDeb.resize(0); LineFin.resize(0);
- Buffer = NULL;
 
  // Caracteristiques du FitsOpenFile
@@ -1072,7 +1123,6 @@
    }
    if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode[ColNum]<<endl;
-   if(ColTypeCode[ColNum]==TSTRING || ColTypeCode[ColNum]==TCOMPLEX
-      ||  ColTypeCode[ColNum]==TDBLCOMPLEX || ColTypeCode[ColNum]<0 )
-     throw ParmError("FitsABTColRd1F::Init: Selected column is not Numerical\n");
+   if(ColTypeCode[ColNum]<0 )
+     throw ParmError("FitsABTColRd1F::Init: Selected column type decoding not implemented\n");
    // Get column name, tunit, tform
    char labelcol[128];
@@ -1081,9 +1131,9 @@
    int rc=0;
    if(HDUType()==BINARY_TBL) {
-     fits_get_bcolparmsll(GetFitsPtr(),ColNum+1,labelcol,tunit,tform
+     rc = fits_get_bcolparmsll(GetFitsPtr(),ColNum+1,labelcol,tunit,tform
                        ,&repeat,&tscale,&tzero,NULL,tdisp,&sta);
    } else {
      long repeatlng;
-     fits_get_acolparms(GetFitsPtr(),ColNum+1,labelcol,&repeatlng,tunit,tform
+     rc = fits_get_acolparms(GetFitsPtr(),ColNum+1,labelcol,&repeatlng,tunit,tform
                        ,&tscale,&tzero,NULL,tdisp,&sta);
      repeat = repeatlng;
@@ -1097,18 +1147,19 @@
    ColTForm.push_back(tform);
    ColRepeat.push_back(repeat);
-   // fill the default buffer limits at init
-   LineDeb.push_back(-1);
-   LineFin.push_back(-1);
+
+   int cdispw = 0;
+   fits_get_col_display_width(GetFitsPtr(),ColNum+1,&cdispw,&sta);
+   ColDispWidth.push_back(cdispw);
+   StrBuff.push_back(NULL);
+
    // some debug print if requested
    if(DbgLevel)
      cout<<"FitsABTColRd1F::Init Num="<<ColNum<<" Label="<<ColLabel[ColNum]
-         <<" TypeCode="<<ColTypeCode[ColNum]<<" TUnit="<<ColTUnit[ColNum]<<" TForm="<<ColTForm[ColNum]<<" Repeat="<<ColRepeat[ColNum]<<endl;
+         <<" TypeCode="<<ColTypeCode[ColNum]<<" TUnit="<<ColTUnit[ColNum]<<" TForm="<<ColTForm[ColNum]
+         <<" Repeat="<<ColRepeat[ColNum]<<" ColDispWidth="<<ColDispWidth[ColNum]<<endl;
    if(DbgLevel>1)
      cout<<"      (tscale="<<tscale<<",tzero="<<tzero<<",tdisp="<<tdisp<<")"<<endl;
  }   // ***** ColNum
 
- // Set the buffer for reading
- ChangeBuffer(blen,bsens);
-
 }
 
@@ -1122,43 +1173,10 @@
 void FitsABTColRd1F::Delete(void)
 {
-  if(NBcol>0  && Buffer!=NULL) {
-    for(int ColNum=0; ColNum<NBcol; ColNum++)
-      if(Buffer[ColNum]!=NULL) delete [] Buffer[ColNum];
-    delete [] Buffer; Buffer=NULL;
-  }
- LineDeb.resize(0); LineFin.resize(0);
+  if(NBcol>0) for(int ColNum=0; ColNum<NBcol; ColNum++) {
+      if(StrBuff[ColNum]==NULL) continue;
+      delete [] StrBuff[ColNum];
+      StrBuff[ColNum] = NULL;
+    }
  //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
-}
-
-//////////////////////////////////////////////////////////////
-/*! Change the buffer caracteristiques (see creator) */
-void FitsABTColRd1F::ChangeBuffer(long blen,long bsens)
-{
- long oldnbuffer = NBuffer;
-
- // Compute buffer caracteristics
- BuffLen = (blen<=0)? 1: blen;
- BuffSens = bsens;
- NBuffer = BuffLen;
- if(bsens==0 && NBuffer%2==0) NBuffer++;
-
- // De-allocate if necessary
- if(Buffer!=NULL) {
-   // On des-alloue si pas assez de place
-   // ou si l'ancienne place est beaucoup trop grande (>25%)
-   if(oldnbuffer<NBuffer || (oldnbuffer>NBuffer+long(0.25*NBuffer)) ) {
-     for(int ColNum=0; ColNum<NBcol; ColNum++) if(Buffer[ColNum]!=NULL) delete [] Buffer[ColNum];
-     if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
-   }
- }
-
- // Re-allocate
- if(Buffer==NULL) {
-   Buffer = new double*[NBcol];
-   for(int ColNum=0; ColNum<NBcol; ColNum++) Buffer[ColNum] = new double[NBuffer];
- }
-
- // Tell program that nothing is into buffer
- for(int ColNum=0; ColNum<NBcol; ColNum++) LineDeb[ColNum] = LineFin[ColNum] = -1;
 }
 
@@ -1227,5 +1245,5 @@
   \endverbatim
 */
-double FitsABTColRd1F::Read(int ColNum,LONGLONG n,long nfirstel,bool usebuffer)
+double FitsABTColRd1F::Read(int ColNum,LONGLONG n,long nfirstel)
 // Attention: n=nline [0,NBline[, cfistio veut [1,NBline]
 // Attention: colnum  [0,NBcol[ , cfistio veut [1,NBcol]
@@ -1240,58 +1258,65 @@
    throw RangeCheckError("FitsABTColRd1F::Read try to read outside element range: nfirstel>repeat\n");
 
- // Pas de bufferisation (ou repeat=1), on lit betement
- if(NBuffer==1 || !usebuffer || ColRepeat[ColNum]!=1) {
-   double val;
-   fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n+1,nfirstel+1,1,NULL,&val,NULL,&sta);
-   if(sta) {
-     FitsOpenFile::printerror(sta);
-     throw NotAvailableOperation("FitsABTColRd1F::Read: Error Reading Fits file\n");
-   }
-   // On ne remplit Buffer[ColNum][0] que si on a choisit
-   // un mode de lecture non bufferise (n==1) DES LE DEBUT.
-   // Si on a initialement choisit un mode bufferise (avec n>1),
-   // Buffer contient les valeurs chargees auparavent.
-   // Il ne faut pas faire {Buffer[0]=val; LineDeb=LineFin=n;}
-   // car on perd l'info de ces valeurs.
-   if(NBuffer==1) {Buffer[ColNum][0]=val; LineDeb[ColNum]=LineFin[ColNum]=n;}
-   return val;
- }
-
- // Gestion avec bufferisation (uniquement dans le cas repeat=1)
- if(!Buffer)
-   throw RangeCheckError("FitsABTColRd1F::Read: Buffer not allocated\n");
- if(n<LineDeb[ColNum] || n>LineFin[ColNum]) {
-   LONGLONG row1,row2,nrow;
-   if(BuffSens>0) { // Cas remplissage forward
-     row1 = n+1;
-     row2 = row1+NBuffer-1; if(row2>NBline) row2 = NBline;
-   } else if(BuffSens<0) { // Cas remplissage backward
-     row2 = n+1;
-     row1 = row2-NBuffer+1; if(row1<1) row1 = 1;
-   } else { // Cas remplissage centre
-     row1 = n+1 - NBuffer/2; if(row1<1) row1 = 1;
-     row2 = n+1 + NBuffer/2; if(row2>NBline) row2 = NBline;
-   }
-   nrow = row2 - row1 + 1;
-   LineDeb[ColNum] = row1-1; LineFin[ColNum] = row2-1;
-   //cout<<"DBG-FitsRead: row1="<<row1<<" row2="<<row2<<" nrow="<<nrow
-   //    <<" LineDeb,Fin="<<LineDeb[ColNum]<<","<<LineFin[ColNum]<<endl;
-   fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,row1,1,nrow,NULL,Buffer[ColNum],NULL,&sta);
-   if(sta) {
-     FitsOpenFile::printerror(sta);
-     LineDeb[ColNum] = LineFin[ColNum] = -1;
-     throw NotAvailableOperation("FitsABTColRd1F::Read: Error Reading Fits file\n");
-   }
- }
-
- long ibuf = n-LineDeb[ColNum];
- return Buffer[ColNum][ibuf];
-}
-
+ double val;
+ fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n+1,nfirstel+1,1,NULL,&val,NULL,&sta);
+ if(sta) {
+   FitsOpenFile::printerror(sta);
+   throw NotAvailableOperation("FitsABTColRd1F::Read: Error Reading Fits file\n");
+ }
+ return val;
+}
+
+
+/*!
+  Read row "n" element "nfirstel" and return a complex value
+*/
+complex<r_8> FitsABTColRd1F::ReadComplex(int ColNum,LONGLONG n,long nfirstel)
+{
+ int sta=0;
+ if(ColNum<0 || ColNum>=NBcol)
+   throw RangeCheckError("FitsABTColRd1F::ReadComplex try to read outside column range\n");
+ if(n<0 || n>=NBline)
+   throw RangeCheckError("FitsABTColRd1F::ReadComplex try to read outside line range\n");
+ if(nfirstel<0 || nfirstel>=ColRepeat[ColNum])
+   throw RangeCheckError("FitsABTColRd1F::ReadComplex try to read outside element range: nfirstel>repeat\n");
+
+ r_8 val[2];
+ fits_read_col(GetFitsPtr(),TDBLCOMPLEX,ColNum+1,n+1,nfirstel+1,1,NULL,val,NULL,&sta);
+ if(sta) {
+   FitsOpenFile::printerror(sta);
+   throw NotAvailableOperation("FitsABTColRd1F::ReadComplex: Error Reading Fits file\n");
+ }
+ return complex<r_8>(val[0],val[1]);
+}
+
+/*!
+  Read row "n" element "nfirstel" and return in string (internal pointer)
+*/
+char* FitsABTColRd1F::ReadInStr(int ColNum,LONGLONG n,long nfirstel)
+{
+ int sta=0;
+ if(ColNum<0 || ColNum>=NBcol)
+   throw RangeCheckError("FitsABTColRd1F::ReadInStr try to read outside column range\n");
+ if(n<0 || n>=NBline)
+   throw RangeCheckError("FitsABTColRd1F::ReadInStr try to read outside line range\n");
+ if(nfirstel<0 || nfirstel>=ColRepeat[ColNum])
+   throw RangeCheckError("FitsABTColRd1F::ReadInStr try to read outside element range: nfirstel>repeat\n");
+
+ if(StrBuff[ColNum]==NULL) StrBuff[ColNum] = new char[ColDispWidth[ColNum]+5];
+ char nullstr[]="";
+
+ fits_read_col(GetFitsPtr(),TSTRING,ColNum+1,n+1,nfirstel+1,1,nullstr,&(StrBuff[ColNum]),NULL,&sta);
+ if(sta) {
+   FitsOpenFile::printerror(sta);
+   throw NotAvailableOperation("FitsABTColRd::ReadInStr: Error Reading Fits file\n");
+ }
+
+ return StrBuff[ColNum];
+}
 
 /*! Print on stream os */
 void FitsABTColRd1F::Print(ostream& os,int lp) const
 {
- os<<"FitsABTColRd1F:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
+ os<<"FitsABTColRd1F:Print ("<<NulVal<<")"
    <<" ncols="<<NBcol<<" nrows="<<NBline;
  os<<"\n... "<<FileName()<<"["<<HDU()<<"/"<<NHDU()<<" type="<<HDUType()<<"]"<<endl;
@@ -1299,5 +1324,6 @@
    for(int ColNum=0;ColNum<NBcol;ColNum++) {
      os<<"..Col="<<ColNum<<" Label="<<ColLabel[ColNum]<<" TypeCode="<<ColTypeCode[ColNum]
-       <<" TUnit="<<ColTUnit[ColNum]<<" TForm="<<ColTForm[ColNum]
+       <<" TUnit="<<ColTUnit[ColNum]<<" TForm="<<ColTForm[ColNum]<<" Repeat="<<ColRepeat[ColNum]
+       <<" DispWidth="<<ColDispWidth[ColNum]
        <<endl;
    }
@@ -1316,12 +1342,12 @@
   \warning col = [0,ncol[
 */
-FitsABTColRead1F::FitsABTColRead1F(string fname,int ihdu,long blen,long bsens,int lp)
-: FitsABTColRd1F(new FitsOpenFile(fname),ihdu,blen,bsens,lp)
+FitsABTColRead1F::FitsABTColRead1F(string fname,int ihdu,int lp)
+: FitsABTColRd1F(new FitsOpenFile(fname),ihdu,lp)
 {
 }
 
 /*! Constructor. see below */
-FitsABTColRead1F::FitsABTColRead1F(const char * cfname,int ihdu,long blen,long bsens,int lp)
-: FitsABTColRd1F(new FitsOpenFile(cfname),ihdu,blen,bsens,lp)
+FitsABTColRead1F::FitsABTColRead1F(const char * cfname,int ihdu,int lp)
+: FitsABTColRd1F(new FitsOpenFile(cfname),ihdu,lp)
 {
 }
