24 #include <CCfits/CCfits>
33 namespace po = boost::program_options;
34 namespace fs = boost::filesystem;
37 namespace Configuration {
49 return {{
"Input catalog options", {
51 "The file containing the input catalog"},
53 "The format of the input catalog (AUTO, FITS or ASCII)"},
55 "The name of the column representing the source ID"},
57 "The index of the column representing the source ID"}
87 const fs::path& base_dir) {
89 if (catalog_file.is_relative()) {
90 catalog_file = base_dir / catalog_file;
92 if (!fs::exists(catalog_file)) {
95 if (fs::is_directory(catalog_file)) {
101 enum class FormatType {
105 FormatType autoDetectFormatType(fs::path file) {
106 logger.
info() <<
"Auto-detecting format of file " << file;
107 FormatType result = FormatType::ASCII;
111 in.read(first_header_array.
data(), 80);
114 if (first_header_str.compare(0, 9,
"SIMPLE =") == 0) {
115 result = FormatType::FITS;
118 logger.
info() <<
"Detected " << (result == FormatType::FITS ?
"FITS" :
"ASCII") <<
" format";
122 FormatType getFormatTypeFromOptions(
const Configuration::UserValues& args,
123 const fs::path& file) {
126 format = autoDetectFormatType(file);
128 format = FormatType::FITS;
130 format = FormatType::ASCII;
137 return make_unique<Table::FitsReader>(filename.native(), 1);
139 return make_unique<Table::AsciiReader>(filename.native());
143 std::string getIdColumnFromOptions(
const Configuration::UserValues& args,
144 const Table::ColumnInfo& column_info) {
148 if (column_info.find(id_column_name) ==
nullptr) {
150 <<
"ID column with name " << id_column_name;
155 if (index > column_info.size()) {
157 <<
") is out of range (" << column_info.size() <<
")";
159 id_column_name = column_info.getDescription(index-1).name;
161 logger.
info() <<
"Using ID column \"" << id_column_name <<
'"';
162 return id_column_name;
208 class ConverterImpl {
214 :
m_converter(column_info, id_column_name,
std::move(attribute_handlers)) {
231 throw Elements::Exception() <<
"getTableToCatalogConverter() call to not finalized CatalogConfig";
251 return converter(table);