28 #include <CCfits/CCfits>
40 <<
"has started is not allowed";
49 <<
"has started is not allowed";
58 <<
"has started is not allowed";
71 fits = std::make_shared<CCfits::FITS>(filename, CCfits::RWmode::Write);
75 auto& info = *table.getColumnInfo();
78 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
79 column_name_list.
push_back(info.getDescription(column_index).name);
80 column_unit_list.
push_back(info.getDescription(column_index).unit);
85 CCfits::HduType hdu_type = (
m_format ==
Format::BINARY) ? CCfits::HduType::BinaryTbl : CCfits::HduType::AsciiTbl;
87 auto extension_map = fits->extension();
88 auto extension_i = extension_map.find(
m_hdu_name);
89 bool new_hdu = (extension_i == extension_map.end() || extension_i->second->version() != 1);
91 CCfits::Table* table_hdu;
93 table_hdu =
dynamic_cast<CCfits::Table*
>(extension_i->second);
95 table_hdu = fits->addTable(
m_hdu_name, 0, column_name_list, column_format_list, column_unit_list, hdu_type);
98 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
99 auto& desc = info.getDescription(column_index).description;
100 table_hdu->addKey(
"TDESC" +
std::to_string(column_index + 1), desc,
"");
102 auto shape_str =
getTDIM(table, column_index);
103 if (!shape_str.empty()) {
104 table_hdu->addKey(CCfits::Column::TDIM() +
std::to_string(column_index + 1), shape_str,
"");
109 table_hdu->writeComment(c);
123 fits = std::make_shared<CCfits::FITS>(
m_filename, CCfits::RWmode::Write);
127 auto& info = *table.getColumnInfo();
128 for (
size_t column_index = 0; column_index < info.size(); ++column_index) {
FitsWriter & setFormat(Format format)
Set the FITS table format.
FITS binary table HDU format.
FitsWriter(const std::string &filename, bool override_flag=false)
Creates a FitsWriter that writes to a specific file.
void populateColumn(const Table &table, size_t column_index, CCfits::ExtHDU &table_hdu, long first_row)
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::string getTDIM(const Table &table, size_t column_index)
std::vector< std::string > getAsciiFormatList(const Table &table)
Returns a vector with strings representing the FITS ASCII table formats for the given table...
std::vector< std::string > getBinaryFormatList(const Table &table)
Returns a vector with strings representing the FITS binary table formats for the given table...