66 auto column_info = table.getColumnInfo();
68 for (
size_t column_index = 0; column_index < column_info->size(); ++column_index) {
69 auto type = column_info->getDescription(column_index).type;
70 if (type ==
typeid(
bool)) {
72 }
else if (type ==
typeid(int32_t) || type ==
typeid(int64_t)) {
73 size_t width =
maxWidth(table, column_index);
74 format_list.emplace_back(
"I" + boost::lexical_cast<std::string>(
std::max(
static_cast<size_t>(1), width)));
75 }
else if (type ==
typeid(
float) || type ==
typeid(
double)) {
77 format_list.emplace_back(
"E" + boost::lexical_cast<std::string>(
std::max(
static_cast<size_t>(1), width)));
79 size_t width =
maxWidth(table, column_index);
80 format_list.emplace_back(
"A" + boost::lexical_cast<std::string>(
std::max(
static_cast<size_t>(1), width)));
82 throw Elements::Exception() <<
"Unsupported column format for FITS ASCII table export: " << type.name();
145 {
typeid(bool), GenericScalarFormat<bool>},
146 {
typeid(int32_t), GenericScalarFormat<int32_t>},
147 {
typeid(int64_t), GenericScalarFormat<int64_t>},
148 {
typeid(float), GenericScalarFormat<float>},
149 {
typeid(double), GenericScalarFormat<double>},
158 [](
const Table& table,
size_t column) {
159 size_t width =
maxWidth(table, column);
161 return boost::lexical_cast<std::string>(
std::max(
static_cast<size_t>(1), width)) +
"A";
243 const auto& vec = boost::get<std::vector<T>>(table[0][column_index]);
244 if (vec.size() > 1) {
245 table_hdu.column(column_index + 1).writeArrays(createVectorColumnData<T>(table, column_index), first_row);
247 table_hdu.column(column_index + 1).write(createSingleValueVectorColumnData<T>(table, column_index), first_row);
253 const auto& nd = boost::get<NdArray<T>>(table[0][column_index]);
255 table_hdu.column(column_index + 1).writeArrays(createNdArrayColumnData<T>(table, column_index), first_row);
257 table_hdu.column(column_index + 1).write(createSingleNdArrayVectorColumnData<T>(table, column_index), first_row);
262 if (table.size() == 0) {
266 auto& first_row = table[0];
267 auto& cell = first_row[column_index];
268 auto type = table.getColumnInfo()->getDescription(column_index).type;
272 shape = boost::get<NdArray<int32_t>>(cell).shape();
274 shape = boost::get<NdArray<int64_t>>(cell).shape();
276 shape = boost::get<NdArray<float>>(cell).shape();
278 shape = boost::get<NdArray<double>>(cell).shape();
292 for (j = shape.
size() - 1; j > 0; --j) {
293 stream << shape[j] <<
",";
296 stream << shape[j] <<
')';
300void populateColumn(
const Table& table,
int column_index,
const CCfits::ExtHDU& table_hdu,
long first_row) {
301 if (table.size() == 0) {
304 auto type = table.getColumnInfo()->getDescription(column_index).type;
306 if (type ==
typeid(
bool)) {
307 table_hdu.column(column_index + 1).write(createColumnData<bool>(table, column_index), first_row);
308 }
else if (type ==
typeid(int32_t)) {
309 table_hdu.column(column_index + 1).write(createColumnData<int32_t>(table, column_index), first_row);
310 }
else if (type ==
typeid(int64_t)) {
311 table_hdu.column(column_index + 1).write(createColumnData<int64_t>(table, column_index), first_row);
312 }
else if (type ==
typeid(
float)) {
313 table_hdu.column(column_index + 1).write(createColumnData<float>(table, column_index), first_row);
314 }
else if (type ==
typeid(
double)) {
315 table_hdu.column(column_index + 1).write(createColumnData<double>(table, column_index), first_row);
317 table_hdu.column(column_index + 1).write(createColumnData<std::string>(table, column_index), first_row);
319 populateVectorColumn<int32_t>(table, column_index, table_hdu, first_row);
321 populateVectorColumn<int64_t>(table, column_index, table_hdu, first_row);
323 populateVectorColumn<float>(table, column_index, table_hdu, first_row);
325 populateVectorColumn<double>(table, column_index, table_hdu, first_row);
327 populateNdArrayColumn<int32_t>(table, column_index, table_hdu, first_row);
329 populateNdArrayColumn<int64_t>(table, column_index, table_hdu, first_row);
331 populateNdArrayColumn<float>(table, column_index, table_hdu, first_row);
333 populateNdArrayColumn<double>(table, column_index, table_hdu, first_row);
335 throw Elements::Exception() <<
"Cannot populate FITS column with data of type " << type.name();