@@ -96,8 +96,11 @@ FitsImageSource::FitsImageSource(const std::string& filename, int hdu_number,
9696
9797 fits_get_img_param (fptr, 2 , &bitpix, &naxis, naxes, &status);
9898 if (status != 0 || (naxis != 2 && naxis != 3 )) {
99+ char error_message[32 ];
100+ fits_get_errstatus (status, error_message);
99101 throw Elements::Exception ()
100- << " Can't find 2D image or data cube in FITS file: " << filename << " [" << m_hdu_number << " ]" ;
102+ << " Can't find 2D image or data cube in FITS file: " << filename << " [" << m_hdu_number << " ]"
103+ << " status: " << status << " = " << error_message;
101104 }
102105
103106 m_width = naxes[0 ];
@@ -139,15 +142,21 @@ FitsImageSource::FitsImageSource(const std::string& filename, int width, int hei
139142 if (empty_primary && acc->m_fd .getImageHdus ().empty ()) {
140143 fits_create_img (fptr, FLOAT_IMG, 0 , nullptr , &status);
141144 if (status != 0 ) {
142- throw Elements::Exception () << " Can't create empty hdu: " << filename << " status: " << status;
145+ char error_message[32 ];
146+ fits_get_errstatus (status, error_message);
147+ throw Elements::Exception () << " Can't create empty hdu: " << filename
148+ << " status: " << status << " = " << error_message;
143149 }
144150 }
145151
146152 long naxes[2 ] = {width, height};
147153 fits_create_img (fptr, getImageType (), 2 , naxes, &status);
148154
149155 if (fits_get_hdu_num (fptr, &m_hdu_number) < 0 ) {
150- throw Elements::Exception () << " Can't get the active HDU from the FITS file: " << filename << " status: " << status;
156+ char error_message[32 ];
157+ fits_get_errstatus (status, error_message);
158+ throw Elements::Exception () << " Can't get the active HDU from the FITS file: " << filename
159+ << " status: " << status << " = " << error_message;
151160 }
152161
153162 int hdutype = 0 ;
@@ -164,9 +173,10 @@ FitsImageSource::FitsImageSource(const std::string& filename, int width, int hei
164173
165174 fits_update_card (fptr, padded_key.str ().c_str (), str.c_str (), &status);
166175 if (status != 0 ) {
167- char err_txt[31 ];
168- fits_get_errstatus (status, err_txt);
169- throw Elements::Exception () << " Couldn't write the WCS headers (" << err_txt << " ): " << str << " status: " << status;
176+ char error_message[32 ];
177+ fits_get_errstatus (status, error_message);
178+ throw Elements::Exception () << " Couldn't write the WCS headers: " << filename
179+ << " status: " << status << " = " << error_message;
170180 }
171181 }
172182 }
@@ -178,7 +188,10 @@ FitsImageSource::FitsImageSource(const std::string& filename, int width, int hei
178188 }
179189
180190 if (status != 0 ) {
181- throw Elements::Exception () << " Couldn't allocate space for new FITS file: " << filename << " status: " << status;
191+ char error_message[32 ];
192+ fits_get_errstatus (status, error_message);
193+ throw Elements::Exception () << " Couldn't allocate space for new FITS file: " << filename
194+ << " status: " << status << " = " << error_message;
182195 }
183196
184197 acc->m_fd .refresh (); // make sure changes to the file structure are taken into account
@@ -209,7 +222,10 @@ std::shared_ptr<ImageTile> FitsImageSource::getImageTile(int x, int y, int width
209222 fits_read_subset (fptr, getDataType (), first_pixel, last_pixel, increment,
210223 nullptr , tile->getDataPtr (), nullptr , &status);
211224 if (status != 0 ) {
212- throw Elements::Exception () << " Error reading image tile from FITS file." ;
225+ char error_message[32 ];
226+ fits_get_errstatus (status, error_message);
227+ throw Elements::Exception () << " Error reading image tile from FITS file."
228+ << " status: " << status << " = " << error_message;
213229 }
214230
215231 return tile;
@@ -231,7 +247,10 @@ void FitsImageSource::saveTile(ImageTile& tile) {
231247
232248 fits_write_subset (fptr, getDataType (), first_pixel, last_pixel, tile.getDataPtr (), &status);
233249 if (status != 0 ) {
234- throw Elements::Exception () << " Error saving image tile to FITS file." ;
250+ char error_message[32 ];
251+ fits_get_errstatus (status, error_message);
252+ throw Elements::Exception () << " Error saving image tile to FITS file."
253+ << " status: " << status << " = " << error_message;
235254 }
236255 fits_flush_buffer (fptr, 0 , &status);
237256}
@@ -243,8 +262,10 @@ void FitsImageSource::switchHdu(fitsfile *fptr, int hdu_number) const {
243262 fits_movabs_hdu (fptr, hdu_number, &hdu_type, &status);
244263
245264 if (status != 0 ) {
246- throw Elements::Exception () << " Could not switch to HDU # " << hdu_number << " in file "
247- << m_filename;
265+ char error_message[32 ];
266+ fits_get_errstatus (status, error_message);
267+ throw Elements::Exception () << " Could not switch to HDU # " << hdu_number << " in file " << m_filename
268+ << " status: " << status << " = " << error_message;
248269 }
249270 if (hdu_type != IMAGE_HDU) {
250271 throw Elements::Exception () << " Trying to access non-image HDU in file " << m_filename;
@@ -324,9 +345,10 @@ void FitsImageSource::setMetadata(const std::string& key, const MetadataEntry& v
324345 fits_update_card (fptr, padded_key.str ().c_str (), str.c_str (), &status);
325346
326347 if (status != 0 ) {
327- char err_txt[31 ];
328- fits_get_errstatus (status, err_txt);
329- throw Elements::Exception () << " Couldn't write the metadata (" << err_txt << " ): " << str;
348+ char error_message[32 ];
349+ fits_get_errstatus (status, error_message);
350+ throw Elements::Exception () << " Couldn't write the metadata: " << str
351+ << " status: " << status << " = " << error_message;
330352 }
331353
332354 // update the metadata
0 commit comments