diff --git a/data-access/engine/src/common/src/ast_frameset.hpp b/data-access/engine/src/common/include/ast_frameset.hpp similarity index 97% rename from data-access/engine/src/common/src/ast_frameset.hpp rename to data-access/engine/src/common/include/ast_frameset.hpp index 413c926a1e17f4a66220de1c9acdd41682ad8650..542c9630ae615b001b05d58c5c09d59f78647fc6 100644 --- a/data-access/engine/src/common/src/ast_frameset.hpp +++ b/data-access/engine/src/common/include/ast_frameset.hpp @@ -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: diff --git a/data-access/engine/src/common/src/ast_frameset.cpp b/data-access/engine/src/common/src/ast_frameset.cpp index 672156126eee9e347a1f5b7dc807affe99819039..d557629ecd8e511d624afd947aabc616e546f34e 100644 --- a/data-access/engine/src/common/src/ast_frameset.cpp +++ b/data-access/engine/src/common/src/ast_frameset.cpp @@ -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) @@ -915,8 +942,8 @@ overlap_ranges ast::frameset::overlap(coordinates coord) int ix_lon = m_sky_lon_axis - 1; //astGetI(m_hdr_fs,"LonAxis") - 1; int ix_lat = m_sky_lat_axis - 1; //astGetI(m_hdr_fs,"LatAxis") - 1; - //if ( !astOK ) - // throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetI( Lon/LatAxis )")); + //if ( !astOK ) + // throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetI( Lon/LatAxis )")); LOG_STREAM << "lon/lat axes indeces (zero-based): " << to_string(ix_lon) << " " << to_string(ix_lat) << endl; @@ -1142,8 +1169,8 @@ std::vector<point2d> ast::frameset::sky_vertices(void) const int ixlon = m_sky_lon_axis - 1; //astGetI(m_hdr_fs,"LonAxis") - 1; const int ixlat = m_sky_lat_axis - 1; //astGetI(m_hdr_fs,"LatAxis") - 1; - //if ( !astOK ) - // throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetI( Lon/LatAxis )")); + //if ( !astOK ) + // throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetI( Lon/LatAxis )")); LOG_STREAM << "VERT ix_lon ix_lat: " << ixlon << " " << ixlat << endl; @@ -1411,7 +1438,7 @@ std::ostream& ast::frameset::serialize(std::ostream& ostrm) const const char * csystem_lat = astGetC(m_hdr_fs, system_key_lat.c_str()); string system_lat(csystem_lat); LOG_STREAM << "System[Lat](" << system_lat << ") "; - + string unit_key_lon{"Unit("+to_string(m_sky_lon_axis)+")"}; const char * cunit_lon = astGetC(m_hdr_fs, unit_key_lon.c_str()); string unit_lon(cunit_lon); diff --git a/data-access/engine/src/common/src/fits_header.cpp b/data-access/engine/src/common/src/fits_header.cpp index 61e601ffb04250d6cabba4b19c503daf81f6f181..6149acf7af88d1dd0833c97a47fb43e399483e9f 100644 --- a/data-access/engine/src/common/src/fits_header.cpp +++ b/data-access/engine/src/common/src/fits_header.cpp @@ -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)) diff --git a/data-access/engine/src/vlkb/src/ast.cpp b/data-access/engine/src/vlkb/src/ast.cpp index f13650f587392571c8e48818c1fbec37ae1f648d..03cc610a092fc61936a655cc94e6857d4daecd79 100644 --- a/data-access/engine/src/vlkb/src/ast.cpp +++ b/data-access/engine/src/vlkb/src/ast.cpp @@ -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; +} diff --git a/data-access/engine/src/vlkb/src/ast.hpp b/data-access/engine/src/vlkb/src/ast.hpp index 0ba4b902613b2e894f5c3a345791de4bee913091..38683d62c92b672144f4a9ebf6ee8d1608125305 100644 --- a/data-access/engine/src/vlkb/src/ast.hpp +++ b/data-access/engine/src/vlkb/src/ast.hpp @@ -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 diff --git a/data-access/engine/src/vlkb/src/main.cpp b/data-access/engine/src/vlkb/src/main.cpp index 52b41da1b1216d0016a889de604376f31ea3c38b..0fca1465f7595f4f09a31270de37826531d37635 100644 --- a/data-access/engine/src/vlkb/src/main.cpp +++ b/data-access/engine/src/vlkb/src/main.cpp @@ -43,7 +43,7 @@ namespace vlkb << "Usage: " << progname << " <command> [cmd-options] [cmd-args]" << endl << "\n where commands are:\n " << "\n\t cutout imcopy cutpixels multicutout mergefiles\n" - << "\n\t listbounds skyvertices overlap\n" + << "\n\t listbounds header skyvertices overlap\n" << "\n\t nullvals dropdegen checkcard addcard modcard rawdelcard\n" << std::endl << "Version: " << VERSIONSTR << " " << BUILD << std::endl; @@ -55,7 +55,7 @@ namespace vlkb enum cmd_set { multicutout, mergefiles, cutout, imcopy, cutpixels, - listbounds, overlap, skyvertices, nullvals, dropdegen, checkcard, addcard, modcard, rawdelcard}; + listbounds, header, overlap, skyvertices, nullvals, dropdegen, checkcard, addcard, modcard, rawdelcard}; // from bash or interpreters usually receive params as strings @@ -70,6 +70,7 @@ namespace vlkb else if(cmdstr.compare("imcopy") == 0) cmd = imcopy; else if(cmdstr.compare("cutpixels") == 0) cmd = cutpixels; else if(cmdstr.compare("listbounds") == 0) cmd = listbounds; + else if(cmdstr.compare("header") == 0) cmd = header; else if(cmdstr.compare("overlap") == 0) cmd = overlap; else if(cmdstr.compare("skyvertices") == 0) cmd = skyvertices; else if(cmdstr.compare("nullvals") == 0) cmd = nullvals; @@ -319,6 +320,48 @@ int cmd_listbounds(int argc, char * argv[]) } +int cmd_header(int argc, char * argv[]) +{ + int rc; + + if (!((argc == 2) || (argc == 3) || (argc == 4))) + { + std::cerr + << "Usage: header <filename.fits> <SkySystem> <SpecSystem>\n" + << "\n" + << "Modify header for new coord system.\n" + << "Arguments:\n" + << " SkySystem GALACTIC or ICRS\n" + << " SpecSystem System=VELO,StdOfRest=LSRK,Unit=km/s or WAVE, Barycentric, m\n"; + rc = EXIT_FAILURE; + } + else + { + string pathname(argv[1]); + + string skySystem; + string specSystem; + + if(argc >= 3) + { + skySystem = argv[2]; + } + if(argc == 4) + { + specSystem = argv[3]; + } + + cout << string{argv[0]} << ": " << pathname << " '" << skySystem << "' " << specSystem << endl; + + rc = header_modif_coordsys(skySystem, specSystem, pathname); + std::cout << "header_modif_coordsys rc: " << rc << std::endl; + rc = EXIT_SUCCESS; + } + return rc; +} + + + int cmd_skyvertices(int argc, char * argv[]) { @@ -590,6 +633,7 @@ int main (int argc, char * argv[]) case vlkb::nullvals: rc = cmd_nullvals(cmd_argc, cmd_argv); break; case vlkb::listbounds: rc = cmd_listbounds(cmd_argc, cmd_argv); break; + case vlkb::header: rc = cmd_header(cmd_argc, cmd_argv); break; case vlkb::skyvertices: rc = cmd_skyvertices(cmd_argc, cmd_argv); break; case vlkb::overlap: rc = cmd_overlap(cmd_argc, cmd_argv); break;