Commit e9039de9e028f750211db9041983ad1450d39be1

Authored by knodlseder
1 parent 92099a5d

add fits_inconsistent_tdim exception

include/GException.hpp
... ... @@ -29,6 +29,7 @@
29 29  
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include <string> // string
  32 +#include <vector> // string
32 33 #include <sstream> // ostringstream
33 34 #include <stdexcept> // exception
34 35 #include "GTime.hpp"
... ... @@ -310,6 +311,13 @@ public:
310 311 int max_rows,
311 312 std::string message = "");
312 313 };
  314 + class fits_inconsistent_tdim : public GExceptionHandler {
  315 + public:
  316 + fits_inconsistent_tdim(std::string origin,
  317 + std::vector<int> tdim,
  318 + int number,
  319 + std::string message = "");
  320 + };
313 321  
314 322  
315 323 // GSkymap exceptions
... ...
src/fits/GException_fits.cpp
... ... @@ -565,3 +565,48 @@ GException::fits_invalid_nrows::fits_invalid_nrows(std::string origin,
565 565 }
566 566  
567 567  
  568 +/***********************************************************************//**
  569 + * @brief FITS error: Inconsistent TDIM information
  570 + *
  571 + * @param[in] origin Method that throws the error.
  572 + * @param[in] tdim Number of rows.
  573 + * @param[in] number Expected total number of elements.
  574 + * @param[in] message Error message.
  575 + ***************************************************************************/
  576 +GException::fits_inconsistent_tdim::fits_inconsistent_tdim(std::string origin,
  577 + std::vector<int> tdim,
  578 + int number,
  579 + std::string message)
  580 +{
  581 + // Set origin
  582 + m_origin = origin;
  583 +
  584 + // Set message
  585 + if (tdim.size() < 1) {
  586 + m_message = "Empty TDIM keyword encountered.";
  587 + }
  588 + else {
  589 + // Compute expectation
  590 + std::string sdim = "("+str(tdim[0]);
  591 + int num = tdim[0];
  592 + for (int k = 1; k < tdim.size(); ++k) {
  593 + sdim += ","+str(tdim[k]);
  594 + num *= tdim[k];
  595 + }
  596 + sdim += ")";
  597 +
  598 + // Set message
  599 + m_message = "TDIM keyword "+sdim+" predicts "+str(num)+" column"
  600 + " elements, while there are "+str(number)+" elements"
  601 + " in the column.";
  602 + }
  603 +
  604 + // Set optional message
  605 + if (message.length() > 0)
  606 + m_message += " "+message;
  607 +
  608 + // Return
  609 + return;
  610 +}
  611 +
  612 +
... ...