Commit 41fcf69cb31cc601406ced58c86ef1fd9b9fd928

Authored by Jürgen Knödlseder
1 parent 5f79af82

GSkyMap::save() now overwrites existing files if clobber=true

ChangeLog
1   -2016-06-08 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
  1 +2016-06-09 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2  
3 3 * Version 1.1.0 released
4 4 =========================
5 5  
  6 + GSkyMap::save() now overwrites files (#1787)
6 7 Add GCTAPsfTable class (#1786)
7 8 Use std::vector for naxes argument in GFitsImage (#1779)
8 9 GCTACubePsf and GCTACubeEdisp now save 4D images
... ...
... ... @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0
2 2  
3 3 Author(s) : Juergen Knoedlseder
4 4  
5   -8 June 2016
  5 +9 June 2016
6 6  
7 7  
8 8 1. Introduction
... ... @@ -121,6 +121,7 @@ The interface for the following methods has been changed:
121 121 - GFitsImageShort naxes constructor
122 122 - GFitsImageULong naxes constructor
123 123 - GFitsImageUShort naxes constructor
  124 +- GSkyMap::save()
124 125  
125 126  
126 127 3. Configuration
... ... @@ -252,6 +253,9 @@ the number of dimensions. Note that a longitude and latitude dimensions
252 253 are not counted in the map dimensions, i.e. a 3D image cube with
253 254 longitude, latitude and a number of maps has a dimension of 1 (#1733).
254 255  
  256 +An optional extname argument has been added to the GSkyMap::save() method
  257 +so that the extension name can be set (#1787).
  258 +
255 259  
256 260 13. Support module
257 261 ------------------
... ...
README.md
1 1 GammaLib information
2 2 ====================
3   -* Version: 1.1.0.dev1 (8 June 2016)
  3 +* Version: 1.1.0.dev1 (9 June 2016)
4 4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu)
5 5  
6 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/)
... ...
include/GSkyMap.hpp
... ... @@ -163,7 +163,8 @@ public:
163 163 void save(const GFilename& filename,
164 164 const bool& clobber = false) const;
165 165 void read(const GFitsHDU& hdu);
166   - void write(GFits& file) const;
  166 + void write(GFits& file,
  167 + const std::string& extname = "") const;
167 168 void publish(const std::string& name = "") const;
168 169 std::string print(const GChatter& chatter = NORMAL) const;
169 170  
... ...
pyext/GSkyMap.i
... ... @@ -178,7 +178,8 @@ public:
178 178 void save(const GFilename& filename,
179 179 const bool& clobber = false) const;
180 180 void read(const GFitsHDU& hdu);
181   - void write(GFits& file) const;
  181 + void write(GFits& file,
  182 + const std::string& extname = "") const;
182 183 void publish(const std::string& name = "") const;
183 184 };
184 185  
... ...
src/sky/GSkyMap.cpp
... ... @@ -1979,9 +1979,9 @@ void GSkyMap::load(const GFilename&amp; filename)
1979 1979 * @param[in] filename FITS file name.
1980 1980 * @param[in] clobber Overwrite existing file?
1981 1981 *
1982   - * Saves the sky map into a FITS file. If the file exists already the method
1983   - * will append the sky map to the FITS file in case that the @p clobber
1984   - * parameter is set to true.
  1982 + * Saves the sky map into a FITS file. If the file exists already and the
  1983 + * @p clobber parameter is true, the method will overwrite the content of
  1984 + * the existing file. Otherwise, an exception is thrown.
1985 1985 ***************************************************************************/
1986 1986 void GSkyMap::save(const GFilename& filename, const bool& clobber) const
1987 1987 {
... ... @@ -2009,21 +2009,15 @@ void GSkyMap::save(const GFilename&amp; filename, const bool&amp; clobber) const
2009 2009 hdu->extname(filename.extname());
2010 2010 }
2011 2011  
2012   - // Open or create FITS file (without extension name since the
2013   - // requested extension may not yet exist in the file)
2014   - GFits fits(filename.url(), true);
2015   -
2016   - // If the FITS file contains already an extension with the same
2017   - // name then remove now this extension
2018   - if (fits.contains(filename.extname())) {
2019   - fits.remove(filename.extname());
2020   - }
  2012 + // Initialise empty FITS file
  2013 + GFits fits;
2021 2014  
2022 2015 // Append sky map to FITS file
2023 2016 fits.append(*hdu);
2024 2017  
2025   - // Save FITS file
2026   - fits.save(clobber);
  2018 + // Save FITS file (without extension name which was extracted
  2019 + // earlier and set in the HDU)
  2020 + fits.saveto(filename.url(), clobber);
2027 2021  
2028 2022 // Delete HDU
2029 2023 delete hdu;
... ... @@ -2074,11 +2068,15 @@ void GSkyMap::read(const GFitsHDU&amp; hdu)
2074 2068  
2075 2069  
2076 2070 /***********************************************************************//**
2077   - * @brief Write skymap into FITS file
  2071 + * @brief Write sky map into FITS file
2078 2072 *
2079 2073 * @param[in] file FITS file pointer.
  2074 + * @param[in] extname Sky map extension name.
  2075 + *
  2076 + * Write the sky map into a FITS file. Optionally, the extension name of
  2077 + * the FITS HDU can be specified using the @p extname parameter.
2080 2078 ***************************************************************************/
2081   -void GSkyMap::write(GFits& file) const
  2079 +void GSkyMap::write(GFits& file, const std::string& extname) const
2082 2080 {
2083 2081 // Continue only if we have data to save
2084 2082 if (m_proj != NULL) {
... ... @@ -2098,11 +2096,19 @@ void GSkyMap::write(GFits&amp; file) const
2098 2096  
2099 2097 // Append HDU to FITS file.
2100 2098 if (hdu != NULL) {
  2099 +
  2100 + // Optionally set extension name
  2101 + if (extname.length() > 0) {
  2102 + hdu->extname(extname);
  2103 + }
  2104 +
  2105 + // Append HDU
2101 2106 file.append(*hdu);
2102   - }
2103 2107  
2104   - // Delete HDU
2105   - if (hdu != NULL) delete hdu;
  2108 + // Delete HDU
  2109 + if (hdu != NULL) delete hdu;
  2110 +
  2111 + } // endif: there was a valid HDU
2106 2112  
2107 2113 } // endif: we had data to save
2108 2114  
... ...
test/test_GSky.cpp
... ... @@ -1201,13 +1201,15 @@ void TestGSky::test_GSkyMap_io(void)
1201 1201 wcs3(i,k) = 3.0*double(i+k+1);
1202 1202 }
1203 1203 }
1204   - healpix1.save(filename+"[HEALPIX1]", true);
1205   - wcs1.save(filename+"[WCS1]", true);
1206   - healpix2.save(filename+"[HEALPIX2]", true);
1207   - wcs2.save(filename+"[WCS2]", true);
  1204 + GFits fits(filename, true);
  1205 + healpix1.write(fits, "HEALPIX1");
  1206 + wcs1.write(fits, "WCS1");
  1207 + healpix2.write(fits, "HEALPIX2");
  1208 + wcs2.write(fits, "WCS2");
1208 1209 wcs3.shape(2,2,3);
1209   - wcs3.save(filename+"[WCS3]", true);
1210   -
  1210 + wcs3.write(fits, "WCS3");
  1211 + fits.save(true);
  1212 +
1211 1213 // Load HEALPix map and check content
1212 1214 GSkyMap map1(filename+"[HEALPIX1]");
1213 1215 test_value(map1.npix(), healpix1.npix(), "Check number of HEALPix pixels");
... ...