Commit d7308f66 authored by Robert Butora's avatar Robert Butora
Browse files

vlkb: header subcommands now actually writes/updates the header in the given fits-file

parent f80ad873
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ class frameset
      overlap_ranges overlap(coordinates coord);

      void write(std::ostream& ostrm, std::string header);
      void write2(std::string fits_pathname, int hdunum);

      std::ostream& serialize(std::ostream& strm) const;

+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ class header
      int read_record(int keynum, char *card, int *status);
      int get_nkeys();
      void update(const std::vector<fits_card> additional_cards);
      void update(const std::string card);
      std::string get_header(bool apply_fixes = false);
      std::string read_card(std::string keyname);
      bool contains_card(std::string keyname);
+24 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@


#include "ast_frameset.hpp"
#include "fits_header.hpp"
#include "io.hpp"
#include "my_assert.hpp"

@@ -650,6 +651,29 @@ void ast::frameset::write(std::ostream& ostrm, std::string header)
}


void ast::frameset::write2(std::string fits_pathname, int hdunum)
{
   LOG_trace(__func__);

   AstFitsChan * fchan = astFitsChan( NULL, NULL, "Encoding=FITS-WCS" );

   astWrite(fchan, m_hdr_fs);
   if ( !astOK )
      throw runtime_error(failed_with_status(__FILE__,__LINE__,"astWrite(fchan, m_hdr_fs)"));

   fits::header hdr(fits_pathname, hdunum, READWRITE);

   char card[ 81 ];
   astClear( fchan, "Card" );
   while ( astFindFits( fchan, "%f", card, 1 ) )
   {
      if(0 ==string(card).compare(0,7,"WCSAXES")) continue; // writes this key after other existing CRxxx keys, which is illegal
      cout << string(card) << endl;
      hdr.update(card);
   }
}





+18 −0
Original line number Diff line number Diff line
@@ -445,6 +445,24 @@ void fits::header::update_card(const struct fits_card new_card)
}


void fits::header::update(const std::string card)
{
   LOG_trace(__func__);

   int status = 0;
   int keylength;
   char ccard[FLEN_CARD];
   char keyname[FLEN_KEYWORD];

   strcpy(ccard ,card.c_str());

   if(fits_get_keyname(ccard, keyname, &keylength, &status))
      throw runtime_error(cfitsio_errmsg(__FILE__,__LINE__,status) + " card: " + card);

   if(fits_update_card(fptr, keyname, ccard, &status))
      throw runtime_error(cfitsio_errmsg(__FILE__,__LINE__,status) + " card: " + card);
}



void fits::header::update(const vector<fits_card> additional_cards)
+12 −3
Original line number Diff line number Diff line
@@ -94,6 +94,15 @@ int vlkb_listbounds(const string& skysys_str, const string& specsys_str, const s
const string VELOLSRK{"System=VELO,StdOfRest=LSRK,Unit=km/s"};
const string WAVEBARY{"System=WAVE,StdOfRest=Bary,Unit=m"};
*/

void write_previous(string header, string filename)
{
   std::ofstream out(filename);
   out << header;
}



int header_modif_coordsys(const string& skysys_str, const string& specsys_str, const string& pathname)
{
   LOG_trace(__func__);
@@ -109,20 +118,20 @@ int header_modif_coordsys(const string& skysys_str, const string& specsys_str, c

      fitsfiles::Hdu hd = allHdus.at(i);

      write_previous(hd.m_header, "backup.fitshdu"+ to_string(i) +"header.orig");
      ast::frameset frm_set(hd.m_header);
      frm_set.set_skysystem(skysys_str); 
      if(frm_set.has_specframe())
         frm_set.set_specsystem(specsys_str);

      frm_set.write(cout, hd.m_header);
      //frm_set.write(cout, hd.m_header);
      frm_set.write2(pathname, i+1);
   }

   return 0;
}




//---------------------------------------------------------------------
// overlap with area given in query-string form (name=value&...)
//---------------------------------------------------------------------