Commit 7b87d97735ee8c80820e7c51fb0e6cc7f82c6760
1 parent
1eb6a5c9
throw error if pointers do not exist and add header card access
Showing
5 changed files
with
132 additions
and
21 deletions
include/GException.hpp
| ... | ... | @@ -160,6 +160,12 @@ public: |
| 160 | 160 | fits_column_not_found(string origin, string colname, int status = 0); |
| 161 | 161 | }; |
| 162 | 162 | |
| 163 | + // FITS has no header | |
| 164 | + class fits_no_header : public GExceptionHandler { | |
| 165 | + public: | |
| 166 | + fits_no_header(string origin, string message, int status = 0); | |
| 167 | + }; | |
| 168 | + | |
| 163 | 169 | // FITS has no data |
| 164 | 170 | class fits_no_data : public GExceptionHandler { |
| 165 | 171 | public: | ... | ... |
include/GFitsHDU.hpp
| ... | ... | @@ -61,15 +61,17 @@ public: |
| 61 | 61 | GFitsHDU& operator= (const GFitsHDU& hdu); |
| 62 | 62 | |
| 63 | 63 | // Methods |
| 64 | - std::string extname(void) const; | |
| 65 | - void extname(const std::string& extname); | |
| 66 | - int extno(void) const; | |
| 67 | - int exttype(void) const; | |
| 68 | - GFitsHeader* header(void) const; | |
| 69 | - GFitsData* data(void) const; | |
| 70 | - GFitsTableCol* column(const std::string& colname) const; | |
| 71 | - GFitsTableCol* column(const int& colnum) const; | |
| 72 | - void primary(void); | |
| 64 | + std::string extname(void) const; | |
| 65 | + void extname(const std::string& extname); | |
| 66 | + int extno(void) const; | |
| 67 | + int exttype(void) const; | |
| 68 | + GFitsHeader* header(void) const; | |
| 69 | + GFitsData* data(void) const; | |
| 70 | + GFitsHeaderCard* card(const std::string& keyname) const; | |
| 71 | + GFitsHeaderCard* card(const int& cardno) const; | |
| 72 | + GFitsTableCol* column(const std::string& colname) const; | |
| 73 | + GFitsTableCol* column(const int& colnum) const; | |
| 74 | + void primary(void); | |
| 73 | 75 | |
| 74 | 76 | private: |
| 75 | 77 | // Private methods |
| ... | ... | @@ -90,14 +92,4 @@ private: |
| 90 | 92 | GFitsData* m_data; //!< HDU data |
| 91 | 93 | }; |
| 92 | 94 | |
| 93 | - | |
| 94 | -/*************************************************************************** | |
| 95 | - * Inline methods * | |
| 96 | - ***************************************************************************/ | |
| 97 | -inline std::string GFitsHDU::extname(void) const { return m_name; } | |
| 98 | -inline int GFitsHDU::extno(void) const { return m_hdunum; } | |
| 99 | -inline int GFitsHDU::exttype(void) const { return m_type; } | |
| 100 | -inline GFitsHeader* GFitsHDU::header(void) const { return m_header; } | |
| 101 | -inline GFitsData* GFitsHDU::data(void) const { return m_data; } | |
| 102 | - | |
| 103 | 95 | #endif /* GFITSHDU_HPP */ | ... | ... |
src/GException.cpp
| ... | ... | @@ -317,6 +317,24 @@ GException::fits_column_not_found::fits_column_not_found(string origin, |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | /***********************************************************************//** |
| 320 | + * @brief FITS error: No header | |
| 321 | + * | |
| 322 | + * @param[in] origin Method that throws the error. | |
| 323 | + * @param[in] message Error message. | |
| 324 | + * @param[in] status cfitsio status. | |
| 325 | + ***************************************************************************/ | |
| 326 | +GException::fits_no_header::fits_no_header(string origin, | |
| 327 | + string message, | |
| 328 | + int status) | |
| 329 | +{ | |
| 330 | + m_origin = origin; | |
| 331 | + m_message = message; | |
| 332 | + if (status != 0) | |
| 333 | + m_message += " (status=" + str(status) + ")"; | |
| 334 | +} | |
| 335 | + | |
| 336 | + | |
| 337 | +/***********************************************************************//** | |
| 320 | 338 | * @brief FITS error: No data |
| 321 | 339 | * |
| 322 | 340 | * @param[in] origin Method that throws the error. | ... | ... |
src/fits/GFitsHDU.cpp
| ... | ... | @@ -11,6 +11,11 @@ |
| 11 | 11 | * * |
| 12 | 12 | * ----------------------------------------------------------------------- * |
| 13 | 13 | ***************************************************************************/ |
| 14 | +/** | |
| 15 | + * @file GFitsHDU.cpp | |
| 16 | + * @brief GFitsHDU class implementation. | |
| 17 | + * @author J. Knodlseder | |
| 18 | + */ | |
| 14 | 19 | |
| 15 | 20 | /* __ Includes ___________________________________________________________ */ |
| 16 | 21 | #include <iostream> |
| ... | ... | @@ -24,6 +29,8 @@ |
| 24 | 29 | /* __ Method name definitions ____________________________________________ */ |
| 25 | 30 | #define G_OPEN "GFitsHDU::open(int)" |
| 26 | 31 | #define G_SAVE "GFitsHDU::save()" |
| 32 | +#define G_HEADER "GFitsHDU::header()" | |
| 33 | +#define G_DATA "GFitsHDU::data()" | |
| 27 | 34 | #define G_COLUMN "GFitsHDU::column(const std::string&)" |
| 28 | 35 | #define G_NEW_IMAGE "GFitsHDU::new_image()" |
| 29 | 36 | |
| ... | ... | @@ -256,11 +263,20 @@ GFitsHDU& GFitsHDU::operator= (const GFitsHDU& hdu) |
| 256 | 263 | ==========================================================================*/ |
| 257 | 264 | |
| 258 | 265 | /***********************************************************************//** |
| 266 | + * @brief Get HDU extension name (EXTNAME keyword) | |
| 267 | + ***************************************************************************/ | |
| 268 | +std::string GFitsHDU::extname(void) const | |
| 269 | +{ | |
| 270 | + return m_name; | |
| 271 | +} | |
| 272 | + | |
| 273 | + | |
| 274 | +/***********************************************************************//** | |
| 259 | 275 | * @brief Set HDU extension name (EXTNAME keyword) |
| 260 | 276 | * |
| 261 | 277 | * @param[in] extname Name of HDU |
| 262 | 278 | * |
| 263 | - * This methos sets the extension name of the HDU. The extension name will | |
| 279 | + * This method sets the extension name of the HDU. The extension name will | |
| 264 | 280 | * be saved in the 'EXTNAME' header keyword. The header attached to the |
| 265 | 281 | * HDU will be automatically updated by this method. |
| 266 | 282 | ***************************************************************************/ |
| ... | ... | @@ -282,10 +298,89 @@ void GFitsHDU::extname(const std::string& extname) |
| 282 | 298 | |
| 283 | 299 | |
| 284 | 300 | /***********************************************************************//** |
| 301 | + * @brief Get HDU extension number | |
| 302 | +***************************************************************************/ | |
| 303 | +int GFitsHDU::extno(void) const | |
| 304 | +{ | |
| 305 | + return m_hdunum; | |
| 306 | +} | |
| 307 | + | |
| 308 | + | |
| 309 | +/***********************************************************************//** | |
| 310 | + * @brief Get HDU extension type | |
| 311 | +***************************************************************************/ | |
| 312 | +int GFitsHDU::exttype(void) const | |
| 313 | +{ | |
| 314 | + return m_type; | |
| 315 | +} | |
| 316 | + | |
| 317 | + | |
| 318 | +/***********************************************************************//** | |
| 319 | + * @brief Get pointer to header | |
| 320 | + * | |
| 321 | + * @exception GException::fits_no_header | |
| 322 | + * No header was found in HDU | |
| 323 | + ***************************************************************************/ | |
| 324 | +GFitsHeader* GFitsHDU::header(void) const | |
| 325 | +{ | |
| 326 | + // If no header pointer is available then throw exception | |
| 327 | + if (m_header == NULL) | |
| 328 | + throw GException::fits_no_header(G_HEADER, "No header found"); | |
| 329 | + | |
| 330 | + // Return header pointer | |
| 331 | + return m_header; | |
| 332 | +} | |
| 333 | + | |
| 334 | + | |
| 335 | +/***********************************************************************//** | |
| 336 | + * @brief Get pointer to data | |
| 337 | + * | |
| 338 | + * @exception GException::fits_no_data | |
| 339 | + * No data was found in HDU | |
| 340 | + ***************************************************************************/ | |
| 341 | +GFitsData* GFitsHDU::data(void) const | |
| 342 | +{ | |
| 343 | + // If no header pointer is available then throw exception | |
| 344 | + if (m_data == NULL) | |
| 345 | + throw GException::fits_no_data(G_HEADER, "No data found"); | |
| 346 | + | |
| 347 | + // Return data pointer | |
| 348 | + return m_data; | |
| 349 | +} | |
| 350 | + | |
| 351 | + | |
| 352 | +/***********************************************************************//** | |
| 353 | + * @brief Get pointer to header card | |
| 354 | + * | |
| 355 | + * @param[in] keyname Name of header card | |
| 356 | + ***************************************************************************/ | |
| 357 | +GFitsHeaderCard* GFitsHDU::card(const std::string& keyname) const | |
| 358 | +{ | |
| 359 | + return m_header->card(keyname); | |
| 360 | +} | |
| 361 | + | |
| 362 | + | |
| 363 | +/***********************************************************************//** | |
| 364 | + * @brief Get pointer to header card | |
| 365 | + * | |
| 366 | + * @param[in] cardno Number of card in header | |
| 367 | + ***************************************************************************/ | |
| 368 | +GFitsHeaderCard* GFitsHDU::card(const int& cardno) const | |
| 369 | +{ | |
| 370 | + return m_header->card(cardno); | |
| 371 | +} | |
| 372 | + | |
| 373 | + | |
| 374 | +/***********************************************************************//** | |
| 285 | 375 | * @brief Return pointer to column of table |
| 286 | 376 | * |
| 287 | 377 | * @param[in] colname Name of FITS table column to be returned |
| 288 | 378 | * |
| 379 | + * @exception GException::fits_HDU_not_a_table | |
| 380 | + * HDU is not a table | |
| 381 | + * @exception GException::fits_unknown_HDU_type | |
| 382 | + * HDU type is not known | |
| 383 | + * | |
| 289 | 384 | * If this method is called for an image a 'fits_HDU_not_a_table' exception |
| 290 | 385 | * will be thrown. |
| 291 | 386 | ***************************************************************************/ | ... | ... |
src/fits/GFitsHeader.cpp
| ... | ... | @@ -189,7 +189,7 @@ GFitsHeaderCard* GFitsHeader::card(const std::string& keyname) |
| 189 | 189 | /***********************************************************************//** |
| 190 | 190 | * @brief Return pointer of header card |
| 191 | 191 | * |
| 192 | - * @param[in] keyname Name of header card | |
| 192 | + * @param[in] cardno Number of card in header | |
| 193 | 193 | * |
| 194 | 194 | * Returns a pointer on the header card. |
| 195 | 195 | * If card was not found a 'out_of_range' error will be thrown. | ... | ... |