29 #include <CCfits/CCfits>
30 #include <boost/lexical_cast.hpp>
36 : m_filename(filename), m_override_file(override_flag) {}
43 <<
"has started is not allowed";
52 <<
"has started is not allowed";
61 <<
"has started is not allowed";
74 fits = std::make_shared<CCfits::FITS>(filename, CCfits::RWmode::Write);
78 auto& info = *table.getColumnInfo();
81 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
82 column_name_list.
push_back(info.getDescription(column_index).name);
83 column_unit_list.
push_back(info.getDescription(column_index).unit);
88 CCfits::HduType hdu_type = (
m_format ==
Format::BINARY) ? CCfits::HduType::BinaryTbl : CCfits::HduType::AsciiTbl;
90 auto extension_map = fits->extension();
91 auto extension_i = extension_map.find(
m_hdu_name);
92 bool new_hdu = (extension_i == extension_map.end() || extension_i->second->version() != 1);
94 CCfits::Table* table_hdu;
96 table_hdu =
dynamic_cast<CCfits::Table*
>(extension_i->second);
97 assert(table_hdu !=
nullptr);
99 table_hdu = fits->addTable(
m_hdu_name, 0, column_name_list, column_format_list, column_unit_list, hdu_type);
102 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
103 auto& desc = info.getDescription(column_index).description;
104 table_hdu->addKey(
"TDESC" +
std::to_string(column_index + 1), desc,
"");
106 auto shape_str =
getTDIM(table, column_index);
107 if (!shape_str.empty()) {
108 table_hdu->addKey(CCfits::Column::TDIM() +
std::to_string(column_index + 1), shape_str,
"");
113 table_hdu->addKey(h.m_key, boost::lexical_cast<std::string>(
cell_stream_adaptor(h.m_value)), h.m_comment);
117 table_hdu->writeComment(c);
131 fits = std::make_shared<CCfits::FITS>(
m_filename, CCfits::RWmode::Write);
135 auto& info = *table.getColumnInfo();
136 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
FitsWriter & setFormat(Format format)
Set the FITS table format.
std::vector< Header > m_headers
FITS binary table HDU format.
std::string getTDIM(const Table &table, int column_index)
FitsWriter(const std::string &filename, bool override_flag=false)
Creates a FitsWriter that writes to a specific file.
std::shared_ptr< CCfits::FITS > m_fits
TableWriter implementation for writing tables in FITS format.
void init(const Table &table) override
Format
The format of the HDUs a FitsWriter creates.
std::vector< std::string > m_comments
FitsWriter & setHduName(const std::string &name)
Set the HDU name where the table is written.
void addComment(const std::string &message) override
Adds a comment to the stream.
void append(const Table &table) override
std::vector< std::string > getAsciiFormatList(const Table &table)
Returns a vector with strings representing the FITS ASCII table formats for the given table...
void populateColumn(const Table &table, int column_index, const CCfits::ExtHDU &table_hdu, long first_row)
std::vector< std::string > getBinaryFormatList(const Table &table)
Returns a vector with strings representing the FITS binary table formats for the given table...