diff --git a/ChangeLog b/ChangeLog index 3b0171a..17b525c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-08-12 +2016-09-26 * Version 1.2.0 released ========================= + Check CTA response table dimension for consistency (#1848) Add GTestSuite::test_value() method with automatic precision computation Add GSkyMap::is_empty() method (#1828) Add GApplication access by index operator (#1838) diff --git a/NEWS b/NEWS index c55f48b..3450da8 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.2.0 -12 August 2016 +26 September 2016 1. Introduction @@ -191,7 +191,8 @@ None 20. CTA interface ----------------- -None +The dimension of response tables is now checked for being consistent with the +axis dimension (#1848). 21. COMPTEL interface diff --git a/inst/cta/src/GCTAResponseTable.cpp b/inst/cta/src/GCTAResponseTable.cpp index 0a8d919..833043d 100644 --- a/inst/cta/src/GCTAResponseTable.cpp +++ b/inst/cta/src/GCTAResponseTable.cpp @@ -1860,6 +1860,41 @@ void GCTAResponseTable::read_tables(const GFitsTable& hdu) throw GException::invalid_value(G_READ_TABLES, msg); } + // Check table dimension if there is dimension information + if (col->dim().size() > 0) { + + // Check that the table dimension is identical to the number of + // axis pairs + if (axes() != col->dim().size()) { + std::string msg = "Table column \""+m_colname_table[i]+"\" " + "dimension "+ + gammalib::str(col->dim().size())+" is " + "inconsistent with "+ + gammalib::str(axes())+" axis pairs. Please " + "check the response table for consistency."; + throw GException::invalid_value(G_READ_TABLES, msg); + } + + // Check for all axes that the length of the axis columns is + // identical to the size of the table in that axis direction + for (int i = 0; i < axes(); ++i) { + if (axis_bins(i) != col->dim()[i]) { + std::string msg = "Table column \""+m_colname_table[i]+"\" " + "has "+gammalib::str(col->dim()[i])+ + " bins in axis "+gammalib::str(i)+ + " while corresponding axis columns \""+ + m_colname_lo[i]+"\" and \""+ + m_colname_hi[i]+"\" have a length of "+ + gammalib::str(axis_bins(i))+". Please " + "check the response table for " + "consistency."; + throw GException::invalid_value(G_READ_TABLES, msg); + } + } + + } // endif: table had dimension information + + // Initialise table std::vector table(num);