From ddd6fc57c9d861b16524c3d4ced6a9f3f6623f7b Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sat, 23 Nov 2013 01:54:17 +0100 Subject: [PATCH] Revise GFitsTable class interface. --- NEWS | 6 ++++++ doc/source/user_manual/modules/fits.rst | 2 +- examples/cpp/createfits/createfits.cpp | 2 +- include/GFitsTable.hpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- inst/cta/src/GCTAAeffArf.cpp | 6 +++--- inst/cta/src/GCTAEventList.cpp | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------- inst/cta/src/GCTAPsfVector.cpp | 8 ++++---- inst/cta/src/GCTAResponseTable.cpp | 8 ++++---- inst/lat/src/GLATAeff.cpp | 6 +++--- inst/lat/src/GLATEdisp.cpp | 8 ++++---- inst/lat/src/GLATEventList.cpp | 32 ++++++++++++++++---------------- inst/lat/src/GLATPsfBase.cpp | 10 +++++----- inst/lat/src/GLATPsfV1.cpp | 16 ++++++++-------- inst/lat/src/GLATPsfV3.cpp | 24 ++++++++++++------------ inst/lat/src/GLATResponseTable.cpp | 18 +++++++++--------- inst/mwl/src/GMWLSpectrum.cpp | 32 ++++++++++++++++++-------------- pyext/GFitsTable.i | 30 +++++++++++++++++------------- src/fits/GFitsTable.cpp | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- src/obs/GEbounds.cpp | 8 ++++---- src/obs/GEnergies.cpp | 6 +++--- src/obs/GGti.cpp | 8 ++++---- src/sky/GSkymap.cpp | 6 +++--- src/xspec/GArf.cpp | 12 ++++++------ src/xspec/GPha.cpp | 20 ++++++++++---------- src/xspec/GRmf.cpp | 24 ++++++++++++------------ test/test_GFits.cpp | 56 ++++++++++++++++++++++++++++---------------------------- test/test_GFits.py | 44 ++++++++++++++++++++++---------------------- 27 files changed, 543 insertions(+), 365 deletions(-) diff --git a/NEWS b/NEWS index 5acda09..6f085e6 100644 --- a/NEWS +++ b/NEWS @@ -102,6 +102,12 @@ GOptimizer & GOptimizerLM The optimization operators have been removed and replaced by the optimize method. +GFitsTable + The column table operator[] now returns a pointer instead of a + reference. Set set() method has been added for column setting. + The append_column() and insert_column() methods have been + renamed to append() and insert(). + All GammaLib constants, defined in GTools.hpp, and functions are now put in the gammalib namespace to avoid name clashes. Mathematical constants and functions have been moved to a new model named GMath. diff --git a/doc/source/user_manual/modules/fits.rst b/doc/source/user_manual/modules/fits.rst index 0ad208b..bb42abd 100644 --- a/doc/source/user_manual/modules/fits.rst +++ b/doc/source/user_manual/modules/fits.rst @@ -1 +1 @@ -.. _sec_fits: FITS file interface ------------------- Overview ~~~~~~~~ :ref:`fig_uml_fits` present an overview over the C++ classes of the FITS module and their relations. .. _fig_uml_fits: .. figure:: uml_fits.png :width: 100% FITS module The FITS module provides a high-level interface to FITS files. The module is based on the cfitsio library for file access. The C++ classes of the module implement a logical representation of the FITS file in memory that can be handled independently of the file representation on disk. The central class of the FITS module is the ``GFits`` class that represents a FITS file. The class is a container for classes derived from the abstract ``GFitsHDU`` base class which represents a FITS extension (also called Header-Data Unit, HDU). Each extension is composed of one header, implemented by the ``GFitsHeader`` class and one data unit. The header is composed of cards representing the meta-data of the fits file. The cards are implemented by the ``GFitsHeaderCard`` class. The data unit is either an image, represented by the abstract ``GFitsImage`` base class, or a table, represented by the abstract ``GFitsTable`` base class. The image can be stored in various data types, each of which is implemented by a specific class derived from ``GFitsImage``. The table can be either an ASCII table, implemented by the ``GFitsASCIITable`` class or a binary table, implemented by the ``GFitsBinTable`` class. Each table is comprised of columns, represented by the abstract ``GFitsTableCol`` base class. This class is the same for ASCII and binary tables. Similar to images, table column data can be stored in a variety of data types, each of which is implemented by a specific class derived from ``GFitsTableCol``. Creating a FITS file ~~~~~~~~~~~~~~~~~~~~ The following example illustrates the creation of a FITS file comprising one image and one table (see ``examples/createfits.cpp`` for the source code; the line numbers are for reference and are not part of the source code):: 1 GFits fits; 2 GFitsImageDouble image(20,10); 3 for (int x = 0; x < 20; ++x) { 4 for (int y = 0; y < 10; ++y) { 5 image(x,y) = x+100.0*y; 6 } 7 } 8 fits.append(image); 9 GFitsBinTable table; 10 GFitsTableDoubleCol column("ENERGY", 10, 3); 11 for (int row = 0; row < 10; ++row) { 12 for (int index = 0; index < 3; ++index) { 13 column(row, index) = row*100.0+index; 14 } 15 } 16 table.append_column(column); 17 fits.append(table); 18 fits.saveto("my_fits_file.fits", true); 19 fits.close(); In line 1, a FITS object is allocated in memory. An image is created in line 2, comprising 20 pixels in the x-direction and 10 pixels in the y-direction, each pixel being a double precision value. Lines 3-7 fill the image by a nested loop over all pixels. The image is then appended to the FITS object in line 8. In line 9, a binary table is created. A column comprising double precision values is created in line 10. The name of the column is set to ``ENERGY``, and comprises 10 rows, each of which is composed of a 3-element vector. This so-called vector column is filled by the nested loop in lines 11-15. In line 16, the column is appended to the binary table, which in turn is appended to the FITS object in line 17. In line 18, the FITS object is saved into the file ``my_fits_file.fits``. The (optional) argument ``true`` indicates that any existing file with the same name will be overwritten (by default, an attempt to overwrite an existing file will lead to an exception, hence if overwriting is desired it has to be explicitly specified). In line 19, the FITS object is closed, implying that all memory related to the object is deallocated. Note that saving of a FITS object does not close the object itself; it continues to exist in memory and can be manipulated further, independently of the FITS file on disk. Line 19 could however be omitted, as a FITS object is automatically closed upon destruction of the object. Note also that up to line 17, the FITS object only exists in memory. The FITS file on disk is only created in line 18. Alternatively, one could have written:: 1 GFits fits("my_fits_file.fits", true); ... 18 fits.save(true); Here, the FITS file on disk is created in line 1. The (optional) ``true`` argument specifies that the FITS file should be created if it does not yet exist. By default, this argument is set to ``false``, and an exception is raised when creating the ``GFits`` object. If a file exists already, line 1 will in fact open the file, and lines 2-17 will add an image and a table *in addition* to the image and table that exists already in the file. Line 1 is in fact identical to:: GFits fits; fits.open("my_fits_file.fits", true); hence it creates an instance of the ``GFits`` object and then opens the file ``my_fits_file.fits``. Line 18 then saves the FITS file taking into account the modifications that have been made. Note that only at this point the modifications will be written to disk. The ``save`` method does not take any filename as it saves a file that has been opened before. It takes however the (optional) clobber flag that specifies whether a file should be overwritten or not (as for the ``saveto`` method this flag is set to ``false`` by default). Note that one can also combine file opening with the ``saveto`` method to create a copy of the FITS file. Specifying:: 1 GFits fits("my_fits_file.fits", true); ... 18 fits.saveto("my_fits_file2.fits", true); will open the file ``my_fits_file.fits`` and save the FITS object after the manipulations of line 2-17 into the file ``my_fits_file2.fits``. A final word on the ``append`` and ``append_column`` methods that are used in the example to append the image and tables to the FITS object, and the column to the binary table. These methods will append a *copy* of the object to the FITS object, hence after appending, any manipulations on the original object will not be reflected in the FITS object. If an object should be manipulated after it has been appended, a pointer to the object has to be retrieved from the FITS object using:: GFitsImage* image = fits.image(0); GFitsTable* table = fits.table(1); GFitsTableCol* column = (*table)["ENERGY"]; For reference, a screen capture of the FITS file that is created by the above example is shown below. .. _fig_fits_example: .. figure:: fits_example.png :width: 100% FITS file example \ No newline at end of file +.. _sec_fits: FITS file interface ------------------- Overview ~~~~~~~~ :ref:`fig_uml_fits` present an overview over the C++ classes of the FITS module and their relations. .. _fig_uml_fits: .. figure:: uml_fits.png :width: 100% FITS module The FITS module provides a high-level interface to FITS files. The module is based on the cfitsio library for file access. The C++ classes of the module implement a logical representation of the FITS file in memory that can be handled independently of the file representation on disk. The central class of the FITS module is the ``GFits`` class that represents a FITS file. The class is a container for classes derived from the abstract ``GFitsHDU`` base class which represents a FITS extension (also called Header-Data Unit, HDU). Each extension is composed of one header, implemented by the ``GFitsHeader`` class and one data unit. The header is composed of cards representing the meta-data of the fits file. The cards are implemented by the ``GFitsHeaderCard`` class. The data unit is either an image, represented by the abstract ``GFitsImage`` base class, or a table, represented by the abstract ``GFitsTable`` base class. The image can be stored in various data types, each of which is implemented by a specific class derived from ``GFitsImage``. The table can be either an ASCII table, implemented by the ``GFitsASCIITable`` class or a binary table, implemented by the ``GFitsBinTable`` class. Each table is comprised of columns, represented by the abstract ``GFitsTableCol`` base class. This class is the same for ASCII and binary tables. Similar to images, table column data can be stored in a variety of data types, each of which is implemented by a specific class derived from ``GFitsTableCol``. Creating a FITS file ~~~~~~~~~~~~~~~~~~~~ The following example illustrates the creation of a FITS file comprising one image and one table (see ``examples/createfits.cpp`` for the source code; the line numbers are for reference and are not part of the source code):: 1 GFits fits; 2 GFitsImageDouble image(20,10); 3 for (int x = 0; x < 20; ++x) { 4 for (int y = 0; y < 10; ++y) { 5 image(x,y) = x+100.0*y; 6 } 7 } 8 fits.append(image); 9 GFitsBinTable table; 10 GFitsTableDoubleCol column("ENERGY", 10, 3); 11 for (int row = 0; row < 10; ++row) { 12 for (int index = 0; index < 3; ++index) { 13 column(row, index) = row*100.0+index; 14 } 15 } 16 table.append(column); 17 fits.append(table); 18 fits.saveto("my_fits_file.fits", true); 19 fits.close(); In line 1, a FITS object is allocated in memory. An image is created in line 2, comprising 20 pixels in the x-direction and 10 pixels in the y-direction, each pixel being a double precision value. Lines 3-7 fill the image by a nested loop over all pixels. The image is then appended to the FITS object in line 8. In line 9, a binary table is created. A column comprising double precision values is created in line 10. The name of the column is set to ``ENERGY``, and comprises 10 rows, each of which is composed of a 3-element vector. This so-called vector column is filled by the nested loop in lines 11-15. In line 16, the column is appended to the binary table, which in turn is appended to the FITS object in line 17. In line 18, the FITS object is saved into the file ``my_fits_file.fits``. The (optional) argument ``true`` indicates that any existing file with the same name will be overwritten (by default, an attempt to overwrite an existing file will lead to an exception, hence if overwriting is desired it has to be explicitly specified). In line 19, the FITS object is closed, implying that all memory related to the object is deallocated. Note that saving of a FITS object does not close the object itself; it continues to exist in memory and can be manipulated further, independently of the FITS file on disk. Line 19 could however be omitted, as a FITS object is automatically closed upon destruction of the object. Note also that up to line 17, the FITS object only exists in memory. The FITS file on disk is only created in line 18. Alternatively, one could have written:: 1 GFits fits("my_fits_file.fits", true); ... 18 fits.save(true); Here, the FITS file on disk is created in line 1. The (optional) ``true`` argument specifies that the FITS file should be created if it does not yet exist. By default, this argument is set to ``false``, and an exception is raised when creating the ``GFits`` object. If a file exists already, line 1 will in fact open the file, and lines 2-17 will add an image and a table *in addition* to the image and table that exists already in the file. Line 1 is in fact identical to:: GFits fits; fits.open("my_fits_file.fits", true); hence it creates an instance of the ``GFits`` object and then opens the file ``my_fits_file.fits``. Line 18 then saves the FITS file taking into account the modifications that have been made. Note that only at this point the modifications will be written to disk. The ``save`` method does not take any filename as it saves a file that has been opened before. It takes however the (optional) clobber flag that specifies whether a file should be overwritten or not (as for the ``saveto`` method this flag is set to ``false`` by default). Note that one can also combine file opening with the ``saveto`` method to create a copy of the FITS file. Specifying:: 1 GFits fits("my_fits_file.fits", true); ... 18 fits.saveto("my_fits_file2.fits", true); will open the file ``my_fits_file.fits`` and save the FITS object after the manipulations of line 2-17 into the file ``my_fits_file2.fits``. A final word on the ``append`` methods that are used in the example to append the image and tables to the FITS object, and the column to the binary table. These methods will append a *copy* of the object to the FITS object, hence after appending, any manipulations on the original object will not be reflected in the FITS object. If an object should be manipulated after it has been appended, a pointer to the object has to be retrieved from the FITS object using:: GFitsImage* image = fits.image(0); GFitsTable* table = fits.table(1); GFitsTableCol* column = (*table)["ENERGY"]; For reference, a screen capture of the FITS file that is created by the above example is shown below. .. _fig_fits_example: .. figure:: fits_example.png :width: 100% FITS file example \ No newline at end of file diff --git a/examples/cpp/createfits/createfits.cpp b/examples/cpp/createfits/createfits.cpp index 5e2f09d..92a2c54 100644 --- a/examples/cpp/createfits/createfits.cpp +++ b/examples/cpp/createfits/createfits.cpp @@ -57,7 +57,7 @@ int main(void) { column(row, index) = row*100.0+index; } } - table.append_column(column); + table.append(column); // Append table to FITS object fits.append(table); diff --git a/include/GFitsTable.hpp b/include/GFitsTable.hpp index b78c226..f3ef1a0 100644 --- a/include/GFitsTable.hpp +++ b/include/GFitsTable.hpp @@ -41,23 +41,23 @@ * is a collection of columns with an identical number of rows. This class * provides high level access to table columns. * - * @todo Implement remove_column method + * @todo Implement remove() method ***************************************************************************/ class GFitsTable : public GFitsHDU { public: // Constructors and destructors GFitsTable(void); - explicit GFitsTable(int nrows); + explicit GFitsTable(const int& nrows); GFitsTable(const GFitsTable& table); virtual ~GFitsTable(void); // Operators GFitsTable& operator=(const GFitsTable& table); - GFitsTableCol& operator[](const int& colnum); - const GFitsTableCol& operator[](const int& colnum) const; - GFitsTableCol& operator[](const std::string& colname); - const GFitsTableCol& operator[](const std::string& colname) const; + GFitsTableCol* operator[](const int& colnum); + const GFitsTableCol* operator[](const int& colnum) const; + GFitsTableCol* operator[](const std::string& colname); + const GFitsTableCol* operator[](const std::string& colname) const; // Pure virtual methods virtual void clear(void) = 0; @@ -65,15 +65,19 @@ public: virtual HDUType exttype(void) const = 0; // Implemented Methods - void append_column(GFitsTableCol& column); - void insert_column(int colnum, GFitsTableCol& column); - void append_rows(const int& nrows); - void insert_rows(const int& rownum, const int& nrows); - void remove_rows(const int& rownum, const int& nrows); - int nrows(void) const; - int ncols(void) const; - bool hascolumn(const std::string& colname) const; - std::string print(const GChatter& chatter = NORMAL) const; + const int& size(void) const; + GFitsTableCol* set(const int& colnum, const GFitsTableCol& column); + GFitsTableCol* set(const std::string& colname, const GFitsTableCol& column); + GFitsTableCol* append(const GFitsTableCol& column); + GFitsTableCol* insert(int colnum, const GFitsTableCol& column); + GFitsTableCol* insert(const std::string& colname, const GFitsTableCol& column); + void append_rows(const int& nrows); + void insert_rows(const int& row, const int& nrows); + void remove_rows(const int& row, const int& nrows); + const int& nrows(void) const; + const int& ncols(void) const; + bool hascolumn(const std::string& colname) const; + std::string print(const GChatter& chatter = NORMAL) const; protected: // Protected methods @@ -98,6 +102,64 @@ private: // Private methods GFitsTableCol* alloc_column(int typecode) const; GFitsTableCol* ptr_column(const std::string& colname) const; + int colnum(const std::string& colname) const; }; + +/***********************************************************************//** + * @brief Return number of columns in table + * + * @return Number of columns in table + * + * Returns the number of columns in table. This method is equivalent to the + * ncols() method. + ***************************************************************************/ +inline +const int& GFitsTable::size(void) const +{ + return m_cols; +} + + +/***********************************************************************//** + * @brief Return number of rows in table + * + * @return Number of rows in table + * + * Returns the number of rows in table. + ***************************************************************************/ +inline +const int& GFitsTable::nrows(void) const +{ + return m_rows; +} + + +/***********************************************************************//** + * @brief Return number of columns in table + * + * @return Number of columns in table + * + * Returns the number of columns in table. This method is equivalent to the + * size() method. + ***************************************************************************/ +inline +const int& GFitsTable::ncols(void) const +{ + return m_cols; +} + + +/***********************************************************************//** + * @brief Append column to the table + * + * @param[in] column Table column. + * @return Pointer to table column that has been appended + ***************************************************************************/ +inline +GFitsTableCol* GFitsTable::append(const GFitsTableCol& column) +{ + return (insert(m_cols, column)); +} + #endif /* GFITSTABLE_HPP */ diff --git a/inst/cta/src/GCTAAeffArf.cpp b/inst/cta/src/GCTAAeffArf.cpp index b0d60c3..4aaab52 100644 --- a/inst/cta/src/GCTAAeffArf.cpp +++ b/inst/cta/src/GCTAAeffArf.cpp @@ -306,9 +306,9 @@ void GCTAAeffArf::read_arf(const GFitsTable* hdu) m_aeff.clear(); // Get pointers to table columns - const GFitsTableCol* energy_lo = &(*hdu)["ENERG_LO"]; - const GFitsTableCol* energy_hi = &(*hdu)["ENERG_HI"]; - const GFitsTableCol* specresp = &(*hdu)["SPECRESP"]; + const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"]; + const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"]; + const GFitsTableCol* specresp = (*hdu)["SPECRESP"]; // Determine unit conversion factors (default: TeV and cm^2) std::string u_energy_lo = gammalib::tolower(gammalib::strip_whitespace(energy_lo->unit())); diff --git a/inst/cta/src/GCTAEventList.cpp b/inst/cta/src/GCTAEventList.cpp index 9f4f87e..c239fb1 100644 --- a/inst/cta/src/GCTAEventList.cpp +++ b/inst/cta/src/GCTAEventList.cpp @@ -653,23 +653,23 @@ void GCTAEventList::read_events_v0(const GFitsTable* table) m_events.reserve(num); // Get column pointers - GFitsTableULongCol* ptr_eid = (GFitsTableULongCol*)&(*table)["EVENT_ID"]; - GFitsTableDoubleCol* ptr_time = (GFitsTableDoubleCol*)&(*table)["TIME"]; - GFitsTableShortCol* ptr_multip = (GFitsTableShortCol*)&(*table)["MULTIP"]; - GFitsTableFloatCol* ptr_ra = (GFitsTableFloatCol*)&(*table)["RA"]; - GFitsTableFloatCol* ptr_dec = (GFitsTableFloatCol*)&(*table)["DEC"]; - GFitsTableFloatCol* ptr_dir_err = (GFitsTableFloatCol*)&(*table)["DIR_ERR"]; - GFitsTableFloatCol* ptr_detx = (GFitsTableFloatCol*)&(*table)["DETX"]; - GFitsTableFloatCol* ptr_dety = (GFitsTableFloatCol*)&(*table)["DETY"]; - GFitsTableFloatCol* ptr_alt = (GFitsTableFloatCol*)&(*table)["ALT"]; - GFitsTableFloatCol* ptr_az = (GFitsTableFloatCol*)&(*table)["AZ"]; - GFitsTableFloatCol* ptr_corex = (GFitsTableFloatCol*)&(*table)["COREX"]; - GFitsTableFloatCol* ptr_corey = (GFitsTableFloatCol*)&(*table)["COREY"]; - GFitsTableFloatCol* ptr_core_err = (GFitsTableFloatCol*)&(*table)["CORE_ERR"]; - GFitsTableFloatCol* ptr_xmax = (GFitsTableFloatCol*)&(*table)["XMAX"]; - GFitsTableFloatCol* ptr_xmax_err = (GFitsTableFloatCol*)&(*table)["XMAX_ERR"]; - GFitsTableFloatCol* ptr_energy = (GFitsTableFloatCol*)&(*table)["ENERGY"]; - GFitsTableFloatCol* ptr_energy_err = (GFitsTableFloatCol*)&(*table)["ENERGY_ERR"]; + GFitsTableULongCol* ptr_eid = (GFitsTableULongCol*)(*table)["EVENT_ID"]; + GFitsTableDoubleCol* ptr_time = (GFitsTableDoubleCol*)(*table)["TIME"]; + GFitsTableShortCol* ptr_multip = (GFitsTableShortCol*)(*table)["MULTIP"]; + GFitsTableFloatCol* ptr_ra = (GFitsTableFloatCol*)(*table)["RA"]; + GFitsTableFloatCol* ptr_dec = (GFitsTableFloatCol*)(*table)["DEC"]; + GFitsTableFloatCol* ptr_dir_err = (GFitsTableFloatCol*)(*table)["DIR_ERR"]; + GFitsTableFloatCol* ptr_detx = (GFitsTableFloatCol*)(*table)["DETX"]; + GFitsTableFloatCol* ptr_dety = (GFitsTableFloatCol*)(*table)["DETY"]; + GFitsTableFloatCol* ptr_alt = (GFitsTableFloatCol*)(*table)["ALT"]; + GFitsTableFloatCol* ptr_az = (GFitsTableFloatCol*)(*table)["AZ"]; + GFitsTableFloatCol* ptr_corex = (GFitsTableFloatCol*)(*table)["COREX"]; + GFitsTableFloatCol* ptr_corey = (GFitsTableFloatCol*)(*table)["COREY"]; + GFitsTableFloatCol* ptr_core_err = (GFitsTableFloatCol*)(*table)["CORE_ERR"]; + GFitsTableFloatCol* ptr_xmax = (GFitsTableFloatCol*)(*table)["XMAX"]; + GFitsTableFloatCol* ptr_xmax_err = (GFitsTableFloatCol*)(*table)["XMAX_ERR"]; + GFitsTableFloatCol* ptr_energy = (GFitsTableFloatCol*)(*table)["ENERGY"]; + GFitsTableFloatCol* ptr_energy_err = (GFitsTableFloatCol*)(*table)["ENERGY_ERR"]; // Copy data from columns into GCTAEventAtom objects GCTAEventAtom event; @@ -734,26 +734,26 @@ void GCTAEventList::read_events_v1(const GFitsTable* table) m_events.reserve(num); // Get column pointers - GFitsTableULongCol* ptr_eid = (GFitsTableULongCol*)&(*table)["EVENT_ID"]; - GFitsTableULongCol* ptr_oid = (GFitsTableULongCol*)&(*table)["OBS_ID"]; - GFitsTableDoubleCol* ptr_time = (GFitsTableDoubleCol*)&(*table)["TIME"]; - GFitsTableShortCol* ptr_multip = (GFitsTableShortCol*)&(*table)["MULTIP"]; - GFitsTableFloatCol* ptr_ra = (GFitsTableFloatCol*)&(*table)["RA"]; - GFitsTableFloatCol* ptr_dec = (GFitsTableFloatCol*)&(*table)["DEC"]; - GFitsTableFloatCol* ptr_dir_err = (GFitsTableFloatCol*)&(*table)["DIR_ERR"]; - GFitsTableFloatCol* ptr_detx = (GFitsTableFloatCol*)&(*table)["DETX"]; - GFitsTableFloatCol* ptr_dety = (GFitsTableFloatCol*)&(*table)["DETY"]; - GFitsTableFloatCol* ptr_alt = (GFitsTableFloatCol*)&(*table)["ALT"]; - GFitsTableFloatCol* ptr_az = (GFitsTableFloatCol*)&(*table)["AZ"]; - GFitsTableFloatCol* ptr_corex = (GFitsTableFloatCol*)&(*table)["COREX"]; - GFitsTableFloatCol* ptr_corey = (GFitsTableFloatCol*)&(*table)["COREY"]; - GFitsTableFloatCol* ptr_core_err = (GFitsTableFloatCol*)&(*table)["CORE_ERR"]; - GFitsTableFloatCol* ptr_xmax = (GFitsTableFloatCol*)&(*table)["XMAX"]; - GFitsTableFloatCol* ptr_xmax_err = (GFitsTableFloatCol*)&(*table)["XMAX_ERR"]; - GFitsTableFloatCol* ptr_shw = (GFitsTableFloatCol*)&(*table)["SHWIDTH"]; - GFitsTableFloatCol* ptr_shl = (GFitsTableFloatCol*)&(*table)["SHLENGTH"]; - GFitsTableFloatCol* ptr_energy = (GFitsTableFloatCol*)&(*table)["ENERGY"]; - GFitsTableFloatCol* ptr_energy_err = (GFitsTableFloatCol*)&(*table)["ENERGY_ERR"]; + GFitsTableULongCol* ptr_eid = (GFitsTableULongCol*)(*table)["EVENT_ID"]; + GFitsTableULongCol* ptr_oid = (GFitsTableULongCol*)(*table)["OBS_ID"]; + GFitsTableDoubleCol* ptr_time = (GFitsTableDoubleCol*)(*table)["TIME"]; + GFitsTableShortCol* ptr_multip = (GFitsTableShortCol*)(*table)["MULTIP"]; + GFitsTableFloatCol* ptr_ra = (GFitsTableFloatCol*)(*table)["RA"]; + GFitsTableFloatCol* ptr_dec = (GFitsTableFloatCol*)(*table)["DEC"]; + GFitsTableFloatCol* ptr_dir_err = (GFitsTableFloatCol*)(*table)["DIR_ERR"]; + GFitsTableFloatCol* ptr_detx = (GFitsTableFloatCol*)(*table)["DETX"]; + GFitsTableFloatCol* ptr_dety = (GFitsTableFloatCol*)(*table)["DETY"]; + GFitsTableFloatCol* ptr_alt = (GFitsTableFloatCol*)(*table)["ALT"]; + GFitsTableFloatCol* ptr_az = (GFitsTableFloatCol*)(*table)["AZ"]; + GFitsTableFloatCol* ptr_corex = (GFitsTableFloatCol*)(*table)["COREX"]; + GFitsTableFloatCol* ptr_corey = (GFitsTableFloatCol*)(*table)["COREY"]; + GFitsTableFloatCol* ptr_core_err = (GFitsTableFloatCol*)(*table)["CORE_ERR"]; + GFitsTableFloatCol* ptr_xmax = (GFitsTableFloatCol*)(*table)["XMAX"]; + GFitsTableFloatCol* ptr_xmax_err = (GFitsTableFloatCol*)(*table)["XMAX_ERR"]; + GFitsTableFloatCol* ptr_shw = (GFitsTableFloatCol*)(*table)["SHWIDTH"]; + GFitsTableFloatCol* ptr_shl = (GFitsTableFloatCol*)(*table)["SHLENGTH"]; + GFitsTableFloatCol* ptr_energy = (GFitsTableFloatCol*)(*table)["ENERGY"]; + GFitsTableFloatCol* ptr_energy_err = (GFitsTableFloatCol*)(*table)["ENERGY_ERR"]; // Copy data from columns into GCTAEventAtom objects GCTAEventAtom event; @@ -821,7 +821,7 @@ void GCTAEventList::read_events_hillas(const GFitsTable* table) // HIL_MSW if (table->hascolumn("HIL_MSW")) { GFitsTableFloatCol* ptr = - (GFitsTableFloatCol*)&(*table)["HIL_MSW"]; + (GFitsTableFloatCol*)(*table)["HIL_MSW"]; for (int i = 0; i < num; ++i) { m_events[i].m_hil_msw = (*ptr)(i); } @@ -830,7 +830,7 @@ void GCTAEventList::read_events_hillas(const GFitsTable* table) // HIL_MSW_ERR if (table->hascolumn("HIL_MSW_ERR")) { GFitsTableFloatCol* ptr = - (GFitsTableFloatCol*)&(*table)["HIL_MSW_ERR"]; + (GFitsTableFloatCol*)(*table)["HIL_MSW_ERR"]; for (int i = 0; i < num; ++i) { m_events[i].m_hil_msw_err = (*ptr)(i); } @@ -839,7 +839,7 @@ void GCTAEventList::read_events_hillas(const GFitsTable* table) // HIL_MSL if (table->hascolumn("HIL_MSL")) { GFitsTableFloatCol* ptr = - (GFitsTableFloatCol*)&(*table)["HIL_MSL"]; + (GFitsTableFloatCol*)(*table)["HIL_MSL"]; for (int i = 0; i < num; ++i) { m_events[i].m_hil_msl = (*ptr)(i); } @@ -848,7 +848,7 @@ void GCTAEventList::read_events_hillas(const GFitsTable* table) // HIL_MSL_ERR if (table->hascolumn("HIL_MSL_ERR")) { GFitsTableFloatCol* ptr = - (GFitsTableFloatCol*)&(*table)["HIL_MSL_ERR"]; + (GFitsTableFloatCol*)(*table)["HIL_MSL_ERR"]; for (int i = 0; i < num; ++i) { m_events[i].m_hil_msl_err = (*ptr)(i); } @@ -1112,32 +1112,32 @@ void GCTAEventList::write_events(GFitsBinTable* hdu) const } // endfor: looped over rows // Append columns to table - hdu->append_column(col_eid); - hdu->append_column(col_oid); - hdu->append_column(col_time); - hdu->append_column(col_live); - hdu->append_column(col_multip); - hdu->append_column(col_telmask); - hdu->append_column(col_ra); - hdu->append_column(col_dec); - hdu->append_column(col_direrr); - hdu->append_column(col_detx); - hdu->append_column(col_dety); - hdu->append_column(col_alt); - hdu->append_column(col_az); - hdu->append_column(col_corex); - hdu->append_column(col_corey); - hdu->append_column(col_core_err); - hdu->append_column(col_xmax); - hdu->append_column(col_xmax_err); - hdu->append_column(col_shw); - hdu->append_column(col_shl); - hdu->append_column(col_energy); - hdu->append_column(col_energy_err); - hdu->append_column(col_hil_msw); - hdu->append_column(col_hil_msw_err); - hdu->append_column(col_hil_msl); - hdu->append_column(col_hil_msl_err); + hdu->append(col_eid); + hdu->append(col_oid); + hdu->append(col_time); + hdu->append(col_live); + hdu->append(col_multip); + hdu->append(col_telmask); + hdu->append(col_ra); + hdu->append(col_dec); + hdu->append(col_direrr); + hdu->append(col_detx); + hdu->append(col_dety); + hdu->append(col_alt); + hdu->append(col_az); + hdu->append(col_corex); + hdu->append(col_corey); + hdu->append(col_core_err); + hdu->append(col_xmax); + hdu->append(col_xmax_err); + hdu->append(col_shw); + hdu->append(col_shl); + hdu->append(col_energy); + hdu->append(col_energy_err); + hdu->append(col_hil_msw); + hdu->append(col_hil_msw_err); + hdu->append(col_hil_msl); + hdu->append(col_hil_msl_err); } // endif: there were events to write diff --git a/inst/cta/src/GCTAPsfVector.cpp b/inst/cta/src/GCTAPsfVector.cpp index 7897480..7f9c1a5 100644 --- a/inst/cta/src/GCTAPsfVector.cpp +++ b/inst/cta/src/GCTAPsfVector.cpp @@ -286,17 +286,17 @@ void GCTAPsfVector::read(const GFitsTable* hdu) const double conv = 0.6624305 * gammalib::deg2rad; // Get pointers to table columns - const GFitsTableCol* energy_lo = &(*hdu)["ENERG_LO"]; - const GFitsTableCol* energy_hi = &(*hdu)["ENERG_HI"]; + const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"]; + const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"]; // Handle various data formats (H.E.S.S. and MAGIC) const GFitsTableCol* r68; double r68_scale = 1.0; if (hdu->hascolumn("R68")) { - r68 = &(*hdu)["R68"]; + r68 = (*hdu)["R68"]; } else { - r68 = &(*hdu)["ANGRES40"]; + r68 = (*hdu)["ANGRES40"]; r68_scale = 1.0 / 0.6624305; // MAGIC PSF is already 1 sigma } diff --git a/inst/cta/src/GCTAResponseTable.cpp b/inst/cta/src/GCTAResponseTable.cpp index 33d72c6..17812a6 100644 --- a/inst/cta/src/GCTAResponseTable.cpp +++ b/inst/cta/src/GCTAResponseTable.cpp @@ -975,7 +975,7 @@ void GCTAResponseTable::read_colnames(const GFitsTable* hdu) for (int i = 0; i < hdu->ncols(); ++i) { // Get column name - std::string colname = (*hdu)[i].name(); + std::string colname = (*hdu)[i]->name(); // If we search for a "_LO" column, check if we have one. If one // is found, change the search mode to 1 and set the expected name @@ -1108,8 +1108,8 @@ void GCTAResponseTable::read_axes(const GFitsTable* hdu) for (int i = 0; i < axes(); ++i) { // Get pointers to table columns - const GFitsTableCol* col_lo = &(*hdu)[m_colname_lo[i]]; - const GFitsTableCol* col_hi = &(*hdu)[m_colname_hi[i]]; + const GFitsTableCol* col_lo = (*hdu)[m_colname_lo[i]]; + const GFitsTableCol* col_hi = (*hdu)[m_colname_hi[i]]; // Extract number of bins. Make sure that both columns have the // same number of bins @@ -1189,7 +1189,7 @@ void GCTAResponseTable::read_pars(const GFitsTable* hdu) for (int i = 0; i < size(); ++i) { // Get pointer to table column - const GFitsTableCol* col = &(*hdu)[m_colname_par[i]]; + const GFitsTableCol* col = (*hdu)[m_colname_par[i]]; // Extract number of bins. Verify that the number of bins // corresponds to the expectation. diff --git a/inst/lat/src/GLATAeff.cpp b/inst/lat/src/GLATAeff.cpp index 5674016..447226d 100644 --- a/inst/lat/src/GLATAeff.cpp +++ b/inst/lat/src/GLATAeff.cpp @@ -609,7 +609,7 @@ void GLATAeff::read_aeff(const GFitsTable* hdu) m_aeff.reserve(size); // Get pointer to effective area column - const GFitsTableCol* ptr = &(*hdu)["EFFAREA"]; + const GFitsTableCol* ptr = (*hdu)["EFFAREA"]; // Check consistency of effective area table int num = ptr->number(); @@ -667,7 +667,7 @@ void GLATAeff::read_efficiency(const GFitsTable* hdu) m_eff_func2 = NULL; // Get pointer to efficiency factors column - const GFitsTableCol* ptr = &(*hdu)["EFFICIENCY_PARS"]; + const GFitsTableCol* ptr = (*hdu)["EFFICIENCY_PARS"]; // Allocate vectors to hold the parameters std::vector par1; @@ -735,7 +735,7 @@ void GLATAeff::write_aeff(GFits& file) const col_aeff(0,i) = m_aeff[i]; // Append columns to table - hdu_aeff->append_column(col_aeff); + hdu_aeff->append(col_aeff); // Append HDU to FITS file file.append(*hdu_aeff); diff --git a/inst/lat/src/GLATEdisp.cpp b/inst/lat/src/GLATEdisp.cpp index 192e0da..e632306 100644 --- a/inst/lat/src/GLATEdisp.cpp +++ b/inst/lat/src/GLATEdisp.cpp @@ -375,8 +375,8 @@ void GLATEdisp::read_edisp(const GFitsTable* hdu) m_ls1.reserve(size); // Get pointer to columns - const GFitsTableCol* norm = &(*hdu)["NORM"]; - const GFitsTableCol* ls1 = &(*hdu)["LS1"]; + const GFitsTableCol* norm = (*hdu)["NORM"]; + const GFitsTableCol* ls1 = (*hdu)["LS1"]; // Check consistency of columns if (norm->number() != size) @@ -432,8 +432,8 @@ void GLATEdisp::write_edisp(GFits& file) const } // Append columns to table - hdu_edisp->append_column(col_norm); - hdu_edisp->append_column(col_ls1); + hdu_edisp->append(col_norm); + hdu_edisp->append(col_ls1); // Append HDU to FITS file file.append(*hdu_edisp); diff --git a/inst/lat/src/GLATEventList.cpp b/inst/lat/src/GLATEventList.cpp index 06e4b19..b29704e 100644 --- a/inst/lat/src/GLATEventList.cpp +++ b/inst/lat/src/GLATEventList.cpp @@ -496,21 +496,21 @@ void GLATEventList::read_events(const GFitsTable& table) m_events.reserve(num); // Get column pointers - GFitsTableDoubleCol* ptr_time = (GFitsTableDoubleCol*)&table["TIME"]; - GFitsTableFloatCol* ptr_energy = (GFitsTableFloatCol*)&table["ENERGY"]; - GFitsTableFloatCol* ptr_ra = (GFitsTableFloatCol*)&table["RA"]; - GFitsTableFloatCol* ptr_dec = (GFitsTableFloatCol*)&table["DEC"]; - GFitsTableFloatCol* ptr_theta = (GFitsTableFloatCol*)&table["THETA"]; - GFitsTableFloatCol* ptr_phi = (GFitsTableFloatCol*)&table["PHI"]; - GFitsTableFloatCol* ptr_zenith = (GFitsTableFloatCol*)&table["ZENITH_ANGLE"]; - GFitsTableFloatCol* ptr_azimuth = (GFitsTableFloatCol*)&table["EARTH_AZIMUTH_ANGLE"]; - GFitsTableLongCol* ptr_eid = (GFitsTableLongCol*)&table["EVENT_ID"]; - GFitsTableLongCol* ptr_rid = (GFitsTableLongCol*)&table["RUN_ID"]; - GFitsTableShortCol* ptr_recon = (GFitsTableShortCol*)&table["RECON_VERSION"]; - GFitsTableShortCol* ptr_calib = (GFitsTableShortCol*)&table["CALIB_VERSION"]; - GFitsTableShortCol* ptr_class = (GFitsTableShortCol*)&table["EVENT_CLASS"]; - GFitsTableShortCol* ptr_conv = (GFitsTableShortCol*)&table["CONVERSION_TYPE"]; - GFitsTableDoubleCol* ptr_ltime = (GFitsTableDoubleCol*)&table["LIVETIME"]; + GFitsTableDoubleCol* ptr_time = (GFitsTableDoubleCol*)table["TIME"]; + GFitsTableFloatCol* ptr_energy = (GFitsTableFloatCol*)table["ENERGY"]; + GFitsTableFloatCol* ptr_ra = (GFitsTableFloatCol*)table["RA"]; + GFitsTableFloatCol* ptr_dec = (GFitsTableFloatCol*)table["DEC"]; + GFitsTableFloatCol* ptr_theta = (GFitsTableFloatCol*)table["THETA"]; + GFitsTableFloatCol* ptr_phi = (GFitsTableFloatCol*)table["PHI"]; + GFitsTableFloatCol* ptr_zenith = (GFitsTableFloatCol*)table["ZENITH_ANGLE"]; + GFitsTableFloatCol* ptr_azimuth = (GFitsTableFloatCol*)table["EARTH_AZIMUTH_ANGLE"]; + GFitsTableLongCol* ptr_eid = (GFitsTableLongCol*)table["EVENT_ID"]; + GFitsTableLongCol* ptr_rid = (GFitsTableLongCol*)table["RUN_ID"]; + GFitsTableShortCol* ptr_recon = (GFitsTableShortCol*)table["RECON_VERSION"]; + GFitsTableShortCol* ptr_calib = (GFitsTableShortCol*)table["CALIB_VERSION"]; + GFitsTableShortCol* ptr_class = (GFitsTableShortCol*)table["EVENT_CLASS"]; + GFitsTableShortCol* ptr_conv = (GFitsTableShortCol*)table["CONVERSION_TYPE"]; + GFitsTableDoubleCol* ptr_ltime = (GFitsTableDoubleCol*)table["LIVETIME"]; // Copy data from columns into GLATEventAtom objects GLATEventAtom event; @@ -565,7 +565,7 @@ void GLATEventList::read_events(const GFitsTable& table) // Get column pointer GFitsTableFloatCol* ptr_dif = - static_cast(const_cast(&table[std::string(keyword)])); + static_cast(const_cast(table[std::string(keyword)])); // Copy data from columns into GLATEventAtom objects for (int i = 0; i < num; ++i) { diff --git a/inst/lat/src/GLATPsfBase.cpp b/inst/lat/src/GLATPsfBase.cpp index 705ba26..682fe15 100644 --- a/inst/lat/src/GLATPsfBase.cpp +++ b/inst/lat/src/GLATPsfBase.cpp @@ -1,7 +1,7 @@ /*************************************************************************** - * GLATPsfBase.cpp - Fermi/LAT point spread function abstract base class * + * GLATPsfBase.cpp - Fermi/LAT point spread function abstract base class * * ----------------------------------------------------------------------- * - * copyright (C) 2012 by Juergen Knoedlseder * + * copyright (C) 2012-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -21,7 +21,7 @@ /** * @file GLATPsfBase.cpp * @brief Fermi/LAT point spread function abstract base class implementation - * @author J. Knoedlseder + * @author Juergen Knoedlseder */ /* __ Includes ___________________________________________________________ */ @@ -199,7 +199,7 @@ void GLATPsfBase::free_members(void) void GLATPsfBase::read_scale(const GFitsTable* hdu) { // Get pointer to column - const GFitsTableCol* scale = &(*hdu)["PSFSCALE"]; + const GFitsTableCol* scale = (*hdu)["PSFSCALE"]; // Get scaling factors if (front()) { @@ -256,7 +256,7 @@ void GLATPsfBase::write_scale(GFits& file) const col_scale(0,4) = m_scale_index; // Append column to table - hdu_scale->append_column(col_scale); + hdu_scale->append(col_scale); // Append HDU to FITS file file.append(*hdu_scale); diff --git a/inst/lat/src/GLATPsfV1.cpp b/inst/lat/src/GLATPsfV1.cpp index f41588f..0ac4bb8 100644 --- a/inst/lat/src/GLATPsfV1.cpp +++ b/inst/lat/src/GLATPsfV1.cpp @@ -205,10 +205,10 @@ void GLATPsfV1::read(const GFitsTable* hdu) m_gtail.reserve(size); // Get pointer to columns - const GFitsTableCol* ncore = &(*hdu)["NCORE"]; - const GFitsTableCol* sigma = &(*hdu)["SIGMA"]; - const GFitsTableCol* gcore = &(*hdu)["GCORE"]; - const GFitsTableCol* gtail = &(*hdu)["GTAIL"]; + const GFitsTableCol* ncore = (*hdu)["NCORE"]; + const GFitsTableCol* sigma = (*hdu)["SIGMA"]; + const GFitsTableCol* gcore = (*hdu)["GCORE"]; + const GFitsTableCol* gtail = (*hdu)["GTAIL"]; // Check consistency of columns if (ncore->number() != size) { @@ -286,10 +286,10 @@ void GLATPsfV1::write(GFits& file) const } // Append columns to table - hdu_rpsf->append_column(col_ncore); - hdu_rpsf->append_column(col_sigma); - hdu_rpsf->append_column(col_gcore); - hdu_rpsf->append_column(col_gtail); + hdu_rpsf->append(col_ncore); + hdu_rpsf->append(col_sigma); + hdu_rpsf->append(col_gcore); + hdu_rpsf->append(col_gtail); // Append HDU to FITS file file.append(*hdu_rpsf); diff --git a/inst/lat/src/GLATPsfV3.cpp b/inst/lat/src/GLATPsfV3.cpp index d3e0db3..2b2d18d 100644 --- a/inst/lat/src/GLATPsfV3.cpp +++ b/inst/lat/src/GLATPsfV3.cpp @@ -214,12 +214,12 @@ void GLATPsfV3::read(const GFitsTable* hdu) m_gtail.reserve(size); // Get pointer to columns - const GFitsTableCol* ncore = &(*hdu)["NCORE"]; - const GFitsTableCol* ntail = &(*hdu)["NTAIL"]; - const GFitsTableCol* score = &(*hdu)["SCORE"]; - const GFitsTableCol* stail = &(*hdu)["STAIL"]; - const GFitsTableCol* gcore = &(*hdu)["GCORE"]; - const GFitsTableCol* gtail = &(*hdu)["GTAIL"]; + const GFitsTableCol* ncore = (*hdu)["NCORE"]; + const GFitsTableCol* ntail = (*hdu)["NTAIL"]; + const GFitsTableCol* score = (*hdu)["SCORE"]; + const GFitsTableCol* stail = (*hdu)["STAIL"]; + const GFitsTableCol* gcore = (*hdu)["GCORE"]; + const GFitsTableCol* gtail = (*hdu)["GTAIL"]; // Check consistency of columns if (ncore->number() != size) { @@ -314,12 +314,12 @@ void GLATPsfV3::write(GFits& file) const } // Append columns to table - hdu_rpsf->append_column(col_ncore); - hdu_rpsf->append_column(col_ntail); - hdu_rpsf->append_column(col_score); - hdu_rpsf->append_column(col_stail); - hdu_rpsf->append_column(col_gcore); - hdu_rpsf->append_column(col_gtail); + hdu_rpsf->append(col_ncore); + hdu_rpsf->append(col_ntail); + hdu_rpsf->append(col_score); + hdu_rpsf->append(col_stail); + hdu_rpsf->append(col_gcore); + hdu_rpsf->append(col_gtail); // Append HDU to FITS file file.append(*hdu_rpsf); diff --git a/inst/lat/src/GLATResponseTable.cpp b/inst/lat/src/GLATResponseTable.cpp index 9863657..55901bd 100644 --- a/inst/lat/src/GLATResponseTable.cpp +++ b/inst/lat/src/GLATResponseTable.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GLATResponseTable.cpp - Fermi/LAT Response table class * + * GLATResponseTable.cpp - Fermi/LAT Response table class * * ----------------------------------------------------------------------- * * copyright (C) 2008-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -184,10 +184,10 @@ void GLATResponseTable::read(const GFitsTable* hdu) clear(); // Get pointers to table columns - const GFitsTableCol* energy_lo = &(*hdu)["ENERG_LO"]; - const GFitsTableCol* energy_hi = &(*hdu)["ENERG_HI"]; - const GFitsTableCol* ctheta_lo = &(*hdu)["CTHETA_LO"]; - const GFitsTableCol* ctheta_hi = &(*hdu)["CTHETA_HI"]; + const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"]; + const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"]; + const GFitsTableCol* ctheta_lo = (*hdu)["CTHETA_LO"]; + const GFitsTableCol* ctheta_hi = (*hdu)["CTHETA_HI"]; // Extract number of bins m_energy_num = energy_lo->number(); @@ -264,10 +264,10 @@ void GLATResponseTable::write(GFitsTable* hdu) const } // Append columns to boundary table - hdu->append_column(col_energy_lo); - hdu->append_column(col_energy_hi); - hdu->append_column(col_ctheta_lo); - hdu->append_column(col_ctheta_hi); + hdu->append(col_energy_lo); + hdu->append(col_energy_hi); + hdu->append(col_ctheta_lo); + hdu->append(col_ctheta_hi); // Return return; diff --git a/inst/mwl/src/GMWLSpectrum.cpp b/inst/mwl/src/GMWLSpectrum.cpp index 5b87547..db84b21 100644 --- a/inst/mwl/src/GMWLSpectrum.cpp +++ b/inst/mwl/src/GMWLSpectrum.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * GMWLSpectrum.cpp - Multi-wavelength spectrum class * + * GMWLSpectrum.cpp - Multi-wavelength spectrum class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -636,19 +636,19 @@ void GMWLSpectrum::read_fits(const GFitsTable* table) // Extract column pointers if (table->ncols() == 2) { - c_energy = &(*table)[0]; - c_flux = &(*table)[1]; + c_energy = (*table)[0]; + c_flux = (*table)[1]; } else if (table->ncols() == 3) { - c_energy = &(*table)[0]; - c_flux = &(*table)[1]; - c_flux_err = &(*table)[2]; + c_energy = (*table)[0]; + c_flux = (*table)[1]; + c_flux_err = (*table)[2]; } else if (table->ncols() > 3) { - c_energy = &(*table)[0]; - c_energy_err = &(*table)[1]; - c_flux = &(*table)[2]; - c_flux_err = &(*table)[3]; + c_energy = (*table)[0]; + c_energy_err = (*table)[1]; + c_flux = (*table)[2]; + c_flux_err = (*table)[3]; } else { throw GMWLException::bad_file_format(G_READ_FITS, @@ -659,14 +659,18 @@ void GMWLSpectrum::read_fits(const GFitsTable* table) // Read spectral points and add to spectrum for (int i = 0; i < table->nrows(); ++i) { GMWLDatum datum; - if (c_energy != NULL) + if (c_energy != NULL) { datum.m_eng = conv_energy(c_energy->real(i), c_energy->unit()); - if (c_energy_err != NULL) + } + if (c_energy_err != NULL) { datum.m_eng_err = conv_energy(c_energy_err->real(i), c_energy->unit()); - if (c_flux != NULL) + } + if (c_flux != NULL) { datum.m_flux = conv_flux(datum.m_eng, c_flux->real(i), c_flux->unit()); - if (c_flux_err != NULL) + } + if (c_flux_err != NULL) { datum.m_flux_err = conv_flux(datum.m_eng, c_flux_err->real(i), c_flux_err->unit()); + } m_data.push_back(datum); } diff --git a/pyext/GFitsTable.i b/pyext/GFitsTable.i index d2a380c..26bbea7 100644 --- a/pyext/GFitsTable.i +++ b/pyext/GFitsTable.i @@ -109,7 +109,7 @@ class GFitsTable : public GFitsHDU { public: // Constructors and destructors GFitsTable(void); - explicit GFitsTable(int nrows); + explicit GFitsTable(const int& nrows); GFitsTable(const GFitsTable& table); virtual ~GFitsTable(void); @@ -119,14 +119,18 @@ public: virtual HDUType exttype(void) const = 0; // Implemented Methods - void append_column(GFitsTableCol& column); - void insert_column(int colnum, GFitsTableCol& column); - void append_rows(const int& nrows); - void insert_rows(const int& rownum, const int& nrows); - void remove_rows(const int& rownum, const int& nrows); - bool hascolumn(const std::string& colname) const; - int nrows(void) const; - int ncols(void) const; + const int& size(void) const; + GFitsTableCol* set(const int& colnum, const GFitsTableCol& column); + GFitsTableCol* set(const std::string& colname, const GFitsTableCol& column); + GFitsTableCol* append(const GFitsTableCol& column); + GFitsTableCol* insert(int colnum, const GFitsTableCol& column); + GFitsTableCol* insert(const std::string& colname, const GFitsTableCol& column); + void append_rows(const int& nrows); + void insert_rows(const int& row, const int& nrows); + void remove_rows(const int& row, const int& nrows); + const int& nrows(void) const; + const int& ncols(void) const; + bool hascolumn(const std::string& colname) const; }; @@ -134,18 +138,18 @@ public: * @brief GFitsTable class extension ***************************************************************************/ %extend GFitsTable { - GFitsTableCol& __getitem__(const int& colnum) { + GFitsTableCol* __getitem__(const int& colnum) { return (*self)[colnum]; } - GFitsTableCol& __getitem__(const std::string& colname) { + GFitsTableCol* __getitem__(const std::string& colname) { return (*self)[colname]; } void __setitem__(const int& colnum, const GFitsTableCol& col) { - (*self)[colnum] = col; + self->set(colnum, col); return; } void __setitem__(const std::string& colname, const GFitsTableCol& col) { - (*self)[colname] = col; + self->set(colname, col); return; } }; diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index 227ef03..8945926 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -55,8 +55,10 @@ /* __ Method name definitions ____________________________________________ */ #define G_ACCESS1 "GFitsTable::operator[](int&)" #define G_ACCESS2 "GFitsTable::operator[](std::string&)" -#define G_APPEND_COLUMN "GFitsTable::append_column(GFitsTableCol*)" -#define G_INSERT_COLUMN "GFitsTable::insert_column(int, GFitsTableCol*)" +#define G_SET1 "GFitsTable::set(int&, GFitsTableCol&)" +#define G_SET2 "GFitsTable::set(std::string&, GFitsTableCol&)" +#define G_INSERT1 "GFitsTable::insert(int, GFitsTableCol&)" +#define G_INSERT2 "GFitsTable::insert(std::string&, GFitsTableCol&)" #define G_INSERT_ROWS "GFitsTable::insert_rows(int&, int&)" #define G_REMOVE_ROWS "GFitsTable::remove_rows(int&, int&)" #define G_DATA_OPEN "GFitsTable::data_open(void*)" @@ -80,7 +82,7 @@ /***********************************************************************//** * @brief Void constructor * - * Construct an instance of GFitsTable with zero rows. + * Construct void instance. ***************************************************************************/ GFitsTable::GFitsTable(void) : GFitsHDU() { @@ -97,9 +99,9 @@ GFitsTable::GFitsTable(void) : GFitsHDU() * * @param[in] nrows Number of rows in table. * - * Construct an instance of GFitsTable with a given number of rows. + * Construct instance for a specified number of table rows. ***************************************************************************/ -GFitsTable::GFitsTable(int nrows) : GFitsHDU() +GFitsTable::GFitsTable(const int& nrows) : GFitsHDU() { // Initialise class members for clean destruction init_members(); @@ -115,7 +117,7 @@ GFitsTable::GFitsTable(int nrows) : GFitsHDU() /***********************************************************************//** * @brief Copy constructor * - * @param[in] table Table from which to construct instance. + * @param[in] table Table. ***************************************************************************/ GFitsTable::GFitsTable(const GFitsTable& table) : GFitsHDU(table) { @@ -153,6 +155,7 @@ GFitsTable::~GFitsTable(void) * @brief Assignment operator * * @param[in] table Table. + * @return Table. ***************************************************************************/ GFitsTable& GFitsTable::operator=(const GFitsTable& table) { @@ -179,16 +182,17 @@ GFitsTable& GFitsTable::operator=(const GFitsTable& table) /***********************************************************************//** - * @brief Returns reference to table column + * @brief Returns pointer to table column * * @param[in] colnum Column number [0,...,ncols()-1]. + * @return Table column pointer. * * @exception GException::fits_no_data * No data found in table. * @exception GException::out_of_range * Column number is out of range. ***************************************************************************/ -GFitsTableCol& GFitsTable::operator[](const int& colnum) +GFitsTableCol* GFitsTable::operator[](const int& colnum) { // If there is no data then throw an exception if (m_columns == NULL) { @@ -197,8 +201,9 @@ GFitsTableCol& GFitsTable::operator[](const int& colnum) // Compile option: raise exception if column number is out of range #if defined(G_RANGE_CHECK) - if (colnum < 0 || colnum >= m_cols) + if (colnum < 0 || colnum >= m_cols) { throw GException::out_of_range(G_ACCESS1, colnum, 0, m_cols-1); + } #endif // Get column pointer @@ -207,22 +212,23 @@ GFitsTableCol& GFitsTable::operator[](const int& colnum) throw GException::fits_no_data(G_ACCESS1, "No data for this column."); } - // Return reference - return *ptr; + // Return pointer + return ptr; } /***********************************************************************//** - * @brief Returns reference to table column (const version) + * @brief Returns pointer to table column (const version) * * @param[in] colnum Column number [0,...,ncols()-1]. + * @return Table column pointer. * * @exception GException::fits_no_data * No data found in table. * @exception GException::out_of_range * Column number is out of range. ***************************************************************************/ -const GFitsTableCol& GFitsTable::operator[](const int& colnum) const +const GFitsTableCol* GFitsTable::operator[](const int& colnum) const { // If there is no data then throw an exception if (m_columns == NULL) { @@ -231,8 +237,9 @@ const GFitsTableCol& GFitsTable::operator[](const int& colnum) const // Compile option: raise exception if column number is out of range #if defined(G_RANGE_CHECK) - if (colnum < 0 || colnum >= m_cols) + if (colnum < 0 || colnum >= m_cols) { throw GException::out_of_range(G_ACCESS1, colnum, 0, m_cols-1); + } #endif // Get column pointer @@ -241,22 +248,23 @@ const GFitsTableCol& GFitsTable::operator[](const int& colnum) const throw GException::fits_no_data(G_ACCESS1, "No data for this column."); } - // Return reference - return *ptr; + // Return pointer + return ptr; } /***********************************************************************//** - * @brief Returns reference to table column + * @brief Returns pointer to table column * * @param[in] colname Column name. + * @return Table column pointer. * * @exception GException::fits_no_data * No data found in table. * @exception GException::fits_column_not_found * Column name not found. ***************************************************************************/ -GFitsTableCol& GFitsTable::operator[](const std::string& colname) +GFitsTableCol* GFitsTable::operator[](const std::string& colname) { // If there is no data then throw an exception if (m_columns == NULL) { @@ -271,22 +279,23 @@ GFitsTableCol& GFitsTable::operator[](const std::string& colname) throw GException::fits_column_not_found(G_ACCESS2, colname); } - // Return reference - return *ptr; + // Return pointer + return ptr; } /***********************************************************************//** - * @brief Returns reference to table column (const version) + * @brief Returns pointer to table column (const version) * * @param[in] colname Column name. + * @return Table column pointer. * * @exception GException::fits_no_data * No data found in table. * @exception GException::fits_column_not_found * Column name not found. ***************************************************************************/ -const GFitsTableCol& GFitsTable::operator[](const std::string& colname) const +const GFitsTableCol* GFitsTable::operator[](const std::string& colname) const { // If there is no data then throw an exception if (m_columns == NULL) { @@ -301,8 +310,8 @@ const GFitsTableCol& GFitsTable::operator[](const std::string& colname) const throw GException::fits_column_not_found(G_ACCESS2, colname); } - // Return reference - return *ptr; + // Return pointer + return ptr; } @@ -313,29 +322,66 @@ const GFitsTableCol& GFitsTable::operator[](const std::string& colname) const ==========================================================================*/ /***********************************************************************//** - * @brief Append column to the table + * @brief Set column * - * @param[in] column Column which should be appended to table. + * @param[in] colnum Column number [0,...,ncols()-1]. + * @param[in] column Table column. + * @return Pointer to table column that has been set. * - * A column will be appended at the end of the table. See - * GFitsTable::insert_column - * for more details on the method. + * Sets the column of a table by making a deep copy of the @p column + * provided. ***************************************************************************/ -void GFitsTable::append_column(GFitsTableCol& column) +GFitsTableCol* GFitsTable::set(const int& colnum, const GFitsTableCol& column) { - // Inserting at the end correspond to appending - insert_column(m_cols, column); + // Check if column number is valid + if (colnum < 0 || colnum >= ncols()) { + throw GException::out_of_range(G_SET1, "Column number", colnum, ncols()); + } - // Return - return; + // Free existing column + if (m_columns[colnum] != NULL) delete m_columns[colnum]; + + // Clone column + m_columns[colnum] = column.clone(); + + // Return pointer to column + return m_columns[colnum]; } /***********************************************************************//** + * @brief Set column + * + * @param[in] colname Column name. + * @param[in] column Table column. + * @return Pointer to table column that has been set. + * + * Sets the column of a table by making a deep copy of the @p column + * provided. + ***************************************************************************/ +GFitsTableCol* GFitsTable::set(const std::string& colname, + const GFitsTableCol& column) +{ + // Get column number + int colnum = this->colnum(colname); + + // If column has not been found throw an exception + if (colnum < 0) { + throw GException::fits_column_not_found(G_SET2, colname); + } + + // Set column and return pointer to column + return (set(colnum, column)); +} + + + +/***********************************************************************//** * @brief Insert column into the table * - * @param[in] colnum Column number to be inserted. - * @param[in] column Column which should be inserted into the table. + * @param[in] colnum Column number [0,...,ncols()]. + * @param[in] column Table column. + * @return Pointer to table column that has been appended. * * @exception GException::fits_bad_col_length * The length of the column is incompatible with the number of @@ -343,7 +389,6 @@ void GFitsTable::append_column(GFitsTableCol& column) * * A column will be inserted at position 'colnum' of the table. If the * position is beyond the end of the table the column will be appended. - * Any 'colnum' value smaller than 0 will be set automatically to 0. * * If the table is empty and has 0 rows, the number of rows will be set to * the length of the column. @@ -351,24 +396,31 @@ void GFitsTable::append_column(GFitsTableCol& column) * The length of the column to be inserted has to be identical to the number * of rows in the table. ***************************************************************************/ -void GFitsTable::insert_column(int colnum, GFitsTableCol& column) +GFitsTableCol* GFitsTable::insert(int colnum, const GFitsTableCol& column) { // Make sure that 'colnum' is valid. Since we add one column the total // number of columns at return will be m_cols+1, hence the column // index is comprised between [0,m_cols] - if (colnum < 0) colnum = 0; - if (colnum > m_cols) colnum = m_cols; + //if (colnum < 0) colnum = 0; + //if (colnum > m_cols) colnum = m_cols; + + // Check if column number is valid + if (colnum < 0 || colnum > ncols()) { + throw GException::out_of_range(G_INSERT1, "Column number", colnum, ncols()+1); + } // If the table is empty and has 0 rows then set the number of rows in // the table to the length of the column - if (m_columns == NULL && m_rows == 0) + if (m_columns == NULL && m_rows == 0) { m_rows = column.length(); + } // Throw exception if the column length is incompatible with number of // rows in the table - if (m_rows != column.length()) - throw GException::fits_bad_col_length(G_INSERT_COLUMN, + if (m_rows != column.length()) { + throw GException::fits_bad_col_length(G_INSERT1, column.length(), m_rows); + } // If no column data exist then allocate them now if (m_columns == NULL) { @@ -389,8 +441,9 @@ void GFitsTable::insert_column(int colnum, GFitsTableCol& column) int src; int dst; for (src = 0, dst = 0; dst < m_cols+1; ++dst) { - if (dst == colnum) + if (dst == colnum) { tmp[dst] = NULL; + } else { tmp[dst] = m_columns[src]; src++; @@ -415,8 +468,33 @@ void GFitsTable::insert_column(int colnum, GFitsTableCol& column) // file m_columns[colnum]->colnum(0); - // Return - return; + // Return column pointer + return (m_columns[colnum]); +} + + +/***********************************************************************//** + * @brief Insert column into the table + * + * @param[in] colname Column name. + * @param[in] column Table column. + * @return Pointer to table column that has been appended + * + * Inserts the column at the position given by the specified column name. + ***************************************************************************/ +GFitsTableCol* GFitsTable::insert(const std::string& colname, + const GFitsTableCol& column) +{ + // Get column number + int colnum = this->colnum(colname); + + // If column has not been found throw an exception + if (colnum < 0) { + throw GException::fits_column_not_found(G_INSERT2, colname); + } + + // Insert column and return pointer to column + return (insert(colnum, column)); } @@ -425,8 +503,9 @@ void GFitsTable::insert_column(int colnum, GFitsTableCol& column) * * @param[in] nrows Number of rows to be appended. * - * This method appends rows to a FITS table. This implies that all columns - * will be loaded into memory. + * Appends @p nrows rows at the end of the FITS table. The method calls the + * insert() method to do the job. Note that a call of this method will lead + * to loading all table data into memory. ***************************************************************************/ void GFitsTable::append_rows(const int& nrows) { @@ -444,27 +523,31 @@ void GFitsTable::append_rows(const int& nrows) /***********************************************************************//** * @brief Insert rows into the table * - * @param[in] rownum Row after which rows should be inserted (0=first row). + * @param[in] row Row at which rows are inserted [0,...,nrows()]. * @param[in] nrows Number of rows to be inserted. * * @exception GException::fits_invalid_row * Specified rownum is invalid. * - * This method inserts rows into a FITS table. This implies that all columns - * will be loaded into memory. + * Inserts @p nrows table rows at the specified @p row into the table. If the + * @p row index is set to the number of existing rows, nrows(), @p nrows + * will be appened at the end of the table. + * + * Note that this method will load all table data into memory. ***************************************************************************/ -void GFitsTable::insert_rows(const int& rownum, const int& nrows) +void GFitsTable::insert_rows(const int& row, const int& nrows) { - // Make sure that rownum is valid - if (rownum < 0 || rownum > m_rows) - throw GException::fits_invalid_row(G_INSERT_ROWS, rownum, m_rows); + // Make sure that row is valid + if (row < 0 || row > m_rows) { + throw GException::fits_invalid_row(G_INSERT_ROWS, row, m_rows); + } // Continue only if there are rows to be inserted if (nrows > 0) { // Insert rows for all columns for (int icol = 0; icol < m_cols; ++icol) { - m_columns[icol]->insert(rownum, nrows); + m_columns[icol]->insert(row, nrows); } // Increment number of rows in table @@ -480,7 +563,7 @@ void GFitsTable::insert_rows(const int& rownum, const int& nrows) /***********************************************************************//** * @brief Remove rows from the table * - * @param[in] rownum Row after which rows should be removed (0=first row). + * @param[in] row Row from which on rows are removed [0,...,nrows()-1]. * @param[in] nrows Number of rows to be removed. * * @exception GException::fits_invalid_row @@ -488,25 +571,28 @@ void GFitsTable::insert_rows(const int& rownum, const int& nrows) * @exception GException::fits_invalid_nrows * Invalid number of rows specified. * - * This method inserts rows into a FITS table. This implies that all columns - * will be loaded into memory. + * Removes @p nrows table rows from the specified @p row on from the table. + * + * Note that this method will load all column data into memory. ***************************************************************************/ -void GFitsTable::remove_rows(const int& rownum, const int& nrows) +void GFitsTable::remove_rows(const int& row, const int& nrows) { - // Make sure that rownum is valid - if (rownum < 0 || rownum >= m_rows) - throw GException::fits_invalid_row(G_REMOVE_ROWS, rownum, m_rows-1); + // Make sure that row is valid + if (row < 0 || row >= m_rows) { + throw GException::fits_invalid_row(G_REMOVE_ROWS, row, m_rows-1); + } // Make sure that we don't remove beyond the limit - if (nrows < 0 || nrows > m_rows-rownum) - throw GException::fits_invalid_nrows(G_REMOVE_ROWS, nrows, m_rows-rownum); + if (nrows < 0 || nrows > m_rows-row) { + throw GException::fits_invalid_nrows(G_REMOVE_ROWS, nrows, m_rows-row); + } // Continue only if there are rows to be removed if (nrows > 0) { - // Insert rows for all columns + // Remove rows for all columns for (int icol = 0; icol < m_cols; ++icol) { - m_columns[icol]->remove(rownum, nrows); + m_columns[icol]->remove(row, nrows); } // Decrement number of rows in table @@ -520,29 +606,10 @@ void GFitsTable::remove_rows(const int& rownum, const int& nrows) /***********************************************************************//** - * @brief Return number of rows in table - ***************************************************************************/ -int GFitsTable::nrows(void) const -{ - // Return number of rows - return m_rows; -} - - -/***********************************************************************//** - * @brief Return number of columns in table - ***************************************************************************/ -int GFitsTable::ncols(void) const -{ - // Return number of columns - return m_cols; -} - - -/***********************************************************************//** * @brief Checks the presence of a column in table * * @param[in] colname Column name. + * @return True of the column exists, false otherwise. ***************************************************************************/ bool GFitsTable::hascolumn(const std::string& colname) const { @@ -589,8 +656,10 @@ std::string GFitsTable::print(const GChatter& chatter) const } // Append table dimensions - result.append(gammalib::parformat("Number of rows")+gammalib::str(m_rows)+"\n"); - result.append(gammalib::parformat("Number of columns")+gammalib::str(m_cols)+"\n"); + result.append(gammalib::parformat("Number of rows")); + result.append(gammalib::str(m_rows)+"\n"); + result.append(gammalib::parformat("Number of columns")); + result.append(gammalib::str(m_cols)+"\n"); // Append header information result.append(m_header.print(chatter)); @@ -1380,10 +1449,12 @@ void GFitsTable::copy_members(const GFitsTable& table) if (table.m_columns != NULL && m_cols > 0) { m_columns = new GFitsTableCol*[m_cols]; for (int i = 0; i < m_cols; ++i) { - if (table.m_columns[i] != NULL) + if (table.m_columns[i] != NULL) { m_columns[i] = table.m_columns[i]->clone(); - else + } + else { m_columns[i] = NULL; + } } } @@ -1482,10 +1553,12 @@ GFitsTableCol* GFitsTable::alloc_column(int typecode) const * @brief Returns pointer of column with given name * * @param[in] colname Name of column. + * @return Pointer to table column (NULL if column has not been found). * - * This method returns a pointer on the column with the specified name. It - * returns NULL if no column with the given name was found, or if the - * column is not allocated. + * Returns a pointer to the column with the specified name. If more columns + * with the same name exist, a pointer to the first of these columns is + * returned. If no column with the specified name is found, a NULL pointer + * will be returned. ***************************************************************************/ GFitsTableCol* GFitsTable::ptr_column(const std::string& colname) const { @@ -1505,3 +1578,32 @@ GFitsTableCol* GFitsTable::ptr_column(const std::string& colname) const // Return pointer return ptr; } + + +/***********************************************************************//** + * @brief Returns column number of a given column name + * + * @param[in] colname Name of column. + * @return Column number (-1 if column has not been found). + * + * Returns the column number of the column with the specified name. If more + * columns with the same name exist, the first of these columns is returned. + ***************************************************************************/ +int GFitsTable::colnum(const std::string& colname) const +{ + // Initialise column number + int colnum = -1; + + // If there are columns then search for the specified name + if (m_columns != NULL) { + for (int i = 0; i < m_cols; ++i) { + if (m_columns[i]->name() == colname) { + colnum = i; + break; + } + } + } + + // Return column number + return colnum; +} diff --git a/src/obs/GEbounds.cpp b/src/obs/GEbounds.cpp index 5c38d82..96a29f2 100644 --- a/src/obs/GEbounds.cpp +++ b/src/obs/GEbounds.cpp @@ -633,8 +633,8 @@ void GEbounds::read(GFitsTable* hdu) // Copy information for (int i = 0; i < m_num; ++i) { - m_min[i].keV((*hdu)["E_MIN"].real(i)); - m_max[i].keV((*hdu)["E_MAX"].real(i)); + m_min[i].keV((*hdu)["E_MIN"]->real(i)); + m_max[i].keV((*hdu)["E_MAX"]->real(i)); } } // endif: there were channels to read @@ -679,8 +679,8 @@ void GEbounds::write(GFits* file, const std::string& extname) const // Create binary table GFitsBinTable* table = new GFitsBinTable(m_num); - table->append_column(cemin); - table->append_column(cemax); + table->append(cemin); + table->append(cemax); table->extname(extname); // Write to FITS file diff --git a/src/obs/GEnergies.cpp b/src/obs/GEnergies.cpp index 3aa9ac4..1b2602d 100644 --- a/src/obs/GEnergies.cpp +++ b/src/obs/GEnergies.cpp @@ -438,11 +438,11 @@ void GEnergies::read(const GFitsTable* hdu) } // Get the column with the name "Energy" - const GFitsTableCol& col_energy = (*hdu)["Energy"]; + const GFitsTableCol* col_energy = (*hdu)["Energy"]; // Set energies for (int i = 0; i < num; ++i) { - append(GEnergy(col_energy.real(i), unit)); + append(GEnergy(col_energy->real(i), unit)); } } // endif: there were energy bins @@ -478,7 +478,7 @@ void GEnergies::write(GFits* file, const std::string& extname) const // Create energies table GFitsBinTable* table = new GFitsBinTable(num); - table->append_column(col_energy); + table->append(col_energy); table->extname(extname); // Write to FITS file diff --git a/src/obs/GGti.cpp b/src/obs/GGti.cpp index f33080e..862dc9c 100644 --- a/src/obs/GGti.cpp +++ b/src/obs/GGti.cpp @@ -606,8 +606,8 @@ void GGti::read(const GFitsTable* hdu) m_start = new GTime[m_num]; m_stop = new GTime[m_num]; for (int i = 0; i < m_num; ++i) { - m_start[i].set((*hdu)["START"].real(i), m_reference); - m_stop[i].set((*hdu)["STOP"].real(i), m_reference); + m_start[i].set((*hdu)["START"]->real(i), m_reference); + m_stop[i].set((*hdu)["STOP"]->real(i), m_reference); } // Set attributes @@ -647,8 +647,8 @@ void GGti::write(GFits* file, const std::string& extname) const // Create GTI table GFitsBinTable* table = new GFitsBinTable(m_num); - table->append_column(cstart); - table->append_column(cstop); + table->append(cstart); + table->append(cstop); table->extname(extname); // Write time reference diff --git a/src/sky/GSkymap.cpp b/src/sky/GSkymap.cpp index 909f045..8687f9e 100644 --- a/src/sky/GSkymap.cpp +++ b/src/sky/GSkymap.cpp @@ -1329,7 +1329,7 @@ void GSkymap::read_healpix(const GFitsTable* hdu) // all columns. Only count columns that can fully hold the map. m_num_maps = 0; for (int icol = 0; icol < ncols; ++icol) { - const GFitsTableCol* col = &(*hdu)[icol]; + const GFitsTableCol* col = (*hdu)[icol]; if (col->number() % nentry == 0) { m_num_maps += col->number() / nentry; } @@ -1348,7 +1348,7 @@ void GSkymap::read_healpix(const GFitsTable* hdu) for (int icol = 0; icol < ncols; ++icol) { // Get next column - const GFitsTableCol* col = &(*hdu)[icol]; + const GFitsTableCol* col = (*hdu)[icol]; // Only consider columns that can fully hold maps if (col->number() % nentry == 0) { @@ -1562,7 +1562,7 @@ GFitsBinTable* GSkymap::create_healpix_hdu(void) const // Create HDU that contains Healpix map in a binary table hdu = new GFitsBinTable(rows); - hdu->append_column(column); + hdu->append(column); } // endif: there were pixels diff --git a/src/xspec/GArf.cpp b/src/xspec/GArf.cpp index 68c9e1a..303ec5c 100644 --- a/src/xspec/GArf.cpp +++ b/src/xspec/GArf.cpp @@ -311,9 +311,9 @@ void GArf::read(const GFitsTable* hdu) if (hdu != NULL) { // Get pointer to data columns - const GFitsTableCol* energy_lo = &(*hdu)["ENERG_LO"]; - const GFitsTableCol* energy_hi = &(*hdu)["ENERG_HI"]; - const GFitsTableCol* specresp = &(*hdu)["SPECRESP"]; + const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"]; + const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"]; + const GFitsTableCol* specresp = (*hdu)["SPECRESP"]; // Determine effective area conversion factor. Internal // units are cm^2 @@ -384,9 +384,9 @@ void GArf::write(GFits& fits) const hdu->extname("SPECRESP"); // Append columns to table - hdu->append_column(energy_lo); - hdu->append_column(energy_hi); - hdu->append_column(specresp); + hdu->append(energy_lo); + hdu->append(energy_hi); + hdu->append(specresp); // Append HDU to FITS file fits.append(*hdu); diff --git a/src/xspec/GPha.cpp b/src/xspec/GPha.cpp index bc658e4..c01583f 100644 --- a/src/xspec/GPha.cpp +++ b/src/xspec/GPha.cpp @@ -400,7 +400,7 @@ void GPha::read(const GFitsTable* hdu) if (hdu != NULL) { // Get data column - const GFitsTableCol& col_data = (*hdu)["COUNTS"]; + const GFitsTableCol* col_data = (*hdu)["COUNTS"]; // Extract number of channels in FITS file int length = hdu->integer("NAXIS2"); @@ -423,7 +423,7 @@ void GPha::read(const GFitsTable* hdu) // Copy data for (int i = 0; i < length; ++i) { - m_counts[i] = col_data.real(i); + m_counts[i] = col_data->real(i); } } // endif: HDU was valid @@ -469,14 +469,14 @@ void GPha::write(GFits& fits) const hdu->extname("SPECTRUM"); // Append columns to table - hdu->append_column(col_chan); - hdu->append_column(col_data); - hdu->append_column(col_stat); - hdu->append_column(col_syst); - hdu->append_column(col_qual); - hdu->append_column(col_grpg); - hdu->append_column(col_area); - hdu->append_column(col_back); + hdu->append(col_chan); + hdu->append(col_data); + hdu->append(col_stat); + hdu->append(col_syst); + hdu->append(col_qual); + hdu->append(col_grpg); + hdu->append(col_area); + hdu->append(col_back); // Append HDU to FITS file fits.append(*hdu); diff --git a/src/xspec/GRmf.cpp b/src/xspec/GRmf.cpp index 0bfb300..e868287 100644 --- a/src/xspec/GRmf.cpp +++ b/src/xspec/GRmf.cpp @@ -331,12 +331,12 @@ void GRmf::read(const GFitsTable* hdu) m_ebds_true.clear(); // Get pointer to data columns - const GFitsTableCol* energy_lo = &(*hdu)["ENERG_LO"]; - const GFitsTableCol* energy_hi = &(*hdu)["ENERG_HI"]; - const GFitsTableCol* n_grp = &(*hdu)["N_GRP"]; - const GFitsTableCol* f_chan = &(*hdu)["F_CHAN"]; - const GFitsTableCol* n_chan = &(*hdu)["N_CHAN"]; - const GFitsTableCol* matrix = &(*hdu)["MATRIX"]; + const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"]; + const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"]; + const GFitsTableCol* n_grp = (*hdu)["N_GRP"]; + const GFitsTableCol* f_chan = (*hdu)["F_CHAN"]; + const GFitsTableCol* n_chan = (*hdu)["N_CHAN"]; + const GFitsTableCol* matrix = (*hdu)["MATRIX"]; // Set matrix rows and columns int rows = energy_lo->length(); @@ -482,12 +482,12 @@ void GRmf::write(GFits& fits) const hdu->extname("MATRIX"); // Append columns to table - hdu->append_column(energy_lo); - hdu->append_column(energy_hi); - hdu->append_column(n_grp); - hdu->append_column(f_chan); - hdu->append_column(n_chan); - hdu->append_column(matrix); + hdu->append(energy_lo); + hdu->append(energy_hi); + hdu->append(n_grp); + hdu->append(f_chan); + hdu->append(n_chan); + hdu->append(matrix); // Append HDU to FITS file fits.append(*hdu); diff --git a/test/test_GFits.cpp b/test/test_GFits.cpp index e0c255d..33a09a1 100644 --- a/test/test_GFits.cpp +++ b/test/test_GFits.cpp @@ -348,10 +348,10 @@ try { \ GFits fits; \ fits.open(filename, true); \ - GFitsBinTable table = GFitsBinTable(nrows); \ - table.append_column(col1); \ - table.insert_column(1, col2); \ - table.append_column(col3); \ + GFitsBinTable table(nrows); \ + table.append(col1); \ + table.insert(1, col2); \ + table.append(col3); \ fits.append(table); \ fits.save(); \ fits.close(); \ @@ -498,8 +498,8 @@ void TestGFits::test_create(void) first(1) = 2.0; first(2) = 3.0; second(0) = -99.0; - table.append_column(first); - table.append_column(second); + table.append(first); + table.append(second); // Append table to FILE file fits.append(table); @@ -529,8 +529,8 @@ void TestGFits::test_create(void) first(1) = 2.0; first(2) = 3.0; second(0) = -99.0; - table.append_column(first); - table.append_column(second); + table.append(first); + table.append(second); // Append table to FILE file fits.append(table); @@ -1024,8 +1024,8 @@ void TestGFits::test_bintable_double(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["DOUBLE"]); - col2 = static_cast((*fits.table(1))["DOUBLE10"]); + col1 = static_cast(*(*fits.table(1))["DOUBLE"]); + col2 = static_cast(*(*fits.table(1))["DOUBLE10"]); fits.close(); test_try_success(); } @@ -1078,8 +1078,8 @@ void TestGFits::test_bintable_float(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["FLOAT"]); - col2 = static_cast((*fits.table(1))["FLOAT10"]); + col1 = static_cast(*(*fits.table(1))["FLOAT"]); + col2 = static_cast(*(*fits.table(1))["FLOAT10"]); fits.close(); test_try_success(); } @@ -1133,8 +1133,8 @@ void TestGFits::test_bintable_short(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["SHORT"]); - col2 = static_cast((*fits.table(1))["SHORT10"]); + col1 = static_cast(*(*fits.table(1))["SHORT"]); + col2 = static_cast(*(*fits.table(1))["SHORT10"]); fits.close(); test_try_success(); } @@ -1188,8 +1188,8 @@ void TestGFits::test_bintable_short(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["USHORT"]); - col2 = static_cast((*fits.table(1))["USHORT10"]); + col1 = static_cast(*(*fits.table(1))["USHORT"]); + col2 = static_cast(*(*fits.table(1))["USHORT10"]); fits.close(); test_try_success(); } @@ -1243,8 +1243,8 @@ void TestGFits::test_bintable_long(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["LONG"]); - col2 = static_cast((*fits.table(1))["LONG10"]); + col1 = static_cast(*(*fits.table(1))["LONG"]); + col2 = static_cast(*(*fits.table(1))["LONG10"]); fits.close(); test_try_success(); } @@ -1298,8 +1298,8 @@ void TestGFits::test_bintable_longlong(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["LONGLONG"]); - col2 = static_cast((*fits.table(1))["LONGLONG10"]); + col1 = static_cast(*(*fits.table(1))["LONGLONG"]); + col2 = static_cast(*(*fits.table(1))["LONGLONG10"]); fits.close(); test_try_success(); } @@ -1353,8 +1353,8 @@ void TestGFits::test_bintable_ulong(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["ULONG"]); - col2 = static_cast((*fits.table(1))["ULONG10"]); + col1 = static_cast(*(*fits.table(1))["ULONG"]); + col2 = static_cast(*(*fits.table(1))["ULONG10"]); fits.close(); test_try_success(); } @@ -1409,8 +1409,8 @@ void TestGFits::test_bintable_string(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["STRING"]); - col2 = static_cast((*fits.table(1))["STRING10"]); + col1 = static_cast(*(*fits.table(1))["STRING"]); + col2 = static_cast(*(*fits.table(1))["STRING10"]); fits.close(); test_try_success(); } @@ -1464,8 +1464,8 @@ void TestGFits::test_bintable_logical(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["LOGICAL"]); - col2 = static_cast((*fits.table(1))["LOGICAL10"]); + col1 = static_cast(*(*fits.table(1))["LOGICAL"]); + col2 = static_cast(*(*fits.table(1))["LOGICAL10"]); fits.close(); test_try_success(); } @@ -1519,8 +1519,8 @@ void TestGFits::test_bintable_bit(void) test_try("Read Tables"); try { GFits fits(filename); - col1 = static_cast((*fits.table(1))["BIT"]); - col2 = static_cast((*fits.table(1))["BIT10"]); + col1 = *(static_cast((*fits.table(1))["BIT"])); + col2 = *(static_cast((*fits.table(1))["BIT10"])); fits.close(); test_try_success(); } diff --git a/test/test_GFits.py b/test/test_GFits.py index 8017f7d..9c359bd 100755 --- a/test/test_GFits.py +++ b/test/test_GFits.py @@ -154,34 +154,34 @@ class Test(GPythonTestSuite): # Set ASCII table tbl_ascii = GFitsAsciiTable() - # tbl_ascii.append_column(col1) # Need to implement ?/! - # tbl_ascii.append_column(col2) # Need to implement ?/! - tbl_ascii.append_column(col3) - tbl_ascii.append_column(col4) - tbl_ascii.append_column(col5) - tbl_ascii.append_column(col6) - tbl_ascii.append_column(col7) - tbl_ascii.append_column(col8) - tbl_ascii.append_column(col9) - tbl_ascii.append_column(col10) - tbl_ascii.append_column(col11) + # tbl_ascii.append(col1) # Need to implement ?/! + # tbl_ascii.append(col2) # Need to implement ?/! + tbl_ascii.append(col3) + tbl_ascii.append(col4) + tbl_ascii.append(col5) + tbl_ascii.append(col6) + tbl_ascii.append(col7) + tbl_ascii.append(col8) + tbl_ascii.append(col9) + tbl_ascii.append(col10) + tbl_ascii.append(col11) tbl_ascii.extname("ASCII table") fits.append(tbl_ascii) sys.stdout.write(".") # Set binary table tbl_bin = GFitsBinTable() - tbl_bin.append_column(col1) - tbl_bin.append_column(col2) - tbl_bin.append_column(col3) - tbl_bin.append_column(col4) - tbl_bin.append_column(col5) - tbl_bin.append_column(col6) - tbl_bin.append_column(col7) - tbl_bin.append_column(col8) - tbl_bin.append_column(col9) - tbl_bin.append_column(col10) - tbl_bin.append_column(col11) + tbl_bin.append(col1) + tbl_bin.append(col2) + tbl_bin.append(col3) + tbl_bin.append(col4) + tbl_bin.append(col5) + tbl_bin.append(col6) + tbl_bin.append(col7) + tbl_bin.append(col8) + tbl_bin.append(col9) + tbl_bin.append(col10) + tbl_bin.append(col11) tbl_bin.extname("Binary table") fits.append(tbl_bin) sys.stdout.write(".") -- libgit2 0.21.4