From e9039de9e028f750211db9041983ad1450d39be1 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Fri, 5 Aug 2011 18:59:22 +0000 Subject: [PATCH] add fits_inconsistent_tdim exception --- include/GException.hpp | 8 ++++++++ src/fits/GException_fits.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 0 deletions(-) diff --git a/include/GException.hpp b/include/GException.hpp index 1a75197..9cbcc7a 100644 --- a/include/GException.hpp +++ b/include/GException.hpp @@ -29,6 +29,7 @@ /* __ Includes ___________________________________________________________ */ #include // string +#include // string #include // ostringstream #include // exception #include "GTime.hpp" @@ -310,6 +311,13 @@ public: int max_rows, std::string message = ""); }; + class fits_inconsistent_tdim : public GExceptionHandler { + public: + fits_inconsistent_tdim(std::string origin, + std::vector tdim, + int number, + std::string message = ""); + }; // GSkymap exceptions diff --git a/src/fits/GException_fits.cpp b/src/fits/GException_fits.cpp index bf0eea0..fdeda80 100644 --- a/src/fits/GException_fits.cpp +++ b/src/fits/GException_fits.cpp @@ -565,3 +565,48 @@ GException::fits_invalid_nrows::fits_invalid_nrows(std::string origin, } +/***********************************************************************//** + * @brief FITS error: Inconsistent TDIM information + * + * @param[in] origin Method that throws the error. + * @param[in] tdim Number of rows. + * @param[in] number Expected total number of elements. + * @param[in] message Error message. + ***************************************************************************/ +GException::fits_inconsistent_tdim::fits_inconsistent_tdim(std::string origin, + std::vector tdim, + int number, + std::string message) +{ + // Set origin + m_origin = origin; + + // Set message + if (tdim.size() < 1) { + m_message = "Empty TDIM keyword encountered."; + } + else { + // Compute expectation + std::string sdim = "("+str(tdim[0]); + int num = tdim[0]; + for (int k = 1; k < tdim.size(); ++k) { + sdim += ","+str(tdim[k]); + num *= tdim[k]; + } + sdim += ")"; + + // Set message + m_message = "TDIM keyword "+sdim+" predicts "+str(num)+" column" + " elements, while there are "+str(number)+" elements" + " in the column."; + } + + // Set optional message + if (message.length() > 0) + m_message += " "+message; + + // Return + return; +} + + -- libgit2 0.21.4