Commit d4cf5f7d53f1f202fa767c1f9ec57c85c2b7d72f
1 parent
4ffbfa5a
Handle non-existing extension name in GFits::open().
Showing
2 changed files
with
17 additions
and
11 deletions
src/fits/GFits.cpp
| ... | ... | @@ -1039,18 +1039,30 @@ void GFits::open(const GFilename& filename, const bool& create) |
| 1039 | 1039 | int status = 0; |
| 1040 | 1040 | status = __ffopen(FHANDLE(m_fitsfile), std::string(filename).c_str(), 1, &status); |
| 1041 | 1041 | |
| 1042 | - // If failed then try opening as readonly | |
| 1043 | - if (status == 104 || status == 112) { | |
| 1042 | + // If failed then try opening as readonly. | |
| 1043 | + // | |
| 1044 | + // Possible error codes are: | |
| 1045 | + // 104: FILE_NOT_OPENED (could not open the named file) | |
| 1046 | + // 107: END_OF_FILE (tried to move past end of file, occurs if extname is invalid) | |
| 1047 | + // 112: READONLY_FILE (cannot write to readonly file) | |
| 1048 | + if (status == 104 || status == 107 || status == 112) { | |
| 1044 | 1049 | status = 0; |
| 1045 | 1050 | status = __ffopen(FHANDLE(m_fitsfile), std::string(filename).c_str(), 0, &status); |
| 1046 | 1051 | m_readwrite = false; |
| 1047 | 1052 | } |
| 1048 | 1053 | |
| 1049 | 1054 | // If failed and if we are allowed to create a new FITS file then create |
| 1050 | - // FITS file now | |
| 1051 | - if (create && status == 104) { | |
| 1055 | + // FITS file now. We pass the URL as filename since we want to create a | |
| 1056 | + // fresh file without any extension. We also remove any file before in | |
| 1057 | + // case that file exists but is not a FITS file. | |
| 1058 | + // | |
| 1059 | + // Possible error codes are: | |
| 1060 | + // 104: FILE_NOT_OPENED (could not open the named file) | |
| 1061 | + // 107: END_OF_FILE (tried to move past end of file, occurs if extname is invalid) | |
| 1062 | + if (create && (status == 104 || status == 107)) { | |
| 1063 | + filename.remove(); | |
| 1052 | 1064 | status = 0; |
| 1053 | - status = __ffinit(FHANDLE(m_fitsfile), std::string(filename).c_str(), &status); | |
| 1065 | + status = __ffinit(FHANDLE(m_fitsfile), filename.url().c_str(), &status); | |
| 1054 | 1066 | m_readwrite = true; |
| 1055 | 1067 | m_created = true; |
| 1056 | 1068 | } | ... | ... |
test/test_GObservation.cpp
| ... | ... | @@ -262,12 +262,6 @@ void TestGObservation::test_ebounds(void) |
| 262 | 262 | ***************************************************************************/ |
| 263 | 263 | void TestGObservation::test_gti(void) |
| 264 | 264 | { |
| 265 | - // Remove test files | |
| 266 | - GFilename file1("test_gti1.fits"); | |
| 267 | - GFilename file2("test_gti2.fits"); | |
| 268 | - file1.remove(); | |
| 269 | - file2.remove(); | |
| 270 | - | |
| 271 | 265 | // Test void constructor |
| 272 | 266 | test_try("Void constructor"); |
| 273 | 267 | try { | ... | ... |