Commit 2d4b3adc authored by Robert Butora's avatar Robert Butora
Browse files

vlkb: implements header sub-command (creates new header by sky- & specsystem)

parent e797a57a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ class frameset
      std::vector<Bounds> bounds(void);
      overlap_ranges overlap(coordinates coord);

      void write(std::ostream& ostrm, std::string header);

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

   private:
+33 −6
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ ast::frameset::frameset(string header)

   astPutCards(fchan, header.c_str());
   if ( !astOK )
      throw runtime_error(failed_with_status(__FILE__,__LINE__,"astPutChards"));
      throw runtime_error(failed_with_status(__FILE__,__LINE__,"astPutCards"));

   const char * encoding = astGetC(fchan,"Encoding");
   LOG_STREAM << __func__ << " : Encoding: " << (encoding == AST__NULL ? "NULL" : encoding) << endl;
@@ -626,6 +626,33 @@ vector<Bounds> ast::frameset::bounds(void)
   return bounds_vec;
}




void ast::frameset::write(std::ostream& ostrm, std::string header)
{
   LOG_trace(__func__);

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

   astPutCards(fchan, header.c_str());
   if ( !astOK )
      throw runtime_error(failed_with_status(__FILE__,__LINE__,"astPutCards"));

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

   char card[ 81 ];
   astClear( fchan, "Card" );
   while ( astFindFits( fchan, "%f", card, 1 ) )
      ostrm << string(card) << endl;
}





#if 0
/* uses only NAXIS to create header region (however FITS header axes count can be more */
overlap_ranges ast::frameset::overlap_in_wcs(coordinates coord)
+1 −1
Original line number Diff line number Diff line
@@ -469,7 +469,7 @@ string fits::header::get_header(bool apply_fixes)

   int status = 0;
   char * header_cstr;
   const int nocomments = 1;
   const int nocomments = 0;
   int nkeys;

   if(fits_hdr2str(fptr, nocomments, NULL, 0, &header_cstr, &nkeys, &status))
+34 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@
#include "io.hpp"
#include "my_assert.hpp"

#include "ast_frameset.hpp" // FIXME temporarily was moved common/src -> common/include


#include <iostream>
#include <climits> // INT_MAX needed
#include <sstream>
@@ -84,7 +87,38 @@ int vlkb_listbounds(const string& skysys_str, const string& specsys_str, const s



//---------------------------------------------------------------------
// header modif coord sys
//---------------------------------------------------------------------
/*
const string VELOLSRK{"System=VELO,StdOfRest=LSRK,Unit=km/s"};
const string WAVEBARY{"System=WAVE,StdOfRest=Bary,Unit=m"};
*/
int header_modif_coordsys(const string& skysys_str, const string& specsys_str, const string& pathname)
{
   LOG_trace(__func__);

   int maxHdu = 1;//FIXME INT_MAX; // read all HDU's

   std::vector<fitsfiles::Hdu> allHdus = 
      fitsfiles::fname2hdrstr(pathname, maxHdu);

   for(unsigned int i=0; i<allHdus.size(); i++)
   {
      cout << "HDU#" << i << endl;

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

      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);
   }

   return 0;
}



+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

int vlkb_skyvertices(const std::string& pathname, const std::string& skysys_str);
int vlkb_listbounds(const std::string& skysys_str, const std::string& specsys_str, const std::string& pathname);
int header_modif_coordsys(const std::string& skysys_str, const std::string& specsys_str, const std::string& pathname);
int vlkb_overlap(const std::string& pathname, const std::string& region, std::vector<uint_bounds>& bnds);

#endif
Loading