Commit 6c5f557d0a84287eec21b30e002973c76ad14bc0
1 parent
b1ae56cb
Updated ctool.cpp to run in the latest GFilename scheme
Integrate code
Showing
1 changed file
with
30 additions
and
18 deletions
src/support/ctool.cpp
| @@ -414,26 +414,38 @@ GEbounds ctool::create_ebounds(void) | @@ -414,26 +414,38 @@ GEbounds ctool::create_ebounds(void) | ||
| 414 | // Get filename | 414 | // Get filename |
| 415 | std::string ebinfile = (*this)["ebinfile"].filename(); | 415 | std::string ebinfile = (*this)["ebinfile"].filename(); |
| 416 | 416 | ||
| 417 | - // Open energy boundary file using the EBOUNDS or ENERGYBINS | ||
| 418 | - // extension. Throw an exception if opening fails. | ||
| 419 | - GFits file(ebinfile); | ||
| 420 | - if (file.contains("EBOUNDS")) { | ||
| 421 | - file.close(); | ||
| 422 | - ebounds.load(ebinfile,"EBOUNDS"); | ||
| 423 | - } | ||
| 424 | - else if (file.contains("ENERGYBINS")) { | ||
| 425 | - file.close(); | ||
| 426 | - ebounds.load(ebinfile,"ENERGYBINS"); | 417 | + // Create filename instance |
| 418 | + GFilename fname(ebinfile); | ||
| 419 | + | ||
| 420 | + // Check if extension name was provided | ||
| 421 | + if (!fname.has_extname()) { | ||
| 422 | + | ||
| 423 | + // Open energy boundary file using the EBOUNDS or ENERGYBINS | ||
| 424 | + // extension. Throw an exception if opening fails. | ||
| 425 | + GFits file(ebinfile); | ||
| 426 | + if (file.contains("EBOUNDS")) { | ||
| 427 | + file.close(); | ||
| 428 | + ebounds.load(ebinfile); | ||
| 429 | + } | ||
| 430 | + else if (file.contains("ENERGYBINS")) { | ||
| 431 | + file.close(); | ||
| 432 | + ebinfile += "[ENERGYBINS]"; | ||
| 433 | + ebounds.load(ebinfile); | ||
| 434 | + } | ||
| 435 | + else { | ||
| 436 | + file.close(); | ||
| 437 | + std::string msg = "No extension with name \"EBOUNDS\" or" | ||
| 438 | + " \"ENERGYBINS\" found in FITS file" | ||
| 439 | + " \""+ebinfile+"\".\n" | ||
| 440 | + "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | ||
| 441 | + " is required if the parameter \"ebinalg\"" | ||
| 442 | + " is set to \"FILE\"."; | ||
| 443 | + throw GException::invalid_value(G_CREATE_EBOUNDS, msg); | ||
| 444 | + } | ||
| 427 | } | 445 | } |
| 428 | else { | 446 | else { |
| 429 | - file.close(); | ||
| 430 | - std::string msg = "No extension with name \"EBOUNDS\" or" | ||
| 431 | - " \"ENERGYBINS\" found in FITS file" | ||
| 432 | - " \""+ebinfile+"\".\n" | ||
| 433 | - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | ||
| 434 | - " is required if the parameter \"ebinalg\"" | ||
| 435 | - " is set to \"FILE\"."; | ||
| 436 | - throw GException::invalid_value(G_CREATE_EBOUNDS, msg); | 447 | + // Load ebounds from filename including extension |
| 448 | + ebounds.load(ebinfile); | ||
| 437 | } | 449 | } |
| 438 | 450 | ||
| 439 | } // endif: ebinalg was "FILE" | 451 | } // endif: ebinalg was "FILE" |