Changeset 2449 in Sophya


Ignore:
Timestamp:
Oct 29, 2003, 12:17:48 AM (22 years ago)
Author:
cmv
Message:

class FitsABTColRd et FitsABTColRead modifs cmv 29/10/2003

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 edited

Legend:

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

    r2174 r2449  
    55#include "pexceptions.h"
    66#include "fabtcolread.h"
     7
     8///////////////////////////////////////////////////////////////////
     9///////////////////////////////////////////////////////////////////
     10///////////////////////////////////////////////////////////////////
     11///////////////////////////////////////////////////////////////////
     12
     13//! Class for opening a FITS file for reading
     14
     15/*!
     16  \class SOPHYA::FitsOpenFile
     17  \ingroup FitsIOServer
     18  Class for opening a FITS file for reading
     19*/
     20
     21/*!
     22  Constructor.
     23  \param fname : FITS file name to be opened for reading
     24*/
     25FitsOpenFile::FitsOpenFile(string fname)
     26{
     27  Init(fname.c_str());
     28}
     29
     30/*!
     31  Constructor.
     32  \param cfname : FITS file name to be opened for reading
     33*/
     34FitsOpenFile::FitsOpenFile(const char *cfname)
     35{
     36  Init(cfname);
     37}
     38
     39/*!
     40  Constructor by default.
     41*/
     42FitsOpenFile::FitsOpenFile()
     43{
     44  FitsFN = "";
     45  NHdu = -1;
     46  FitsPtr = NULL;
     47}
     48
     49/*!
     50  Constructor by copy.
     51*/
     52FitsOpenFile::FitsOpenFile(FitsOpenFile& fof)
     53{
     54  Init(fof.GetFileName().c_str());
     55}
     56
     57/*!
     58  Destructor.
     59*/
     60FitsOpenFile::~FitsOpenFile()
     61{
     62  Delete();
     63  FitsFN = "";
     64  NHdu = 0;
     65}
     66
     67/*!
     68  Delete routine called by the destructor.
     69*/
     70void FitsOpenFile::Delete(void)
     71{
     72  if(FitsPtr != NULL) {
     73    int sta = 0;
     74    if(fits_close_file(FitsPtr,&sta)) printerror(sta);
     75    FitsPtr = NULL;
     76  }
     77}
     78
     79/*! Init routine called by the constructor */
     80void FitsOpenFile::Init(const char* fname)
     81{
     82   // Parametres Generaux
     83   FitsFN = fname;
     84   NHdu = 0;
     85   FitsPtr = NULL;
     86
     87   // Ouverture du fichier
     88   if(FitsFN.size() <= 0 )
     89      throw ParmError("FitsOpenFile::Init: Fits file name error\n");
     90
     91   int sta = 0;
     92   if(fits_open_file(&FitsPtr,FitsFN.c_str(),READONLY,&sta)) {
     93     printerror(sta);
     94     FitsPtr = NULL;
     95     throw NullPtrError("FitsOpenFile::Init: Error opening Fits file\n");
     96   }
     97
     98   // Get number of hdu
     99   if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
     100     printerror(sta);
     101     NHdu = 0;
     102     Delete();
     103     throw NotAvailableOperation("FitsOpenFile::Init: Error getting NHdu\n");
     104   }
     105   if(NHdu<=0) {
     106     Delete();
     107     throw SzMismatchError("FitsOpenFile::Init: Bad NHdu\n");
     108   }
     109
     110 }
     111
     112 void FitsOpenFile::printerror(int sta) const
     113 {
     114  int stat = sta;
     115  fits_report_error(stdout,stat);
     116  fflush(stdout);
     117  return;
     118 }
     119
     120///////////////////////////////////////////////////////////////////
     121///////////////////////////////////////////////////////////////////
     122///////////////////////////////////////////////////////////////////
     123///////////////////////////////////////////////////////////////////
     124
     125///////////////////////////////////////////////////////////////////
    7126//! Class for reading a column in a FITS ASCII or BINARY table
    8127
    9128/*!
    10   \class SOPHYA::FitsABTColRead
     129  \class SOPHYA::FitsABTColRd
    11130  \ingroup FitsIOServer
    12131  Class for reading a column in a FITS ASCII or BINARY table
    13132  \verbatim
    14133  -- Exemple:
    15   FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3);
     134  // Open the fits file with FitsOpenFile
     135  FitsOpenFile fof = new FitsOpenFile("myfits.fits");
     136  // Select the column to be read
     137  FitsABTColRd fbt(fof,"BoloMuv_28",0,1000,1,3);
    16138  fbt.SetDebug(3);
    17139  fbt.Print(3);
     
    28150  n = fbt.Read(10,-1,data);
    29151    cout<<"Number of values read: "<<n<<endl;
     152  // Close the fits file
     153  delete fof;
    30154  \endverbatim
    31155*/
     
    34158/*!
    35159  Constructor.
    36   \param fname : FITS file name to be read
     160  \param fof : Pointer to the Class for opening the FITS file
    37161  \param collabel : label of the column to be read
    38162  \param ihdu : number of the HDU where the column is.
     
    48172  \warning ihdu = [1,nhdu]
    49173*/
    50 FitsABTColRead::FitsABTColRead(string fname,string collabel
    51                             ,int ihdu,long blen,long bsens,int lp)
    52 {
    53 Init(fname.c_str(),collabel.c_str(),-1,ihdu,blen,bsens,lp);
     174FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,string collabel
     175                          ,int ihdu,long blen,long bsens,int lp)
     176{
     177  Init(fof,collabel.c_str(),-1,ihdu,blen,bsens,lp);
    54178}
    55179
     
    60184  \warning col = [0,ncol[
    61185*/
    62 FitsABTColRead::FitsABTColRead(string fname,int colnum
    63                             ,int ihdu,long blen,long bsens,int lp)
    64 {
    65 Init(fname.c_str(),"",colnum,ihdu,blen,bsens,lp);
    66 }
    67 
    68 /*! Constructor. see below */
    69 FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel
    70                             ,int ihdu,long blen,long bsens,int lp)
    71 {
    72 Init(cfname,collabel,-1,ihdu,blen,bsens,lp);
    73 }
    74 
    75 /*! Constructor. see below */
    76 FitsABTColRead::FitsABTColRead(const char * cfname,int colnum
    77                             ,int ihdu,long blen,long bsens,int lp)
    78 {
    79 Init(cfname,"",colnum,ihdu,blen,bsens,lp);
     186FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,int colnum
     187                          ,int ihdu,long blen,long bsens,int lp)
     188{
     189  Init(fof,"",colnum,ihdu,blen,bsens,lp);
    80190}
    81191
    82192/*! Constructor by copy */
    83 FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt)
    84 {
    85 Init(fbt.GetFileName().c_str(),fbt.GetColLabel().c_str()
    86     ,fbt.GetColNum(),fbt.GetHDU()
    87     ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
     193FitsABTColRd::FitsABTColRd(FitsABTColRd& fbt)
     194{
     195  Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str()
     196      ,fbt.GetColNum(),fbt.GetHDU()
     197      ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
     198}
     199
     200/*! Constructor by default */
     201FitsABTColRd::FitsABTColRd()
     202{
     203 FitsFN = "";
     204 ColLabel = ""; ColTUnit = ""; ColTForm = "";
     205 ColNum = -1; ColTypeCode = 0;
     206 IHdu = 0; NHdu = 0; HduType = 0;
     207 NBcol = 0; NBline = 0;
     208 SetNulVal(); SetDebug(0);
     209 NFitsRead = 0;
     210 FitsOF = NULL; FitsPtr = NULL;
     211 LineDeb = LineFin = -1;
     212 Buffer = NULL;
    88213}
    89214
    90215/*! Init routine called by the constructor */
    91 void FitsABTColRead::Init(const char* fname,const char* collabel,int colnum
     216void FitsABTColRd::Init(FitsOpenFile* fof,const char* collabel,int colnum
    92217                        ,int ihdu,long blen,long bsens,int lp)
    93218{
    94  // Parametres Generaux
    95  FitsFN = fname;
     219 // Initialisation des Parametres Generaux
     220 FitsFN = "";
    96221 ColLabel = collabel;
    97222 ColTUnit = "";
     
    107232 SetDebug(lp);
    108233 NFitsRead = 0;
     234 FitsOF = NULL;
    109235 FitsPtr = NULL;
    110236 LineDeb = LineFin = -1;
     
    112238 ChangeBuffer(blen,bsens);
    113239
    114  //////////////////////////
    115  // Ouverture du fichier //
    116  //////////////////////////
    117 
    118  int sta=0;
    119  if(FitsFN.size() <= 0 ) {
    120    IHdu = -1; Delete();
    121    throw ParmError("FitsABTColRead::Init: Fits file name error\n");
    122  }
    123  const char * cfitsfn = FitsFN.c_str();
    124 
    125  // Open fits
    126  if(fits_open_file(&FitsPtr,cfitsfn,READONLY,&sta)) {
    127    printerror(sta); Delete();
    128    throw NullPtrError("FitsABTColRead::Init: Error opening Fits file\n");
    129  }
    130 
    131  // Get number of hdu
    132  if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
    133    printerror(sta); Delete();
    134    throw NotAvailableOperation("FitsABTColRead::Init: Error getting NHdu\n");
    135  }
    136  if(DbgLevel>1) cout<<"FitsABTColRead::Init  NHdu="<<NHdu<<endl;
     240 // Caracteristiques du FitsOpenFile
     241 FitsOF = fof;
     242 if(FitsOF==NULL) {
     243   Delete();
     244   throw NullPtrError("FitsABTColRd::Init: FitsOpenFile pointer is NULL\n");
     245 }
     246 FitsPtr = FitsOF->GetFitsPtr();
     247 if(FitsPtr==NULL) {
     248   Delete();
     249   throw NullPtrError("FitsABTColRd::Init: FitsPtr pointer is NULL\n");
     250 }
     251 NHdu = FitsOF->GetNHdu();
     252 if(DbgLevel>1) cout<<"FitsABTColRd::Init  NHdu="<<NHdu<<endl;
    137253 if(NHdu<=0) {
    138254   Delete();
    139    throw SzMismatchError("FitsABTColRead::Init: Bad NHdu\n");
    140  }
     255   throw SzMismatchError("FitsABTColRd::Init: Bad NHdu\n");
     256 }
     257 FitsFN = FitsOF->GetFileName();
     258 if(FitsFN.size() <= 0 ) {
     259   Delete();
     260   throw ParmError("FitsABTColRd::Init: Fits file name error\n");
     261 }
     262
     263 int sta = 0;
    141264
    142265 // Get HDU for bin/ascii table
     
    153276   cout<<"NO BINARY or ASCII hdu found"<<endl;
    154277   IHdu = 0; Delete();
    155    throw TypeMismatchExc("FitsABTColRead::Init: NO BINARY or ASCII hdu found\n");
     278   throw TypeMismatchExc("FitsABTColRd::Init: NO BINARY or ASCII hdu found\n");
    156279 }
    157280 if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) {
    158281   printerror(sta); Delete();
    159    throw RangeCheckError("FitsABTColRead::Init: Error moving to requested HDU\n");
     282   throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n");
    160283 }
    161284 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) {
    162285   Delete();
    163    throw TypeMismatchExc("FitsABTColRead::Init: HDU not ASCII/BINARY table\n");
     286   throw TypeMismatchExc("FitsABTColRd::Init: HDU not ASCII/BINARY table\n");
    164287 }
    165288
     
    167290 if(fits_get_num_cols(FitsPtr,&NBcol,&sta)) {
    168291   printerror(sta); Delete();
    169    throw NotAvailableOperation("FitsABTColRead::Init: Error getting number of columns\n");
     292   throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n");
    170293 }
    171294 if(DbgLevel>1) cout<<"...Init  NBcol="<<NBcol<<endl;
    172295 if(NBcol<1) {
    173296   Delete();
    174    throw RangeCheckError("FitsABTColRead::Init: Bad number of colums\n");
     297   throw RangeCheckError("FitsABTColRd::Init: Bad number of colums\n");
    175298 }
    176299
     
    178301 if(fits_get_num_rows(FitsPtr,&NBline,&sta)) {
    179302   printerror(sta); Delete();
    180    throw NotAvailableOperation("FitsABTColRead::Init: Error getting number of rows\n");
     303   throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n");
    181304 }
    182305 if(DbgLevel>1) cout<<"...Init  NBline="<<NBline<<endl;
    183306 if(NBline<1) {
    184307   Delete();
    185    throw RangeCheckError("FitsABTColRead::Init: Bad number of rows\n");
     308   throw RangeCheckError("FitsABTColRd::Init: Bad number of rows\n");
    186309 }
    187310
     
    192315   if(fits_get_colnum(FitsPtr,CASESEN,labelcol,&ColNum,&sta)) {
    193316     printerror(sta); Delete();
    194      throw NotAvailableOperation("FitsABTColRead::Init: Error getting column name\n");
     317     throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n");
    195318   }
    196319   ColNum--;  // Convention [0,ncol[
     
    199322 if(ColNum<0 || ColNum>=NBcol) {
    200323   Delete();
    201    throw RangeCheckError("FitsABTColRead::Init: Bad column number\n");
     324   throw RangeCheckError("FitsABTColRd::Init: Bad column number\n");
    202325 }
    203326
     
    205328 if(fits_get_coltype(FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) {
    206329   printerror(sta); Delete();
    207    throw ParmError("FitsABTColRead::Init: Error getting column type\n");
     330   throw ParmError("FitsABTColRd::Init: Error getting column type\n");
    208331 }
    209332 if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl;
     
    211334                         || ColTypeCode<0 ) {
    212335   Delete();
    213    throw ParmError("FitsABTColRead::Init: Selected column is not Numerical\n");
     336   throw ParmError("FitsABTColRd::Init: Selected column is not Numerical\n");
    214337 }
    215338
     
    227350 if(rc) {
    228351   printerror(sta); Delete();
    229    throw RangeCheckError("FitsABTColRead::Init: Error getting the column caracteristics\n");
     352   throw RangeCheckError("FitsABTColRd::Init: Error getting the column caracteristics\n");
    230353 }
    231354 ColLabel = labelcol;
     
    234357
    235358 if(DbgLevel)
    236    cout<<"FitsABTColRead::Init Num="<<ColNum<<" Label="<<ColLabel
     359   cout<<"FitsABTColRd::Init Num="<<ColNum<<" Label="<<ColLabel
    237360       <<" TypeCode="<<ColTypeCode<<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl;
    238361 if(DbgLevel>1)
     
    243366
    244367/*! Destructor. */
    245 FitsABTColRead::~FitsABTColRead()
     368FitsABTColRd::~FitsABTColRd()
    246369{
    247370 Delete();
    248371}
    249372
    250 //////////////////////////////////////////////////////////////
    251 double FitsABTColRead::ReadKey(char *keyname)
    252 {
    253  if(keyname==NULL) return 0.;
    254  int sta=0; double val=0.;
    255  if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta))
    256    printerror(sta);
    257  return val;
     373/*! Delete called by the destructor */
     374void FitsABTColRd::Delete(void)
     375{
     376 if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
     377 LineDeb = LineFin = -1;
     378 //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
    258379}
    259380
    260381//////////////////////////////////////////////////////////////
    261382/*! Change the buffer caracteristiques (see creator) */
    262 void FitsABTColRead::ChangeBuffer(long blen,long bsens)
     383void FitsABTColRd::ChangeBuffer(long blen,long bsens)
    263384{
    264385 long oldnbuffer = NBuffer;
     
    285406}
    286407
    287 /*! Delete called by the destructor */
    288 void FitsABTColRead::Delete()
    289 {
    290  if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
    291  LineDeb = LineFin = -1;
    292  int sta = 0;
    293  if(fits_close_file(FitsPtr,&sta)) printerror(sta);
    294  FitsPtr = NULL;
     408//////////////////////////////////////////////////////////////
     409double FitsABTColRd::ReadKey(char *keyname)
     410{
     411 if(keyname==NULL) return 0.;
     412 int sta=0; double val=0.;
     413 if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta))
     414   printerror(sta);
     415 return val;
    295416}
    296417
     
    307428  \endverbatim
    308429*/
    309 double FitsABTColRead::Read(long n,bool usebuffer)
     430double FitsABTColRd::Read(long n,bool usebuffer)
    310431// Attention: n=nline [0,NBline[, cfistio veut [1,NBline]
    311432// Attention: colnum  [0,NBcol[ , cfistio veut [1,NBcol]
     
    313434 int sta=0;
    314435 if(n<0 || n>=NBline)
    315    throw RangeCheckError("FitsABTColRead::Read try to read outside line range\n");
     436   throw RangeCheckError("FitsABTColRd::Read try to read outside line range\n");
    316437
    317438 // Pas de bufferisation, on lit betement
     
    322443   if(sta) {
    323444     printerror(sta);
    324      throw NotAvailableOperation("FitsABTColRead::Read: Error Reading Fits file\n");
     445     throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n");
    325446   }
    326447   // On ne remplit Buffer[0] que si on a choisit
     
    336457 // Gestion avec bufferisation
    337458 if(!Buffer)
    338    throw RangeCheckError("FitsABTColRead::Read: Buffer not allocated\n");
     459   throw RangeCheckError("FitsABTColRd::Read: Buffer not allocated\n");
    339460 if(n<LineDeb || n>LineFin) {
    340461   NFitsRead++;
     
    358479     printerror(sta);
    359480     LineDeb = LineFin = -1;
    360      throw NotAvailableOperation("FitsABTColRead::Read: Error Reading Fits file\n");
     481     throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n");
    361482   }
    362483 }
     
    398519  \endverbatim
    399520*/
    400 long FitsABTColRead::Read(long n1,long n2,TVector<double>& data)
     521long FitsABTColRd::Read(long n1,long n2,TVector<double>& data)
    401522{
    402523 if(n1<0 || n1>=NBline)
    403    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
     524   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
    404525 if(data.Size()<=0 && n2<n1)
    405    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
     526   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
    406527 if(n2<0) n2 = n1 + data.Size()-1;
    407528 if(n2>=NBline) n2 = NBline-1;
     
    415536 if(sta) {
    416537   printerror(sta);
    417    throw NotAvailableOperation("FitsABTColRead::Read_TVector<double>: Error Reading Fits file\n");
     538   throw NotAvailableOperation("FitsABTColRd::Read_TVector<double>: Error Reading Fits file\n");
    418539 }
    419540
     
    422543
    423544/*! idem before but for TVector of float */
    424 long FitsABTColRead::Read(long n1,long n2,TVector<float>& data)
     545long FitsABTColRd::Read(long n1,long n2,TVector<float>& data)
    425546{
    426547 if(n1<0 || n1>=NBline)
    427    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
     548   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
    428549 if(data.Size()<=0 && n2<n1)
    429    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
     550   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
    430551 if(n2<0) n2 = n1 + data.Size()-1;
    431552 if(n2>=NBline) n2 = NBline-1;
     
    439560 if(sta) {
    440561   printerror(sta);
    441    throw NotAvailableOperation("FitsABTColRead::Read_TVector<float>: Error Reading Fits file\n");
     562   throw NotAvailableOperation("FitsABTColRd::Read_TVector<float>: Error Reading Fits file\n");
    442563 }
    443564
     
    446567
    447568/*! idem before but for TVector of unsigned short */
    448 long FitsABTColRead::Read(long n1,long n2,TVector<uint_2>& data)
     569long FitsABTColRd::Read(long n1,long n2,TVector<uint_2>& data)
    449570{
    450571 if(n1<0 || n1>=NBline)
    451    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
     572   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
    452573 if(data.Size()<=0 && n2<n1)
    453    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
     574   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
    454575 if(n2<0) n2 = n1 + data.Size()-1;
    455576 if(n2>=NBline) n2 = NBline-1;
     
    462583 if(sta) {
    463584   printerror(sta);
    464    throw NotAvailableOperation("FitsABTColRead::Read_TVector<uint_2>: Error Reading Fits file\n");
     585   throw NotAvailableOperation("FitsABTColRd::Read_TVector<uint_2>: Error Reading Fits file\n");
    465586 }
    466587
     
    469590
    470591/*! idem before but for TVector of int_4 */
    471 long FitsABTColRead::Read(long n1,long n2,TVector<int_4>& data)
     592long FitsABTColRd::Read(long n1,long n2,TVector<int_4>& data)
    472593{
    473594 if(n1<0 || n1>=NBline)
    474    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
     595   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
    475596 if(data.Size()<=0 && n2<n1)
    476    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
     597   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
    477598 if(n2<0) n2 = n1 + data.Size()-1;
    478599 if(n2>=NBline) n2 = NBline-1;
     
    487608 if(sta) {
    488609   printerror(sta);
    489    throw NotAvailableOperation("FitsABTColRead::Read_TVector<int_4>: Error Reading Fits file\n");
     610   throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_4>: Error Reading Fits file\n");
    490611 }
    491612
     
    494615
    495616/*! idem before but for TVector of int_8 */
    496 long FitsABTColRead::Read(long n1,long n2,TVector<int_8>& data)
     617long FitsABTColRd::Read(long n1,long n2,TVector<int_8>& data)
    497618{
    498619#ifdef TLONGLONG
    499620 if(n1<0 || n1>=NBline)
    500    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 1srt line \n");
     621   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
    501622 if(data.Size()<=0 && n2<n1)
    502    throw RangeCheckError("FitsABTColRead::Read TVector bad requested 2sd line \n");
     623   throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
    503624 if(n2<0) n2 = n1 + data.Size()-1;
    504625 if(n2>=NBline) n2 = NBline-1;
     
    511632 if(sta) {
    512633   printerror(sta);
    513    throw NotAvailableOperation("FitsABTColRead::Read_TVector<int_8>: Error Reading Fits file\n");
     634   throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_8>: Error Reading Fits file\n");
    514635 }
    515636
    516637 return nread;
    517638#else
    518   throw PException("FitsABTColRead::Read(..,TVector<int_8>&) Not in that cfitsio version");
     639  throw PException("FitsABTColRd::Read(..,TVector<int_8>&) Not in that cfitsio version");
    519640#endif
    520641}
     
    531652  \return <0 means not found
    532653*/
    533 long FitsABTColRead::FirstRow(double val1,double val2,long rowstart)
     654long FitsABTColRd::FirstRow(double val1,double val2,long rowstart)
    534655{
    535656 long row = -1;
     
    560681  \endverbatim
    561682*/
    562 long FitsABTColRead::LastRow(double val1,double val2,long rowstart)
     683long FitsABTColRd::LastRow(double val1,double val2,long rowstart)
    563684{
    564685 long row = -1;
     
    579700
    580701/////////////////////////////////////////////////
    581 void FitsABTColRead::printerror(int sta) const
     702void FitsABTColRd::printerror(int sta) const
    582703{
    583704 int stat = sta;
     
    588709
    589710/*! Print on stream os */
    590 void FitsABTColRead::Print(ostream& os,int lp) const
    591 {
    592  os<<"FitsABTColRead:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
     711void FitsABTColRd::Print(ostream& os,int lp) const
     712{
     713 os<<"FitsABTColRd:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
    593714   <<" ncols="<<NBcol<<" nrows="<<NBline;
    594715 if(lp>0) os<<" NRead="<<NFitsRead;
     
    599720   <<endl;
    600721}
     722
     723///////////////////////////////////////////////////////////////////
     724///////////////////////////////////////////////////////////////////
     725///////////////////////////////////////////////////////////////////
     726///////////////////////////////////////////////////////////////////
     727
     728//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
     729
     730/*!
     731  \class SOPHYA::FitsABTColRead
     732  \ingroup FitsIOServer
     733  Class for reading a column in a FITS ASCII or BINARY table with fits file opening
     734  \verbatim
     735  -- Exemple:
     736  FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3);
     737  fbt.SetDebug(3);
     738  fbt.Print(3);
     739  // Read element by element
     740  for(long i=0;i<fbt.GetNbLine();i++) {
     741    double x = fbt.Read(i);
     742    if(i%lpmod==0) cout<<i<<": "<<x<<endl;
     743  }
     744  // Read into a vector
     745  TVector<double> data;
     746  long n = fbt.Read(32,50,data);
     747    cout<<"Number of values read: "<<n<<endl;
     748  data.ReSize(100);
     749  n = fbt.Read(10,-1,data);
     750    cout<<"Number of values read: "<<n<<endl;
     751  \endverbatim
     752*/
     753
     754
     755//////////////////////////////////////////////////////////////
     756/*!
     757  Constructor.
     758  \param fname : FITS file name to be read
     759  \param collabel : label of the column to be read
     760  \param ihdu : number of the HDU where the column is.
     761  \param blen : read buffer length
     762  \param bsens : buffer reading direction
     763  \param lp : debug level
     764  \verbatim
     765  - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken
     766  - bsens>0    read forward
     767    bsens<0    read backward
     768    bsens==0   read centered
     769  \endverbatim
     770  \warning ihdu = [1,nhdu]
     771*/
     772FitsABTColRead::FitsABTColRead(string fname,string collabel
     773                              ,int ihdu,long blen,long bsens,int lp)
     774: FitsABTColRd(new FitsOpenFile(fname),collabel,ihdu,blen,bsens,lp)
     775{
     776}
     777
     778/*!
     779  Constructor.
     780  Same as before but the column is identified by its column number
     781  \param colnum : number of the column to be read
     782  \warning col = [0,ncol[
     783*/
     784FitsABTColRead::FitsABTColRead(string fname,int colnum
     785                              ,int ihdu,long blen,long bsens,int lp)
     786: FitsABTColRd(new FitsOpenFile(fname),colnum,ihdu,blen,bsens,lp)
     787{
     788}
     789
     790/*! Constructor. see below */
     791FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel
     792                              ,int ihdu,long blen,long bsens,int lp)
     793: FitsABTColRd(new FitsOpenFile(cfname),collabel,ihdu,blen,bsens,lp)
     794{
     795}
     796
     797/*! Constructor. see below */
     798FitsABTColRead::FitsABTColRead(const char * cfname,int colnum
     799                              ,int ihdu,long blen,long bsens,int lp)
     800: FitsABTColRd(new FitsOpenFile(cfname),colnum,ihdu,blen,bsens,lp)
     801{
     802}
     803/*! Constructor by default */
     804FitsABTColRead::FitsABTColRead()
     805{
     806}
     807
     808/*! Constructor by copy */
     809FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt)
     810{
     811 // --- ATTENTION ---
     812 // FitsABTColRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
     813 FitsOpenFile* fof = new FitsOpenFile(*fbt.GetFitsOpenFile());
     814 Init(fof,fbt.GetColLabel().c_str()
     815     ,fbt.GetColNum(),fbt.GetHDU()
     816     ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
     817}
     818
     819/*! Destructor. */
     820FitsABTColRead::~FitsABTColRead()
     821{
     822 Delete();
     823 if(FitsOF!=NULL) delete FitsOF;
     824}
  • trunk/SophyaExt/FitsIOServer/fabtcolread.h

    r2322 r2449  
    1414namespace SOPHYA {
    1515
     16///////////////////////////////////////////////////////////////////
     17//! Class for opening a FITS file for reading
     18class FitsOpenFile : public AnyDataObj {
     19public:
     20  FitsOpenFile(string fname);
     21  FitsOpenFile(const char *cfname);
     22  FitsOpenFile();
     23  FitsOpenFile(FitsOpenFile& fof);
     24  virtual ~FitsOpenFile();
     25
     26  inline string GetFileName() {return FitsFN;}
     27  inline int GetNHdu() {return NHdu;}
     28  inline fitsfile* GetFitsPtr() {return FitsPtr;}
     29
     30protected:
     31  void Init(const char *cfname);
     32  void Delete(void);
     33  void printerror(int sta) const;
     34
     35  string FitsFN;
     36  int NHdu;
     37  fitsfile *FitsPtr;
     38};
     39
     40///////////////////////////////////////////////////////////////////
    1641//! Class for reading a column in a FITS ASCII or BINARY table
    17 class FitsABTColRead : public AnyDataObj {
     42class FitsABTColRd : public AnyDataObj {
    1843public:
    19   FitsABTColRead(string fname,string collabel,int ihdu=0
    20                 ,long blen=100,long bsens=1,int lp=0);
    21   FitsABTColRead(string fname,int colnum,int ihdu=0
    22                 ,long blen=100,long bsens=1,int lp=0);
    23   FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
    24                 ,long blen=100,long bsens=1,int lp=0);
    25   FitsABTColRead(const char *cfname,int colnum,int ihdu=0
    26                 ,long blen=100,long bsens=1,int lp=0);
    27   FitsABTColRead(FitsABTColRead& fbt);
    28   virtual ~FitsABTColRead();
     44  FitsABTColRd(FitsOpenFile* fof,string collabel,int ihdu=0
     45              ,long blen=100,long bsens=1,int lp=0);
     46  FitsABTColRd(FitsOpenFile* fof,int colnum,int ihdu=0
     47              ,long blen=100,long bsens=1,int lp=0);
     48  FitsABTColRd(FitsABTColRd& fbt);
     49  FitsABTColRd();
     50  virtual ~FitsABTColRd();
    2951
    3052  void ChangeBuffer(long blen=100,long bsens=1);
     
    5678  //! Get the FITS file name
    5779  inline string  GetFileName(void) {return FitsFN;}
     80  //! Get the pointer to FitsOpenFile
     81  inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;}
    5882  //! Get the FITS file pointer (cfistio pointer)
    5983  inline fitsfile* GetFitsPointer(void) {return FitsPtr;}
     
    92116
    93117protected:
    94   void Init(const char *cfname,const char *collabel,int colnum
     118  void Init(FitsOpenFile* fof,const char *collabel,int colnum
    95119           ,int ihdu,long blen,long bsens,int lp);
    96120  void Delete(void);
     
    106130
    107131  unsigned long NFitsRead;
    108   fitsfile *FitsPtr;
     132  FitsOpenFile* FitsOF;
     133  fitsfile* FitsPtr;
    109134  long LineDeb, LineFin;
    110135  double *Buffer;
     
    112137};
    113138
     139///////////////////////////////////////////////////////////////////
     140//! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
     141class FitsABTColRead : public FitsABTColRd {
     142public:
     143  FitsABTColRead(string fname,string collabel,int ihdu=0
     144                ,long blen=100,long bsens=1,int lp=0);
     145  FitsABTColRead(string fname,int colnum,int ihdu=0
     146                ,long blen=100,long bsens=1,int lp=0);
     147  FitsABTColRead(const char *cfname,const char *collabel,int ihdu=0
     148                ,long blen=100,long bsens=1,int lp=0);
     149  FitsABTColRead(const char *cfname,int colnum,int ihdu=0
     150                ,long blen=100,long bsens=1,int lp=0);
     151  FitsABTColRead(FitsABTColRead& fbt);
     152  FitsABTColRead();
     153  virtual ~FitsABTColRead();
     154};
     155
    114156} // namespace SOPHYA
    115157#endif    /* FABTCOLREAD_H_SEEN */
Note: See TracChangeset for help on using the changeset viewer.