/* Lecteur de colonne de table Fits (binaire ou ASCII) avec buffer */ #include "machdefs.h" #include #include #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;inhdu 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); NFitsRead = 0; FitsPtr = NULL; LineDeb = LineFin = -1; Buffer = NULL; ChangeBuffer(blen,bsens); ////////////////////////// // Ouverture du fichier // ////////////////////////// int sta=0; if(FitsFN.size() <= 0 ) { IHdu = -1; Delete(); 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 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=" <1) cout<<"...Init NBcol="<1) cout<<"...Init NBline="< 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="<=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="<=NBline) throw RangeCheckError("FitsABTColRead::Read try to read outside line range\n"); // Pas de bufferisation, on lit betement if(NBuffer==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"<LineFin) { NFitsRead++; long 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 = row1-1; LineFin = row2-1; //cout<<"DBG-FitsRead: row1="<& 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()