27 #include <CCfits/CCfits>
28 #include <boost/lexical_cast.hpp>
29 #include <boost/tokenizer.hpp>
34 using NdArray::NdArray;
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};
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);
165 template <
typename T>
168 column.read(data, first, last);
174 template <
typename T>
177 column.readArrays(data, first, last);
185 template <
typename T>
188 column.readArrays(data, first, last);
203 if (type ==
typeid(
bool)) {
204 return convertScalarColumn<bool>(column, first, last);
205 }
else if (type ==
typeid(int32_t)) {
206 return convertScalarColumn<int32_t>(column, first, last);
207 }
else if (type ==
typeid(int64_t)) {
208 return convertScalarColumn<int64_t>(column, first, last);
209 }
else if (type ==
typeid(
float)) {
210 return convertScalarColumn<float>(column, first, last);
211 }
else if (type ==
typeid(
double)) {
212 return convertScalarColumn<double>(column, first, last);
214 return convertScalarColumn<std::string>(column, first, last);
216 return convertVectorColumn<int32_t>(column, first, last);
218 return convertVectorColumn<int64_t>(column, first, last);
220 return convertVectorColumn<float>(column, first, last);
222 return convertVectorColumn<double>(column, first, last);
223 }
else if (type ==
typeid(NdArray<int32_t>)) {
224 return convertNdArrayColumn<int32_t>(column, first, last);
225 }
else if (type ==
typeid(NdArray<int64_t>)) {
226 return convertNdArrayColumn<int64_t>(column, first, last);
227 }
else if (type ==
typeid(NdArray<float>)) {
228 return convertNdArrayColumn<float>(column, first, last);
229 }
else if (type ==
typeid(NdArray<double>)) {
230 return convertNdArrayColumn<double>(column, first, last);
const std::vector< std::pair< char, std::type_index > > ScalarTypeMap
std::vector< Row::cell_type > convertVectorColumn(CCfits::Column &column, long first, long last)
std::pair< std::type_index, std::size_t > asciiFormatToType(const std::string &format)
std::pair< std::type_index, std::size_t > binaryFormatToType(const std::string &format, const std::vector< size_t > &shape)
std::map< std::string, ColumnDescription > autoDetectColumnDescriptions(std::istream &in, const std::string &comment)
Reads the column descriptions of the given stream.
std::vector< size_t > parseTDIM(const std::string &tdim)
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...
T back_inserter(T...args)
const std::vector< std::pair< char, std::type_index > > NdTypeMap
std::vector< Row::cell_type > convertScalarColumn(CCfits::Column &column, long first, long last)
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 > convertNdArrayColumn(CCfits::Column &column, long first, long last)
const std::vector< std::pair< char, std::type_index > > VectorTypeMap
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.