Commit dab3b14cbd205555c60da0319aec27a4dc30ec81

Authored by knodlseder
1 parent 79e6207f

implement saving

include/GFitsHDU.hpp
... ... @@ -75,6 +75,7 @@ private:
75 75  
76 76 // Private data area
77 77 __fitsfile m_fitsfile; // FITS file pointer
  78 + int m_hdunum; // HDU number (starting from 1)
78 79 std::string m_name; // HDU name
79 80 int m_type; // HDU type
80 81 GFitsHeader* m_header; // HDU header
... ... @@ -86,7 +87,7 @@ private:
86 87 * Inline methods *
87 88 ***************************************************************************/
88 89 inline std::string GFitsHDU::extname(void) const { return m_name; }
89   -inline int GFitsHDU::extno(void) const { return m_fitsfile.HDUposition; }
  90 +inline int GFitsHDU::extno(void) const { return m_hdunum; }
90 91 inline int GFitsHDU::exttype(void) const { return m_type; }
91 92 inline GFitsHeader* GFitsHDU::header(void) const { return m_header; }
92 93 inline GFitsData* GFitsHDU::data(void) const { return m_data; }
... ...
src/fits/GFitsHDU.cpp
... ... @@ -143,6 +143,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
143 143 // Store information.
144 144 // Note that the HDU number - 1 is stored in m_fitsfile->HDUposition !!!
145 145 m_fitsfile = *fptr;
  146 + m_hdunum = hdunum;
146 147  
147 148 // Get HDU type
148 149 status = __ffghdt(&m_fitsfile, &m_type, &status);
... ... @@ -197,14 +198,18 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
197 198 ***************************************************************************/
198 199 void GFitsHDU::save(void)
199 200 {
  201 +cout << "GFitsHDU::save " << m_hdunum-1 << endl;
200 202 // Move to HDU
201 203 int status = 0;
202   - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  204 + status = __ffmahd(&m_fitsfile, m_hdunum, NULL, &status);
203 205  
204 206 // If HDU does not yet exist in file then create it now. This works even
205 207 // in the case that the actual HDU has no associated header and/or data
206   - // (these will be created automatically)
  208 + // (these will be created automatically). However, to make this work we have
  209 + // to set the fitsfile HDU position to the position we want to go. In that
  210 + // was the save members will know that they have to create the HDU ...
207 211 if (status == 107) {
  212 + m_fitsfile.HDUposition = m_hdunum-1;
208 213 status = 0;
209 214 switch (m_type) {
210 215 case 0: // Image HDU
... ... @@ -329,6 +334,7 @@ void GFitsHDU::init_members(void)
329 334 // Initialise members
330 335 m_fitsfile.HDUposition = 0;
331 336 m_fitsfile.Fptr = NULL;
  337 + m_hdunum = 1;
332 338 m_name.clear();
333 339 m_type = 0;
334 340 m_header = NULL;
... ... @@ -348,6 +354,7 @@ void GFitsHDU::copy_members(const GFitsHDU&amp; hdu)
348 354 {
349 355 // Copy members
350 356 m_fitsfile = hdu.m_fitsfile;
  357 + m_hdunum = hdu.m_hdunum;
351 358 m_name = hdu.m_name;
352 359 m_type = hdu.m_type;
353 360 if (hdu.m_header != NULL) m_header = hdu.m_header->clone();
... ... @@ -392,7 +399,7 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu)
392 399 {
393 400 // Put header in stream
394 401 os << "=== GFitsHDU ===" << endl;
395   - os << " HDU number ................: " << hdu.m_fitsfile.HDUposition << endl;
  402 + os << " HDU number ................: " << hdu.m_hdunum << endl;
396 403 os << " HDU name ..................: " << hdu.m_name << endl;
397 404 os << " HDU type ..................: ";
398 405 switch (hdu.m_type) {
... ...