Commit 32989d1fee1fa3da444a9c3682d49ea70e2df265

Authored by Jürgen Knödlseder
1 parent 83078827

Put back extension handling in GFits::open().

inst/com/src/GCOMEventCube.cpp
... ... @@ -366,13 +366,13 @@ int GCOMEventCube::naxis(const int& axis) const
366 366 void GCOMEventCube::load(const GFilename& filename)
367 367 {
368 368 // Open DRE FITS file
369   - GFits file(filename);
  369 + GFits fits(filename);
370 370  
371 371 // Load DRE cube from FITS file
372   - read(file);
  372 + read(fits);
373 373  
374 374 // Close FITS file
375   - file.close();
  375 + fits.close();
376 376  
377 377 // Return
378 378 return;
... ... @@ -383,7 +383,7 @@ void GCOMEventCube::load(const GFilename& filename)
383 383 * @brief Save COMPTEL event cube into FITS file
384 384 *
385 385 * @param[in] filename FITS filename.
386   - * @param[in] clobber Overwrite existing FITS file (default=false).
  386 + * @param[in] clobber Overwrite existing FITS file? (default: false).
387 387 *
388 388 * Save the COMPTEL event cube into FITS file.
389 389 ***************************************************************************/
... ...
inst/com/src/GCOMResponse.cpp
... ... @@ -480,16 +480,16 @@ void GCOMResponse::load(const std::string& rspname)
480 480 }
481 481  
482 482 // Open FITS file
483   - GFits file(filename);
  483 + GFits fits(filename);
484 484  
485 485 // Get IAQ image
486   - const GFitsImage& iaq = *file.image(0);
  486 + const GFitsImage& iaq = *fits.image(0);
487 487  
488 488 // Read IAQ
489 489 read(iaq);
490 490  
491 491 // Close ARF FITS file
492   - file.close();
  492 + fits.close();
493 493  
494 494 // Return
495 495 return;
... ...
inst/cta/src/GCTAAeff2D.cpp
... ... @@ -355,16 +355,16 @@ void GCTAAeff2D::write(GFitsBinTable& table) const
355 355 void GCTAAeff2D::load(const GFilename& filename)
356 356 {
357 357 // Open FITS file
358   - GFits file(filename);
  358 + GFits fits(filename);
359 359  
360 360 // Get effective area table
361   - const GFitsTable& table = *file.table(filename.extname("EFFECTIVE AREA"));
  361 + const GFitsTable& table = *fits.table(filename.extname("EFFECTIVE AREA"));
362 362  
363 363 // Read effective area from table
364 364 read(table);
365 365  
366 366 // Close FITS file
367   - file.close();
  367 + fits.close();
368 368  
369 369 // Store filename
370 370 m_filename = filename;
... ... @@ -395,7 +395,7 @@ void GCTAAeff2D::save(const GFilename& filename, const bool& clobber) const
395 395 // Get extension name
396 396 std::string extname = filename.extname("EFFECTIVE AREA");
397 397  
398   - // Open or create FITS file
  398 + // Open or create FITS file (without extension)
399 399 GFits fits(filename, true);
400 400  
401 401 // Remove extension if it exists already
... ...
inst/cta/src/GCTAAeffArf.cpp
... ... @@ -250,16 +250,16 @@ GCTAAeffArf* GCTAAeffArf::clone(void) const
250 250 void GCTAAeffArf::load(const GFilename& filename)
251 251 {
252 252 // Open FITS file
253   - GFits file(filename);
  253 + GFits fits(filename);
254 254  
255 255 // Get ARF table
256   - const GFitsTable& table = *file.table(filename.extname("SPECRESP"));
  256 + const GFitsTable& table = *fits.table(filename.extname("SPECRESP"));
257 257  
258 258 // Read ARF from table
259 259 read(table);
260 260  
261 261 // Close FITS file
262   - file.close();
  262 + fits.close();
263 263  
264 264 // Store filename
265 265 m_filename = filename;
... ...
inst/cta/src/GCTAEdisp2D.cpp
... ... @@ -421,16 +421,16 @@ void GCTAEdisp2D::write(GFitsBinTable& table) const
421 421 void GCTAEdisp2D::load(const GFilename& filename)
422 422 {
423 423 // Open FITS file
424   - GFits file(filename);
  424 + GFits fits(filename);
425 425  
426 426 // Get energy dispersion table
427   - const GFitsTable& table = *file.table(filename.extname("ENERGY DISPERSION"));
  427 + const GFitsTable& table = *fits.table(filename.extname("ENERGY DISPERSION"));
428 428  
429 429 // Read energy dispersion from table
430 430 read(table);
431 431  
432 432 // Close FITS file
433   - file.close();
  433 + fits.close();
434 434  
435 435 // Store filename
436 436 m_filename = filename;
... ...
inst/cta/src/GCTAObservation.cpp
... ... @@ -896,11 +896,11 @@ void GCTAObservation::read(const GFits& fits)
896 896 if (m_events != NULL) delete m_events;
897 897 m_events = NULL;
898 898  
899   - // Initialise file name from FITS file
900   - GFilename fname(fits.filename());
  899 + // Retrieve file name from FITS file
  900 + GFilename filename(fits.filename());
901 901  
902 902 // Get extension name
903   - std::string extname = fname.extname("EVENTS");
  903 + std::string extname = filename.extname("EVENTS");
904 904  
905 905 // If FITS file contains an EVENTS extension we have an unbinned
906 906 // observation ...
... ... @@ -973,6 +973,14 @@ void GCTAObservation::write(GFits& fits, const std::string& evtname,
973 973 // Case A: Observation contains an event list
974 974 if (list != NULL) {
975 975  
  976 + // Remove HDUs if they exist already
  977 + if (fits.contains(evtname)) {
  978 + fits.remove(evtname);
  979 + }
  980 + if (fits.contains(gtiname)) {
  981 + fits.remove(gtiname);
  982 + }
  983 +
976 984 // Write event list and Good Time Intervals into FITS file
977 985 list->write(fits, evtname, gtiname);
978 986  
... ... @@ -1096,7 +1104,8 @@ void GCTAObservation::load(const GFilename& cntcube,
1096 1104 * energy boundaries and the Good Time Intervals. The extension names of
1097 1105 * these binary tables are "EBOUNDS" and "GTI", and cannot be modified.
1098 1106 ***************************************************************************/
1099   -void GCTAObservation::save(const GFilename& filename, const bool& clobber) const
  1107 +void GCTAObservation::save(const GFilename& filename,
  1108 + const bool& clobber) const
1100 1109 {
1101 1110 // Set default events and Good Time Intervals extension name and extract
1102 1111 // a possible overwrite from the extension name argument of the filename.
... ... @@ -1115,16 +1124,10 @@ void GCTAObservation::save(const GFilename& filename, const bool& clobber) const
1115 1124 }
1116 1125 }
1117 1126  
1118   - // Open or create FITS file
1119   - GFits fits(filename, true);
1120   -
1121   - // Remove HDUs if they exist already
1122   - if (fits.contains(evtname)) {
1123   - fits.remove(evtname);
1124   - }
1125   - if (fits.contains(gtiname)) {
1126   - fits.remove(gtiname);
1127   - }
  1127 + // Open or create FITS file. Since we accept here a special structure
  1128 + // for the extension that cfitsio does not understand we only pass
  1129 + // the URL without extension name to the GFits constructor.
  1130 + GFits fits(filename.url(), true);
1128 1131  
1129 1132 // Write data into FITS file
1130 1133 write(fits, evtname, gtiname);
... ...
inst/cta/src/GCTAPointing.cpp
... ... @@ -418,16 +418,16 @@ GHorizDir GCTAPointing::dir_horiz(const GTime& time) const
418 418 void GCTAPointing::load(const GFilename& filename)
419 419 {
420 420 // Open FITS file
421   - GFits file(filename);
  421 + GFits fits(filename);
422 422  
423 423 // Get pointing table
424   - const GFitsTable& table = *file.table(filename.extname("POINTING"));
  424 + const GFitsTable& table = *fits.table(filename.extname("POINTING"));
425 425  
426 426 // Read pointing from table
427 427 read(table);
428 428  
429 429 // Close FITS file
430   - file.close();
  430 + fits.close();
431 431  
432 432 // Return
433 433 return;
... ...
inst/lat/src/GLATEventCube.cpp
... ... @@ -310,13 +310,13 @@ int GLATEventCube::naxis(const int& axis) const
310 310 void GLATEventCube::load(const GFilename& filename)
311 311 {
312 312 // Open FITS file
313   - GFits file(filename);
  313 + GFits fits(filename);
314 314  
315 315 // Read event cube from FITS file
316   - read(file);
  316 + read(fits);
317 317  
318 318 // Close FITS file
319   - file.close();
  319 + fits.close();
320 320  
321 321 // Return
322 322 return;
... ...
inst/lat/src/GLATEventList.cpp
... ... @@ -252,13 +252,13 @@ GLATEventList* GLATEventList::clone(void) const
252 252 void GLATEventList::load(const GFilename& filename)
253 253 {
254 254 // Open FITS file
255   - GFits file(filename);
  255 + GFits fits(filename);
256 256  
257 257 // Read event list from FITS file
258   - read(file);
  258 + read(fits);
259 259  
260 260 // Close FITS file
261   - file.close();
  261 + fits.close();
262 262  
263 263 // Return
264 264 return;
... ...
inst/lat/src/GLATLtCube.cpp
... ... @@ -396,13 +396,13 @@ void GLATLtCube::load(const GFilename& filename)
396 396 clear();
397 397  
398 398 // Open livetime cube FITS file
399   - GFits file(filename);
  399 + GFits fits(filename);
400 400  
401 401 // Get HDUs
402   - const GFitsTable& hdu_exposure = *file.table("EXPOSURE");
403   - const GFitsTable& hdu_weighted_exposure = *file.table("WEIGHTED_EXPOSURE");
404   - //const GFitsTable& hdu_cthetabounds = *file.table("CTHETABOUNDS");
405   - const GFitsTable& hdu_gti = *file.table("GTI");
  402 + const GFitsTable& hdu_exposure = *fits.table("EXPOSURE");
  403 + const GFitsTable& hdu_weighted_exposure = *fits.table("WEIGHTED_EXPOSURE");
  404 + //const GFitsTable& hdu_cthetabounds = *fits.table("CTHETABOUNDS");
  405 + const GFitsTable& hdu_gti = *fits.table("GTI");
406 406  
407 407 // Load exposure
408 408 m_exposure.read(hdu_exposure);
... ... @@ -416,7 +416,7 @@ void GLATLtCube::load(const GFilename& filename)
416 416 m_gti.read(hdu_gti);
417 417  
418 418 // Close FITS file
419   - file.close();
  419 + fits.close();
420 420  
421 421 // Return
422 422 return;
... ...
inst/mwl/src/GMWLSpectrum.cpp
... ... @@ -264,21 +264,21 @@ void GMWLSpectrum::load(const GFilename& filename)
264 264 clear();
265 265  
266 266 // Open FITS file
267   - GFits file(filename);
  267 + GFits fits(filename);
268 268  
269 269 // Read spectrum
270 270 if (filename.has_extno()) {
271   - read(file, filename.extno());
  271 + read(fits, filename.extno());
272 272 }
273 273 else if (filename.has_extname()) {
274   - read(file, filename.extname());
  274 + read(fits, filename.extname());
275 275 }
276 276 else {
277   - read(file);
  277 + read(fits);
278 278 }
279 279  
280 280 // Close FITS file
281   - file.close();
  281 + fits.close();
282 282  
283 283 // Return
284 284 return;
... ...
src/fits/GFits.cpp
... ... @@ -1145,7 +1145,7 @@ void GFits::save(const bool& clobber)
1145 1145 // If we attempt to save an existing file without overwriting permission
1146 1146 // then throw an error
1147 1147 if (!m_created && !clobber) {
1148   - throw GException::fits_file_exist(G_SAVE, m_filename.url());
  1148 + throw GException::fits_file_exist(G_SAVE, m_filename);
1149 1149 }
1150 1150  
1151 1151 // If no FITS file has been opened then throw an error
... ... @@ -1219,14 +1219,10 @@ void GFits::save(const bool& clobber)
1219 1219 * Specified file exists already. Overwriting requires
1220 1220 * clobber=true.
1221 1221 *
1222   - * Saves object into a specific FITS file.
1223   - * Any environment variable present in the filename will be expanded.
  1222 + * Saves the FITS object into a specific file.
1224 1223 ***************************************************************************/
1225 1224 void GFits::saveto(const GFilename& filename, const bool& clobber)
1226 1225 {
1227   - // Create gzipped file name version
1228   - std::string gzfname = filename + ".gz";
1229   -
1230 1226 // Debug header
1231 1227 #if defined(G_DEBUG)
1232 1228 std::cout << "GFits::saveto(\"" << fname << "\", " << clobber << ")"
... ... @@ -1243,7 +1239,7 @@ void GFits::saveto(const GFilename&amp; filename, const bool&amp; clobber)
1243 1239 }
1244 1240  
1245 1241 // Create or open FITS file
1246   - GFits fits(filename, true);;
  1242 + GFits fits(filename, true);
1247 1243  
1248 1244 // Append all headers
1249 1245 for (int i = 0; i < size(); ++i) {
... ... @@ -1304,7 +1300,7 @@ std::string GFits::print(const GChatter&amp; chatter) const
1304 1300  
1305 1301 // Append file information
1306 1302 result.append("\n"+gammalib::parformat("Filename"));
1307   - result.append(m_filename.url());
  1303 + result.append(m_filename);
1308 1304 result.append("\n"+gammalib::parformat("History"));
1309 1305 if (m_created) {
1310 1306 result.append("new file");
... ...
src/model/GModelSpatialDiffuseCube.cpp
... ... @@ -649,7 +649,7 @@ void GModelSpatialDiffuseCube::write(GXmlElement&amp; xml) const
649 649 }
650 650  
651 651 // Set filename
652   - xml.attribute("file", m_filename.url());
  652 + xml.attribute("file", m_filename);
653 653  
654 654 // Return
655 655 return;
... ... @@ -1069,7 +1069,7 @@ std::string GModelSpatialDiffuseCube::print(const GChatter&amp; chatter) const
1069 1069  
1070 1070 // Append parameters
1071 1071 result.append("\n"+gammalib::parformat("Map cube file"));
1072   - result.append(m_filename.url());
  1072 + result.append(m_filename);
1073 1073 if (m_loaded) {
1074 1074 result.append(" [loaded]");
1075 1075 }
... ...
src/model/GModelSpatialDiffuseMap.cpp
... ... @@ -585,7 +585,7 @@ void GModelSpatialDiffuseMap::write(GXmlElement&amp; xml) const
585 585 }
586 586  
587 587 // Set model filename
588   - xml.attribute("file", m_filename.url());
  588 + xml.attribute("file", m_filename);
589 589  
590 590 // Verify model type
591 591 if (xml.attribute("type") != "SpatialMap") {
... ... @@ -840,7 +840,7 @@ std::string GModelSpatialDiffuseMap::print(const GChatter&amp; chatter) const
840 840  
841 841 // Append parameters
842 842 result.append("\n"+gammalib::parformat("Sky map file"));
843   - result.append(m_filename.url());
  843 + result.append(m_filename);
844 844 result.append("\n"+gammalib::parformat("Map normalization"));
845 845 result.append(gammalib::str(m_mc_norm)+" ph/cm2/s");
846 846 if (normalize()) {
... ... @@ -883,7 +883,7 @@ void GModelSpatialDiffuseMap::load(const GFilename&amp; filename)
883 883 m_filename = filename;
884 884  
885 885 // Load skymap
886   - m_map.load(m_filename.url());
  886 + m_map.load(m_filename);
887 887  
888 888 // Prepare sky map
889 889 prepare_map();
... ...
src/obs/GEbounds.cpp
... ... @@ -579,16 +579,16 @@ void GEbounds::set_log(const int&amp; num, const GEnergy&amp; emin, const GEnergy&amp; emax)
579 579 void GEbounds::load(const GFilename& filename)
580 580 {
581 581 // Open FITS file
582   - GFits file(filename);
  582 + GFits fits(filename);
583 583  
584 584 // Get energy boundary table
585   - const GFitsTable& table = *file.table(filename.extname("EBOUNDS"));
  585 + const GFitsTable& table = *fits.table(filename.extname("EBOUNDS"));
586 586  
587 587 // Read energy boundaries from table
588 588 read(table);
589 589  
590 590 // Close FITS file
591   - file.close();
  591 + fits.close();
592 592  
593 593 // Return
594 594 return;
... ... @@ -622,11 +622,6 @@ void GEbounds::save(const GFilename&amp; filename,
622 622 // Open or create FITS file
623 623 GFits fits(filename, true);
624 624  
625   - // Remove extension if it exists already
626   - if (fits.contains(extname)) {
627   - fits.remove(extname);
628   - }
629   -
630 625 // Write energy boundaries to FITS file
631 626 write(fits, extname, unit);
632 627  
... ...
src/obs/GEnergies.cpp
... ... @@ -548,16 +548,16 @@ void GEnergies::set_log(const int&amp; num,
548 548 void GEnergies::load(const GFilename& filename)
549 549 {
550 550 // Open FITS file
551   - GFits file(filename);
  551 + GFits fits(filename);
552 552  
553 553 // Get energies table
554   - const GFitsTable& table = *file.table(filename.extname("ENERGIES"));
  554 + const GFitsTable& table = *fits.table(filename.extname("ENERGIES"));
555 555  
556 556 // Read energies from table
557 557 read(table);
558 558  
559 559 // Close FITS file
560   - file.close();
  560 + fits.close();
561 561  
562 562 // Return
563 563 return;
... ... @@ -587,11 +587,6 @@ void GEnergies::save(const GFilename&amp; filename, const bool&amp; clobber) const
587 587 // Open or create FITS file
588 588 GFits fits(filename, true);
589 589  
590   - // Remove extension if it exists already
591   - if (fits.contains(extname)) {
592   - fits.remove(extname);
593   - }
594   -
595 590 // Write energies to FITS file
596 591 write(fits, extname);
597 592  
... ...
src/obs/GGti.cpp
... ... @@ -585,16 +585,16 @@ void GGti::extend(const GGti&amp; gti)
585 585 void GGti::load(const GFilename& filename)
586 586 {
587 587 // Open FITS file
588   - GFits file(filename);
  588 + GFits fits(filename);
589 589  
590 590 // Get GTI table
591   - const GFitsTable& table = *file.table(filename.extname("GTI"));
  591 + const GFitsTable& table = *fits.table(filename.extname("GTI"));
592 592  
593 593 // Read GTI from table
594 594 read(table);
595 595  
596 596 // Close FITS file
597   - file.close();
  597 + fits.close();
598 598  
599 599 // Return
600 600 return;
... ... @@ -625,11 +625,6 @@ void GGti::save(const GFilename&amp; filename, const bool&amp; clobber) const
625 625 // Open or create FITS file
626 626 GFits fits(filename, true);
627 627  
628   - // Remove extension if it exists already
629   - if (fits.contains(extname)) {
630   - fits.remove(extname);
631   - }
632   -
633 628 // Write GTI to FITS object
634 629 write(fits, extname);
635 630  
... ...
src/xspec/GArf.cpp
... ... @@ -255,20 +255,17 @@ const double&amp; GArf::at(const int&amp; index) const
255 255 ***************************************************************************/
256 256 void GArf::load(const GFilename& filename)
257 257 {
258   - // Clear any existing models
259   - clear();
260   -
261 258 // Open FITS file
262   - GFits file(filename);
  259 + GFits fits(filename);
263 260  
264 261 // Get ARF table
265   - const GFitsTable& table = *file.table("SPECRESP");
  262 + const GFitsTable& table = *fits.table("SPECRESP");
266 263  
267 264 // Read ARF data
268 265 read(table);
269 266  
270 267 // Close FITS file
271   - file.close();
  268 + fits.close();
272 269  
273 270 // Store filename
274 271 m_filename = filename;
... ... @@ -310,6 +307,9 @@ void GArf::save(const GFilename&amp; filename, const bool&amp; clobber) const
310 307 ***************************************************************************/
311 308 void GArf::read(const GFitsTable& table)
312 309 {
  310 + // Clear members
  311 + clear();
  312 +
313 313 // Get pointer to data columns
314 314 const GFitsTableCol* energy_lo = table["ENERG_LO"];
315 315 const GFitsTableCol* energy_hi = table["ENERG_HI"];
... ... @@ -352,6 +352,12 @@ void GArf::read(const GFitsTable&amp; table)
352 352 ***************************************************************************/
353 353 void GArf::write(GFits& fits) const
354 354 {
  355 + // If the FITS object contains already an extension with the same
  356 + // name then remove now this extension
  357 + if (fits.contains("SPECRESP")) {
  358 + fits.remove("SPECRESP");
  359 + }
  360 +
355 361 // Set column length
356 362 int length = size();
357 363  
... ... @@ -359,7 +365,7 @@ void GArf::write(GFits&amp; fits) const
359 365 if (length > 0) {
360 366  
361 367 // Create new binary table
362   - GFitsBinTable* hdu = new GFitsBinTable;
  368 + GFitsBinTable hdu;
363 369  
364 370 // Allocate floating point vector columns
365 371 GFitsTableFloatCol energy_lo("ENERG_LO", length);
... ... @@ -379,18 +385,15 @@ void GArf::write(GFits&amp; fits) const
379 385 specresp.unit("cm^2");
380 386  
381 387 // Set table attributes
382   - hdu->extname("SPECRESP");
  388 + hdu.extname("SPECRESP");
383 389  
384 390 // Append columns to table
385   - hdu->append(energy_lo);
386   - hdu->append(energy_hi);
387   - hdu->append(specresp);
  391 + hdu.append(energy_lo);
  392 + hdu.append(energy_hi);
  393 + hdu.append(specresp);
388 394  
389 395 // Append HDU to FITS file
390   - fits.append(*hdu);
391   -
392   - // Free binary table
393   - delete hdu;
  396 + fits.append(hdu);
394 397  
395 398 } // endif: there were data to write
396 399  
... ...
src/xspec/GPha.cpp
... ... @@ -373,18 +373,27 @@ void GPha::load(const GFilename&amp; filename)
373 373 * @brief Save Pulse Height Analyzer spectrum
374 374 *
375 375 * @param[in] filename File name.
376   - * @param[in] clobber Overwrite existing file? (defaults to true)
  376 + * @param[in] clobber Overwrite existing file? (default: false)
  377 + *
  378 + * Saves Pulse Height Analyzer spectrum and energy boundaries into a FITS
  379 + * file. If a file with the given @p filename does not yet exist it will be
  380 + * created, otherwise the method opens the existing file. The method will
  381 + * create (or replace an existing) Pulse Height Analyzer spectrum and energy
  382 + * boundary extensions.
  383 + *
  384 + * An existing file will only be modified if the @p clobber flag is set to
  385 + * true.
377 386 ***************************************************************************/
378 387 void GPha::save(const GFilename& filename, const bool& clobber) const
379 388 {
380   - // Open FITS file
381   - GFits fits;
  389 + // Open or create FITS file
  390 + GFits fits(filename, true);
382 391  
383 392 // Write PHA into file
384 393 write(fits);
385 394  
386 395 // Close FITS file
387   - fits.saveto(filename, clobber);
  396 + fits.save(clobber);
388 397  
389 398 // Store filename
390 399 m_filename = filename;
... ... @@ -443,6 +452,14 @@ void GPha::read(const GFitsTable&amp; table)
443 452 ***************************************************************************/
444 453 void GPha::write(GFits& fits) const
445 454 {
  455 + // Remove extensions if they exist already
  456 + if (fits.contains("EBOUNDS")) {
  457 + fits.remove("EBOUNDS");
  458 + }
  459 + if (fits.contains("SPECTRUM")) {
  460 + fits.remove("SPECTRUM");
  461 + }
  462 +
446 463 // Set column length
447 464 int length = size();
448 465  
... ...
src/xspec/GRmf.cpp
... ... @@ -376,19 +376,19 @@ void GRmf::load(const GFilename&amp; filename)
376 376 clear();
377 377  
378 378 // Open FITS file
379   - GFits file(filename);
  379 + GFits fits(filename);
380 380  
381 381 // Read measured energy boundaries
382 382 m_ebds_measured.load(filename);
383 383  
384 384 // Get RMF table
385   - const GFitsTable& table = *file.table(filename.extname("MATRIX"));
  385 + const GFitsTable& table = *fits.table(filename.extname("MATRIX"));
386 386  
387 387 // Read RMF data
388 388 read(table);
389 389  
390 390 // Close FITS file
391   - file.close();
  391 + fits.close();
392 392  
393 393 // Store filename
394 394 m_filename = filename;
... ... @@ -501,6 +501,14 @@ void GRmf::read(const GFitsTable&amp; table)
501 501 ***************************************************************************/
502 502 void GRmf::write(GFits& fits, const std::string& unit) const
503 503 {
  504 + // Remove extensions if they exist already
  505 + if (fits.contains("MATRIX")) {
  506 + fits.remove("MATRIX");
  507 + }
  508 + if (fits.contains("EBOUNDS")) {
  509 + fits.remove("EBOUNDS");
  510 + }
  511 +
504 512 // Set table length
505 513 int length = ntrue();
506 514  
... ...