25 #include <CCfits/CCfits>
35 : m_filename(filename), m_override_file(override_flag) {
44 <<
"has started is not allowed";
53 <<
"has started is not allowed";
62 <<
"has started is not allowed";
75 fits = std::make_shared<CCfits::FITS>(filename, CCfits::RWmode::Write);
79 auto& info = *table.getColumnInfo();
82 for (
size_t column_index=0; column_index<info.size(); ++column_index) {
83 column_name_list.
push_back(info.getDescription(column_index).name);
84 column_unit_list.
push_back(info.getDescription(column_index).unit);
91 ? CCfits::HduType::BinaryTbl
92 : CCfits::HduType::AsciiTbl;
94 auto number_of_hdus_before = fits->extension().size();
95 CCfits::Table* table_hdu = fits->addTable(
m_hdu_name, 0, column_name_list,
96 column_format_list, column_unit_list, hdu_type);
97 bool new_hdu = number_of_hdus_before != fits->extension().size();
103 for (
size_t column_index=0; column_index<info.size(); ++column_index) {
104 auto& desc = info.getDescription(column_index).description;
105 table_hdu->addKey(
"TDESC" +
std::to_string(column_index+1), desc,
"");
107 auto shape_str =
getTDIM(table, column_index);
108 if (!shape_str.empty()) {
109 table_hdu->addKey(CCfits::Column::TDIM() +
std::to_string(column_index+1), shape_str,
"");
114 table_hdu->writeComment(c);
126 fits = std::make_shared<CCfits::FITS>(
m_filename, CCfits::RWmode::Write);
130 auto& info = *table.getColumnInfo();
131 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...