28 #include <CCfits/CCfits>
34 : m_filename(filename), m_override_file(override_flag) {}
41 <<
"has started is not allowed";
50 <<
"has started is not allowed";
59 <<
"has started is not allowed";
72 fits = std::make_shared<CCfits::FITS>(filename, CCfits::RWmode::Write);
76 auto& info = *table.getColumnInfo();
79 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
80 column_name_list.
push_back(info.getDescription(column_index).name);
81 column_unit_list.
push_back(info.getDescription(column_index).unit);
86 CCfits::HduType hdu_type = (
m_format ==
Format::BINARY) ? CCfits::HduType::BinaryTbl : CCfits::HduType::AsciiTbl;
88 auto extension_map = fits->extension();
89 auto extension_i = extension_map.find(
m_hdu_name);
90 bool new_hdu = (extension_i == extension_map.end() || extension_i->second->version() != 1);
92 CCfits::Table* table_hdu;
94 table_hdu =
dynamic_cast<CCfits::Table*
>(extension_i->second);
95 assert(table_hdu !=
nullptr);
97 table_hdu = fits->addTable(
m_hdu_name, 0, column_name_list, column_format_list, column_unit_list, hdu_type);
100 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
101 auto& desc = info.getDescription(column_index).description;
102 table_hdu->addKey(
"TDESC" +
std::to_string(column_index + 1), desc,
"");
104 auto shape_str =
getTDIM(table, column_index);
105 if (!shape_str.empty()) {
106 table_hdu->addKey(CCfits::Column::TDIM() +
std::to_string(column_index + 1), shape_str,
"");
111 table_hdu->writeComment(c);
125 fits = std::make_shared<CCfits::FITS>(
m_filename, CCfits::RWmode::Write);
129 auto& info = *table.getColumnInfo();
130 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
TableWriter implementation for writing tables in FITS format.
FitsWriter & setFormat(Format format)
Set the FITS table format.
void addComment(const std::string &message) override
Adds a comment to the stream.
Format
The format of the HDUs a FitsWriter creates.
@ BINARY
FITS binary table HDU format.
void append(const Table &table) override
FitsWriter(const std::string &filename, bool override_flag=false)
Creates a FitsWriter that writes to a specific file.
std::vector< std::string > m_comments
std::shared_ptr< CCfits::FITS > m_fits
void init(const Table &table) override
FitsWriter & setHduName(const std::string &name)
Set the HDU name where the table is written.
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, size_t column_index, CCfits::ExtHDU &table_hdu, long first_row)
std::string getTDIM(const Table &table, size_t column_index)
std::vector< std::string > getBinaryFormatList(const Table &table)
Returns a vector with strings representing the FITS binary table formats for the given table.