Skip to content
Snippets Groups Projects
Commit 4e525bab authored by Robert Butora's avatar Robert Butora
Browse files

vlkb header: adds extra-cards into header before printing the header

parent 36fb776b
Branches
Tags
No related merge requests found
......@@ -97,15 +97,32 @@ 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__);
int maxHdu = 1;//FIXME INT_MAX; // read all HDU's
vector<string> extra_cards;
read_lines(extra_cards_pathname, extra_cards);
int maxHdu = 1;//FIXME INT_MAX; // read all HDU's
std::vector<fitsfiles::Hdu> allHdus =
fitsfiles::fname2hdrstr(pathname, maxHdu);
fitsfiles::fname2hdrstr(pathname, extra_cards, maxHdu);
for(unsigned int i=0; i<allHdus.size(); i++)
{
......@@ -121,7 +138,7 @@ int header_backup(const string& pathname, bool backup)
unsigned long hdr_len = hd.m_header.length();
while((i*80+80) <= hdr_len)
{
cout << hd.m_header.substr(80*i++, 80) << endl;
cout << hd.m_header.substr(80*i++, 80) << "<" << endl;
}
}
// FIXME remove all explicit cout cerr to main.cpp and here use ostream&
......
......@@ -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
......@@ -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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment