172 int original_hdu = 0;
173 fits_get_hdu_num(ptr, &original_hdu);
177 int number_of_hdus = 0;
178 if (fits_get_num_hdus(ptr, &number_of_hdus, &status) < 0) {
179 char error_message[32];
180 fits_get_errstatus(status, error_message);
182 <<
" status: " << status <<
" = " << error_message;
189 for (
int hdu_number = 1; hdu_number <= number_of_hdus; ++hdu_number) {
190 fits_movabs_hdu(ptr, hdu_number, &hdu_type, &status);
192 char error_message[32];
193 fits_get_errstatus(status, error_message);
195 <<
" status: " << status <<
" = " << error_message;
198 if (hdu_type == IMAGE_HDU) {
200 long naxes[3] = {1, 1, 1};
202 fits_get_img_param(ptr, 3, &bitpix, &naxis, naxes, &status);
203 if (status == 0 && (naxis == 2 || naxis == 3)) {
210 fits_movabs_hdu(ptr, original_hdu, &hdu_type, &status);
222 int keynum = 1, status = 0;
224 fits_read_record(fptr, keynum, record, &status);
225 while (status == 0 &&
strncmp(record,
"END", 3) != 0) {
226 static boost::regex
regex(
"([^=]{8})=([^\\/]*)(\\/(.*))?");
229 boost::smatch sub_matches;
230 if (boost::regex_match(record_str, sub_matches,
regex)) {
231 auto keyword = boost::to_upper_copy(sub_matches[1].str());
232 auto value = sub_matches[2].str();
233 auto comment = sub_matches[4].str();
234 boost::trim(keyword);
236 boost::trim(comment);
239 fits_read_record(fptr, ++keynum, record, &status);
264 auto base_name =
m_path.stem();
265 base_name.replace_extension(
".head");
266 auto head_filename =
m_path.parent_path() / base_name;
268 if (!boost::filesystem::exists(head_filename)) {
276 file.
open(head_filename.native());
281 logger.info() <<
"Loading .head file: " << head_filename <<
" for fits: " <<
m_path;
285 bool is_new_hdu =
true;
287 int current_hdu = *hdu_iter;
292 static boost::regex regex_blank_line(
"\\s*$");
293 line = boost::regex_replace(line, regex_blank_line,
std::string(
""));
294 if (line.
size() == 0) {
298 if (boost::to_upper_copy(line) ==
"END") {
299 current_hdu = *(++hdu_iter);
302 static boost::regex
regex(
"([^=]{1,8})=([^\\/]*)(\\/ (.*))?");
303 boost::smatch sub_matches;
304 if (boost::regex_match(line, sub_matches,
regex) && sub_matches.size() >= 3) {
305 auto keyword = boost::to_upper_copy(sub_matches[1].str());
306 auto value = sub_matches[2].str();
307 auto comment = sub_matches[4].str();
308 boost::trim(keyword);
310 boost::trim(comment);
320 if (headers_nb > 0) {
321 logger.info() <<
"Headers overriden: " << headers_nb <<
" in " << hdu_nb <<
" hdu(s)";
329 int original_hdu = 0;
330 fits_get_hdu_num(
m_fits_ptr.get(), &original_hdu);
334 fits_movabs_hdu(
m_fits_ptr.get(), hdu, &hdu_type, &status);
337 long naxes[3] = {1, 1, 1};
340 fits_get_img_param(
m_fits_ptr.get(), 3, &bitpix, &naxis, naxes, &status);
341 if (status != 0 || (naxis != 2 && naxis != 3)) {
342 char error_message[32];
343 fits_get_errstatus(status, error_message);
345 <<
"Can't find 2D image or data cube in FITS file: " <<
m_path <<
"[" << hdu <<
"]"
346 <<
" status: " << status <<
" = " << error_message;
357 fits_movabs_hdu(
m_fits_ptr.get(), original_hdu, &hdu_type, &status);