diff --git a/data-access/engine/src/vlkb/src/ast.cpp b/data-access/engine/src/vlkb/src/ast.cpp index 616930512ce6f246e0fc41561ca4ab5da09c9778..45fccb186854171be3137b62769752c9026d83b8 100644 --- a/data-access/engine/src/vlkb/src/ast.cpp +++ b/data-access/engine/src/vlkb/src/ast.cpp @@ -97,38 +97,55 @@ void write_previous(string header, string filename) out << header; } +void read_lines(string pathname, vector<string>& lines) +{ + LOG_trace(__func__); + + static const string empty_card{" "}; + + lines.clear(); + ifstream file(pathname); + string s; + while (getline(file, s)) + { + if(s.size()<80) s += empty_card.substr(0, 80-s.size()); + lines.push_back(s); + } +} -int header_backup(const string& pathname, bool backup) +int header_backup(const string& pathname, const string& extra_cards_pathname, bool backup) { - LOG_trace(__func__); + LOG_trace(__func__); - int maxHdu = 1;//FIXME INT_MAX; // read all HDU's + vector<string> extra_cards; + read_lines(extra_cards_pathname, extra_cards); - std::vector<fitsfiles::Hdu> allHdus = - fitsfiles::fname2hdrstr(pathname, maxHdu); + int maxHdu = 1;//FIXME INT_MAX; // read all HDU's + std::vector<fitsfiles::Hdu> allHdus = + fitsfiles::fname2hdrstr(pathname, extra_cards, maxHdu); - for(unsigned int i=0; i<allHdus.size(); i++) - { - cerr << "HDU#" << i << endl; + for(unsigned int i=0; i<allHdus.size(); i++) + { + cerr << "HDU#" << i << endl; - fitsfiles::Hdu hd = allHdus.at(i); + fitsfiles::Hdu hd = allHdus.at(i); - if(backup) - write_previous(hd.m_header, pathname +"hdr" + ((i>0) ? "#" + to_string(i+1) : "") ); - else - { - unsigned long i = 0; - unsigned long hdr_len = hd.m_header.length(); - while((i*80+80) <= hdr_len) - { - cout << hd.m_header.substr(80*i++, 80) << endl; - } - } - // FIXME remove all explicit cout cerr to main.cpp and here use ostream& + if(backup) + write_previous(hd.m_header, pathname +"hdr" + ((i>0) ? "#" + to_string(i+1) : "") ); + else + { + unsigned long i = 0; + unsigned long hdr_len = hd.m_header.length(); + while((i*80+80) <= hdr_len) + { + cout << hd.m_header.substr(80*i++, 80) << "<" << endl; + } + } + // FIXME remove all explicit cout cerr to main.cpp and here use ostream& - } + } - return 0; + return 0; } @@ -142,36 +159,36 @@ int header_backup(const string& pathname, bool backup) vector<string> split (const string &s, char delim) { - vector<string> result; - stringstream ss (s); - string item; + vector<string> result; + stringstream ss (s); + string item; - while (getline (ss, item, delim)) { - result.push_back (item); - } + while (getline (ss, item, delim)) { + result.push_back (item); + } - return result; + return result; } int vlkb_overlap(const string& pathname, const string& region, vector<uint_bounds>& bnds) { - LOG_trace(__func__); + LOG_trace(__func__); - int maxHdu = 1;// INT_MAX; FIXME fitsfiles::header throws error reading behind end-of-file due to INT_MAX + int maxHdu = 1;// INT_MAX; FIXME fitsfiles::header throws error reading behind end-of-file due to INT_MAX - std::vector<fitsfiles::Hdu> allHdus = - fitsfiles::fname2hdrstr(pathname, maxHdu); + std::vector<fitsfiles::Hdu> allHdus = + fitsfiles::fname2hdrstr(pathname, maxHdu); - const coordinates coord = parse_coordinates(region.c_str()); + const coordinates coord = parse_coordinates(region.c_str()); - int ov_code; - for(unsigned int i=0; i<allHdus.size(); i++) - { - fitsfiles::Hdu hd = allHdus.at(i); - bnds = calc_overlap(hd.m_header, coord, ov_code); - } - return ov_code; + int ov_code; + for(unsigned int i=0; i<allHdus.size(); i++) + { + fitsfiles::Hdu hd = allHdus.at(i); + bnds = calc_overlap(hd.m_header, coord, ov_code); + } + return ov_code; } diff --git a/data-access/engine/src/vlkb/src/ast.hpp b/data-access/engine/src/vlkb/src/ast.hpp index 1ac379a3fac49e03b8214661fd235bbf8f16b738..15571698efe130a51d5a3927a8317b3331edd3bc 100644 --- a/data-access/engine/src/vlkb/src/ast.hpp +++ b/data-access/engine/src/vlkb/src/ast.hpp @@ -8,7 +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_backup(const std::string& pathname, bool backup = false); +int header_backup(const std::string& pathname, const std::string& extra_cards_pathname, bool backup = false); 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 9197ce5367d5c36a59d7871c37e4488580b8f0b6..5ed5a640edd945eee4e5f5e836cb33d1afef5bcd 100644 --- a/data-access/engine/src/vlkb/src/main.cpp +++ b/data-access/engine/src/vlkb/src/main.cpp @@ -16,6 +16,7 @@ #include <algorithm> // replace needed #include <iostream> #include <sstream> +#include <fstream> #include <assert.h> #include <libgen.h> // basename() @@ -397,7 +398,7 @@ int cmd_header(int argc, char * argv[]) if (argc < 2) { std::cerr - << "Usage: header [--backup] <pathname.fits>...\n" + << "Usage: header [--backup] [--extra-cards-pathname=<pathname>] <pathname.fits>...\n" << "\n" << "Prints current header (one card per line) or writes the header into a file with the same pathname but 'fitshdr' extension.\n" << "Arguments:\n" @@ -407,6 +408,7 @@ int cmd_header(int argc, char * argv[]) else { bool backup = false; + string extra_cards_pathname; for(int i=1; i<argc; i++) { @@ -414,12 +416,17 @@ int cmd_header(int argc, char * argv[]) { backup = true; } + else if(0 == (string(argv[i]).substr(0,2+21)).compare("--extra-cards-pathname=")) + { + extra_cards_pathname = (string{argv[i]}).substr(2+21); + cout << "DBG " << extra_cards_pathname << endl; + } else { string pathname(argv[i]); cout << to_string(i) << " : " << pathname << endl; - rc = header_backup(pathname, backup); + rc = header_backup(pathname, extra_cards_pathname, backup); std::cout << "header_backup rc: " << rc << std::endl; } }