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)}},
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};
121 for (
auto&
s : tok) {
122 result.push_back(boost::lexical_cast<size_t>(
s));
132 for (
int i = 1; i <= table_hdu.numCols(); i++) {
133 auto& column = table_hdu.column(i);
135 if (
typeid(table_hdu) ==
typeid(CCfits::BinTable)) {
147 for (
int i = 1; i <= table_hdu.numCols(); ++i) {
148 units.
push_back(table_hdu.column(i).unit());
155 for (
int i = 1; i <= table_hdu.numCols(); ++i) {
158 if (key != table_hdu.keyWord().end()) {
159 key->second->value(desc);
161 descriptions.push_back(desc);
166 template <
typename T>
169 column.read(data, first, last);
171 for (
auto value : data) {
177 template <
typename T>
180 column.readArrays(data, first, last);
182 for (
auto& valar : data) {
188 template <
typename T>
191 column.readArrays(data, first, last);
195 for (
auto& valar : data) {
206 if (type ==
typeid(
bool)) {
207 return convertScalarColumn<bool>(column, first, last);
208 }
else if (type ==
typeid(int32_t)) {
209 return convertScalarColumn<int32_t>(column, first, last);
210 }
else if (type ==
typeid(int64_t)) {
211 return convertScalarColumn<int64_t>(column, first, last);
212 }
else if (type ==
typeid(
float)) {
213 return convertScalarColumn<float>(column, first, last);
214 }
else if (type ==
typeid(
double)) {
215 return convertScalarColumn<double>(column, first, last);
217 return convertScalarColumn<std::string>(column, first, last);
219 return convertVectorColumn<int32_t>(column, first, last);
221 return convertVectorColumn<int64_t>(column, first, last);
223 return convertVectorColumn<float>(column, first, last);
225 return convertVectorColumn<double>(column, first, last);
227 return convertNdArrayColumn<int32_t>(column, first, last);
229 return convertNdArrayColumn<int64_t>(column, first, last);
231 return convertNdArrayColumn<float>(column, first, last);
233 return convertNdArrayColumn<double>(column, first, last);
NdArray(std::vector< size_t > shape_)
std::vector< size_t > parseTDIM(const std::string &tdim)
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
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 > convertScalarColumn(CCfits::Column &column, long first, long last)
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.
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::pair< std::type_index, std::size_t > binaryFormatToType(const std::string &format, const std::vector< size_t > &shape)
std::vector< Row::cell_type > convertNdArrayColumn(CCfits::Column &column, long first, long last)
std::vector< Row::cell_type > convertVectorColumn(CCfits::Column &column, long first, long last)