28 #include <CCfits/CCfits>
48 : m_filename(filename), m_override_file(override_flag) {}
55 <<
"has started is not allowed";
64 <<
"has started is not allowed";
73 <<
"has started is not allowed";
86 fits = std::make_shared<CCfits::FITS>(filename, CCfits::RWmode::Write);
90 auto& info = *table.getColumnInfo();
93 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
94 column_name_list.
push_back(info.getDescription(column_index).name);
95 column_unit_list.
push_back(info.getDescription(column_index).unit);
100 CCfits::HduType hdu_type = (
m_format ==
Format::BINARY) ? CCfits::HduType::BinaryTbl : CCfits::HduType::AsciiTbl;
102 auto extension_map = fits->extension();
103 auto extension_i = extension_map.find(
m_hdu_name);
104 bool new_hdu = (extension_i == extension_map.end() || extension_i->second->version() != 1);
106 CCfits::Table* table_hdu;
108 table_hdu =
dynamic_cast<CCfits::Table*
>(extension_i->second);
109 assert(table_hdu !=
nullptr);
111 table_hdu = fits->addTable(
m_hdu_name, 0, column_name_list, column_format_list, column_unit_list, hdu_type);
114 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
115 auto& desc = info.getDescription(column_index).description;
116 table_hdu->addKey(
"TDESC" +
std::to_string(column_index + 1), desc,
"");
118 auto shape_str =
getTDIM(table, column_index);
119 if (!shape_str.empty()) {
120 table_hdu->addKey(CCfits::Column::TDIM() +
std::to_string(column_index + 1), shape_str,
"");
126 boost::apply_visitor(visitor, h.m_value);
130 table_hdu->writeComment(c);
144 fits = std::make_shared<CCfits::FITS>(
m_filename, CCfits::RWmode::Write);
148 auto& info = *table.getColumnInfo();
149 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.
std::vector< Header > m_headers
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.