Changeset 1507 in Sophya for trunk/SophyaExt/FitsIOServer


Ignore:
Timestamp:
May 22, 2001, 12:22:18 PM (24 years ago)
Author:
cmv
Message:

sens +/0/- et ChangeBuffer pour Fits BT+ASCII reader cmv 22/5/01

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fbtntintf.cc

    r1505 r1507  
    77
    88//////////////////////////////////////////////////////////////
    9 FitsBTNtuIntf::FitsBTNtuIntf(string fname,int ihdu,uint_4 blen,uint_2 lp)
    10 {
    11  BuffLen = (blen==0) ? 100 : blen;
     9FitsBTNtuIntf::FitsBTNtuIntf(string fname,int ihdu
     10               ,int_4 blen,int_4 bsens,uint_2 lp)
     11{
    1212 DbgLevel = lp;
    1313 SetNulVal();
     14 SetBuffer(blen,bsens);
    1415 FitsFN = fname;
    1516 IHdu = ihdu;
     
    1718}
    1819
    19 FitsBTNtuIntf::FitsBTNtuIntf(char * cfname,int ihdu,uint_4 blen,uint_2 lp)
    20 {
    21  BuffLen = (blen==0) ? 100 : blen;
     20FitsBTNtuIntf::FitsBTNtuIntf(char * cfname,int ihdu
     21               ,int_4 blen,int_4 bsens,uint_2 lp)
     22{
    2223 DbgLevel = lp;
    2324 SetNulVal();
     25 SetBuffer(blen,bsens);
    2426 FitsFN = cfname;
    2527 IHdu = ihdu;
     
    2931FitsBTNtuIntf::FitsBTNtuIntf(FitsBTNtuIntf& fbtnt)
    3032{
    31  BuffLen = fbtnt.BuffLen;
    3233 DbgLevel = fbtnt.DbgLevel;
    33  NulVal = fbtnt.NulVal;
     34 SetNulVal(fbtnt.NulVal);
     35 SetBuffer(fbtnt.BuffLen,fbtnt.BuffSens);
    3436 FitsFN = fbtnt.FitsFN;
    3537 IHdu = fbtnt.IHdu;
     
    3941FitsBTNtuIntf::FitsBTNtuIntf()
    4042{
    41  BuffLen = 100;
    4243 DbgLevel = 0;
    4344 SetNulVal();
     45 SetBuffer();
    4446 FitsFN = "";
    4547 IHdu = -1;
     
    5254}
    5355
     56
    5457//////////////////////////////////////////////////////////////
     58void FitsBTNtuIntf::ChangeBuffer(int_4 blen,int_4 bsens)
     59{
     60SetBuffer(blen,bsens);
     61DeAllocBuff();
     62AllocBuff();
     63}
     64
     65void FitsBTNtuIntf::AllocBuff(void)
     66{
     67if(Buffer==NULL || NBcol<=0) return;
     68int_4 n = BuffLen; if(BuffSens==0) n++;
     69for(int icol=0;icol<NBcol;icol++)
     70  if(ColReadable[icol]) Buffer[icol] = new double[n];
     71    else Buffer[icol] = NULL;
     72}
     73
     74void FitsBTNtuIntf::DeAllocBuff(void)
     75{
     76if(Buffer==NULL || NBcol<=0) return;
     77for(int icol=0;icol<NBcol;icol++)
     78  if(Buffer[icol]!=NULL)
     79    {delete [] Buffer[icol]; Buffer[icol] = NULL;}
     80LineDeb = LineFin = -1;
     81}
     82
     83void FitsBTNtuIntf::Delete()
     84{
     85 DeAllocBuff();
     86 delete [] Buffer; Buffer=NULL;
     87 if(mRet!=NULL) delete [] mRet;
     88 if(ColReadable!=NULL) delete [] ColReadable;
     89
     90 int sta = 0;
     91 if(fits_close_file(FitsPtr,&sta)) printerror(sta);
     92 FitsPtr = NULL;
     93}
     94
    5595void FitsBTNtuIntf::Init()
    5696{
     
    134174         <<" typecode="<<typecode<<" (readable="
    135175         <<ColReadable[icol]<<")"<<endl;
    136    // Prepare buffer
    137    if(ColReadable[icol]) Buffer[icol] = new double[BuffLen];
    138  }
    139 
    140 }
    141 
    142 void FitsBTNtuIntf::Delete()
    143 {
    144   if(Buffer!=NULL) {
    145    for(int i=0;i<NBcol;i++)
    146      if(Buffer[i]!=NULL) delete [] Buffer[i];
    147    delete [] Buffer;
    148   }
    149  if(mRet!=NULL) delete [] mRet;
    150  if(ColReadable!=NULL) delete [] ColReadable;
    151 
    152  int sta = 0;
    153  if(fits_close_file(FitsPtr,&sta)) printerror(sta);
    154  FitsPtr = NULL;
     176 }
     177 // Prepare buffer
     178 AllocBuff();
     179
    155180}
    156181
     
    185210
    186211 // Gestion avec bufferisation
     212 if(!Buffer) {
     213   cout<<"FitsBTNtuIntf::GetLineD Buffer not allocated"<<endl;
     214   return NULL;
     215 }
    187216 if(n<LineDeb || n>LineFin) {
    188217   NFitsRead++;
    189    long row1 = n+1;
    190    long row2 = row1+BuffLen-1; if(row2>NBline) row2 = NBline;
    191    long nrow = row2 - row1 + 1;
    192    LineDeb = n; LineFin = row2-1;
     218   long row1,row2,nrow;
     219   if(BuffSens>0) { // Cas remplissage forward
     220     row1 = n+1;
     221     row2 = row1+BuffLen-1; if(row2>NBline) row2 = NBline;
     222   } else if(BuffSens<0) { // Cas remplissage forward
     223     row2 = n+1;
     224     row1 = row2-BuffLen+1; if(row1<1) row1 = 1;
     225   } else { // Cas remplissage centre
     226     row1 = n+1 - BuffLen/2; if(row1<1) row1 = 1;
     227     row2 = n+1 + BuffLen/2; if(row2>NBline) row2 = NBline;
     228   }
     229   nrow = row2 - row1 + 1;
     230   LineDeb = row1-1; LineFin = row2-1;
     231   //cout<<"DBG-FitsRead: row1="<<row1<<" row2="<<row2<<" nrow="<<nrow
     232   //    <<" LineDeb,Fin="<<LineDeb<<","<<LineFin<<endl;
    193233   for(int icol=0;icol<NBcol;icol++) {
    194234     if(!ColReadable[icol]) continue;
     
    198238 }
    199239
     240 int_4 ibuf = n-LineDeb;
    200241 for(int icol=0;icol<NBcol;icol++)
    201    if(ColReadable[icol]) mRet[icol] = (Buffer[icol])[n-LineDeb];
     242   if(ColReadable[icol]) mRet[icol] = (Buffer[icol])[ibuf];
    202243     else mRet[icol] = 0.;
    203244
  • trunk/SophyaExt/FitsIOServer/fbtntintf.h

    r1505 r1507  
    1818class FitsBTNtuIntf : public AnyDataObj, public NTupleInterface {
    1919public:
    20   FitsBTNtuIntf(string fname,int ihdu=0,uint_4 blen=100,uint_2 lp=0);
    21   FitsBTNtuIntf(char *cfname,int ihdu=0,uint_4 blen=100,uint_2 lp=0);
    22   FitsBTNtuIntf(FitsBTNtuIntf& fbtnt); 
     20  FitsBTNtuIntf(string fname,int ihdu=0,int_4 blen=100,int_4 bsens=1,uint_2 lp=0);
     21  FitsBTNtuIntf(char *cfname,int ihdu=0,int_4 blen=100,int_4 bsens=1,uint_2 lp=0);
     22  FitsBTNtuIntf(FitsBTNtuIntf& fbtnt);
    2323  FitsBTNtuIntf();
    2424  virtual ~FitsBTNtuIntf();
    2525
    2626  void SetNulVal(r_8 nulval=0.) {NulVal = nulval;}
     27  void ChangeBuffer(int_4 blen,int_4 bsens=1);
    2728  virtual void Print(ostream& os,int lp=1) const;
    2829  inline  void Print(int lp=1) const {Print(cout,lp);}
     
    3536
    3637protected:
     38  inline void SetBuffer(int_4 blen=100,int_4 bsens=1)
     39       {BuffLen = (blen<=0)?1:blen; BuffSens = bsens;}
     40  void DeAllocBuff(void);
     41  void AllocBuff(void);
    3742  void Init(void);
    3843  void Delete(void);
     
    4651  int  NBcol;
    4752  r_8 NulVal;
    48   uint_4 BuffLen;
     53  int_4 BuffLen, BuffSens;
    4954  mutable uint_4 NFitsRead;
    5055  mutable long LineDeb, LineFin;
Note: See TracChangeset for help on using the changeset viewer.