31 #include <boost/filesystem/path.hpp>
32 #include <boost/filesystem/operations.hpp>
33 #include <boost/regex.hpp>
34 #include <boost/algorithm/string/case_conv.hpp>
35 #include <boost/algorithm/string/trim.hpp>
40 namespace SourceXtractor {
50 boost::regex float_regex(
"^[-+]?\\d*\\.?\\d+([eE][-+]?\\d+)?$");
51 boost::regex int_regex(
"^[-+]?\\d+$");
57 else if (boost::regex_match(value, int_regex)) {
60 else if (boost::regex_match(value, float_regex)) {
63 else if (value.
size() == 1) {
76 for (
auto i = value.
begin(); i != value.
end(); ++i) {
77 if (*i ==
'\'' && !escape) {
91 m_file_pointer(nullptr),
92 m_is_file_opened(false),
93 m_is_writeable(writeable),
94 m_was_opened_before(false),
111 int number_of_hdus = 0;
112 if (fits_get_num_hdus(
m_file_pointer, &number_of_hdus, &status) < 0) {
119 int original_hdu = 0;
124 for (
int hdu_number=1; hdu_number <= number_of_hdus; hdu_number++) {
130 if (hdu_type == IMAGE_HDU) {
132 long naxes[2] = {1,1};
134 fits_get_img_param(
m_file_pointer, 2, &bitpix, &naxis, naxes, &status);
135 if (status == 0 && naxis == 2) {
142 fits_movabs_hdu(
m_file_pointer, original_hdu, &hdu_type, &status);
195 int original_hdu = 0;
199 for (
unsigned int i = 0; i <
m_headers.size(); i++) {
206 fits_movabs_hdu(
m_file_pointer, original_hdu, &hdu_type, &status);
212 int keynum = 1, status = 0;
214 fits_read_record(fptr, keynum, record, &status);
215 while (status == 0 &&
strncmp(record,
"END", 3) != 0) {
216 static boost::regex
regex(
"([^=]{8})=([^\\/]*)(\\/(.*))?");
219 boost::smatch sub_matches;
220 if (boost::regex_match(record_str, sub_matches, regex)) {
221 auto keyword = boost::to_upper_copy(sub_matches[1].str());
222 auto value = sub_matches[2].str();
223 auto comment = sub_matches[4].str();
224 boost::trim(keyword);
226 boost::trim(comment);
229 fits_read_record(fptr, ++keynum, record, &status);
238 base_name.replace_extension(
".head");
239 auto head_filename =
filename.parent_path() / base_name;
243 if (boost::filesystem::exists(head_filename)) {
247 file.
open(head_filename.native());
253 int current_hdu = *hdu_iter;
258 static boost::regex regex_blank_line(
"\\s*$");
259 line = boost::regex_replace(line, regex_blank_line,
std::string(
""));
260 if (line.
size() == 0) {
264 if (boost::to_upper_copy(line) ==
"END") {
265 current_hdu = *(++hdu_iter);
268 static boost::regex
regex(
"([^=]{1,8})=([^\\/]*)(\\/ (.*))?");
269 boost::smatch sub_matches;
270 if (boost::regex_match(line, sub_matches, regex) && sub_matches.size() >= 3) {
271 auto keyword = boost::to_upper_copy(sub_matches[1].str());
272 auto value = sub_matches[2].str();
273 auto comment = sub_matches[4].str();
274 boost::trim(keyword);
276 boost::trim(comment);