32 #include <boost/filesystem/path.hpp>
33 #include <boost/filesystem/operations.hpp>
34 #include <boost/regex.hpp>
35 #include <boost/algorithm/string/case_conv.hpp>
36 #include <boost/algorithm/string/trim.hpp>
41 namespace SourceXtractor {
51 boost::regex float_regex(
"^[-+]?\\d*\\.?\\d+([eE][-+]?\\d+)?$");
52 boost::regex int_regex(
"^[-+]?\\d+$");
58 else if (boost::regex_match(value, int_regex)) {
61 else if (boost::regex_match(value, float_regex)) {
64 else if (value.
size() == 1) {
77 for (
auto i = value.
begin(); i != value.
end(); ++i) {
78 if (*i ==
'\'' && !escape) {
92 m_file_pointer(nullptr),
93 m_is_file_opened(false),
94 m_is_writeable(writeable),
95 m_was_opened_before(false),
112 int number_of_hdus = 0;
113 if (fits_get_num_hdus(
m_file_pointer, &number_of_hdus, &status) < 0) {
120 int original_hdu = 0;
125 for (
int hdu_number=1; hdu_number <= number_of_hdus; hdu_number++) {
131 if (hdu_type == IMAGE_HDU) {
133 long naxes[2] = {1,1};
135 fits_get_img_param(
m_file_pointer, 2, &bitpix, &naxis, naxes, &status);
136 if (status == 0 && naxis == 2) {
143 fits_movabs_hdu(
m_file_pointer, original_hdu, &hdu_type, &status);
198 int original_hdu = 0;
202 for (
unsigned int i = 0; i <
m_headers.size(); i++) {
209 fits_movabs_hdu(
m_file_pointer, original_hdu, &hdu_type, &status);
215 int keynum = 1, status = 0;
217 fits_read_record(fptr, keynum, record, &status);
218 while (status == 0 &&
strncmp(record,
"END", 3) != 0) {
219 static boost::regex
regex(
"([^=]{8})=([^\\/]*)(\\/(.*))?");
222 boost::smatch sub_matches;
223 if (boost::regex_match(record_str, sub_matches, regex)) {
224 auto keyword = boost::to_upper_copy(sub_matches[1].str());
225 auto value = sub_matches[2].str();
226 auto comment = sub_matches[4].str();
227 boost::trim(keyword);
229 boost::trim(comment);
232 fits_read_record(fptr, ++keynum, record, &status);
241 base_name.replace_extension(
".head");
242 auto head_filename =
filename.parent_path() / base_name;
244 if (!boost::filesystem::exists(head_filename)) {
252 file.
open(head_filename.native());
258 int current_hdu = *hdu_iter;
263 static boost::regex regex_blank_line(
"\\s*$");
264 line = boost::regex_replace(line, regex_blank_line,
std::string(
""));
265 if (line.
size() == 0) {
269 if (boost::to_upper_copy(line) ==
"END") {
270 current_hdu = *(++hdu_iter);
273 static boost::regex
regex(
"([^=]{1,8})=([^\\/]*)(\\/ (.*))?");
274 boost::smatch sub_matches;
275 if (boost::regex_match(line, sub_matches, regex) && sub_matches.size() >= 3) {
276 auto keyword = boost::to_upper_copy(sub_matches[1].str());
277 auto value = sub_matches[2].str();
278 auto comment = sub_matches[4].str();
279 boost::trim(keyword);
281 boost::trim(comment);