26#include "ElementsKernel/Exception.h"
27#include <CCfits/CCfits>
28#include <boost/lexical_cast.hpp>
29#include <boost/tokenizer.hpp>
38 for (
int i = 1; i <= table_hdu.numCols(); ++i) {
49 if (format[0] ==
'A') {
52 }
else if (format[0] ==
'I') {
53 return {
typeid(int64_t), 0};
54 }
else if (format[0] ==
'F') {
55 return {
typeid(double), 0};
56 }
else if (format[0] ==
'E') {
57 return {
typeid(double), 0};
58 }
else if (format[0] ==
'D') {
59 return {
typeid(double), 0};
67 {
'J',
typeid(NdArray<int32_t>)}, {
'B',
typeid(NdArray<int32_t>)}, {
'I',
typeid(NdArray<int32_t>)},
68 {
'K',
typeid(NdArray<int64_t>)}, {
'E',
typeid(NdArray<float>)}, {
'D',
typeid(NdArray<double>)},
70 ScalarTypeMap{{
'L',
typeid(bool)}, {
'J',
typeid(int32_t)}, {
'B',
typeid(int32_t)}, {
'I',
typeid(int32_t)},
71 {
'K',
typeid(int64_t)}, {
'E',
typeid(float)}, {
'D',
typeid(double)}, {
'A',
typeid(
std::string)}},
80 char ft = format.
front();
88 if (shape.
size() > 1) {
92 return {i->second, size};
100 return {i->second, size};
108 return {i->second, size};
118 auto subtdim = tdim.
substr(1, tdim.
size() - 2);
119 boost::char_separator<char> sep{
","};
120 boost::tokenizer<boost::char_separator<char>> tok{subtdim, sep};
122 [](
const std::string& s) { return boost::lexical_cast<size_t>(s); });
131 for (
int i = 1; i <= table_hdu.numCols(); i++) {
132 auto& column = table_hdu.column(i);
134 if (
typeid(table_hdu) ==
typeid(CCfits::BinTable)) {
146 for (
int i = 1; i <= table_hdu.numCols(); ++i) {
147 units.push_back(table_hdu.column(i).unit());
154 for (
int i = 1; i <= table_hdu.numCols(); ++i) {
157 if (key != table_hdu.keyWord().end()) {
158 key->second->value(desc);
160 descriptions.push_back(desc);
168 column.read(data, first, last);
177 column.readArrays(data, first, last);
181 [](
const std::valarray<T>& valar) { return std::vector<T>(std::begin(valar), std::end(valar)); });
188 column.readArrays(data, first, last);
193 return NdArray<T>(shape, std::move(std::vector<T>(std::begin(valar), std::end(valar))));
203 if (type ==
typeid(
bool)) {
205 }
else if (type ==
typeid(int32_t)) {
207 }
else if (type ==
typeid(int64_t)) {
209 }
else if (type ==
typeid(
float)) {
211 }
else if (type ==
typeid(
double)) {
T back_inserter(T... args)
NdArray(std::vector< size_t > shape_)
std::vector< Row::cell_type > convertVectorColumn(CCfits::Column &column, long first, long last)
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
std::vector< Row::cell_type > convertNdArrayColumn(CCfits::Column &column, long first, long last)
std::pair< std::type_index, std::size_t > binaryFormatToType(const std::string &format, const std::vector< size_t > &shape)
std::pair< std::type_index, std::size_t > asciiFormatToType(const std::string &format)
const std::vector< std::pair< char, std::type_index > > ScalarTypeMap
const std::vector< std::pair< char, std::type_index > > NdTypeMap
std::vector< std::string > autoDetectColumnUnits(const CCfits::Table &table_hdu)
Reads the column units based on the TUNITn keyword.
std::vector< std::string > autoDetectColumnNames(std::istream &in, const std::string &comment, size_t columns_number)
Reads the column names of the given stream.
std::vector< Row::cell_type > translateColumn(CCfits::Column &column, std::type_index type)
Returns a vector representing the given FITS table column data, converted to the requested type.
std::vector< size_t > parseTDIM(const std::string &tdim)
const std::vector< std::pair< char, std::type_index > > VectorTypeMap
std::vector< std::pair< std::type_index, std::size_t > > autoDetectColumnTypes(const CCfits::Table &table_hdu)
Reads the column types of the given table HDU.
std::vector< Row::cell_type > convertScalarColumn(CCfits::Column &column, long first, long last)