28 #include <wcslib/wcs.h>
29 #include <wcslib/wcshdr.h>
30 #include <wcslib/wcsfix.h>
31 #include <wcslib/wcsprintf.h>
32 #include <wcslib/getwcstab.h>
39 #include <boost/algorithm/string/trim.hpp>
55 static int wrapped_lincpy(
int alloc,
const struct linprm *linsrc,
struct linprm *lindst) {
59 return lincpy(alloc, linsrc, lindst);
64 fitsfile *fptr = NULL;
66 fits_open_file(&fptr, fits_file_path.
c_str(), READONLY, &status);
69 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
71 if (status != 0 || hdu_type != IMAGE_HDU) {
72 throw Elements::Exception() <<
"Can't read WCS information from " << fits_file_path <<
" HDU " << hdu_number;
77 fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status);
79 if (hdu_type == IMAGE_HDU) {
80 int nreject = 0, nwcs = 0;
82 wcspih(header, nkeyrec, WCSHDR_all, 0, &nreject, &nwcs, &wcs);
85 m_wcs = decltype(
m_wcs)(wcs, [nwcs](wcsprm* wcs) {
88 wcsvfree(&nwcs_copy, &wcs);
93 fits_close_file(fptr, &status);
96 wcslib_version(wcsver);
97 if (wcsver[0] < 5 || (wcsver[0] == 5 && wcsver[1] < 18)) {
98 logger.
info() <<
"wcslib " << wcsver[0] <<
"." << wcsver[1]
99 <<
" is not fully thread safe, using wrapped lincpy call!";
109 wcslib::wcsprm wcs_copy = *
m_wcs;
110 wcs_copy.lin.flag = -1;
112 linset(&wcs_copy.lin);
115 double pc_array[2] {image_coordinate.
m_x + 1, image_coordinate.
m_y + 1};
117 double ic_array[2] {0, 0};
118 double wc_array[2] {0, 0};
122 wcsp2s(&wcs_copy, 1, 1, pc_array, ic_array, &phi, &theta, wc_array, &status);
123 linfree(&wcs_copy.lin);
130 wcslib::wcsprm wcs_copy = *
m_wcs;
131 wcs_copy.lin.flag = -1;
133 linset(&wcs_copy.lin);
135 double pc_array[2] {0, 0};
136 double ic_array[2] {0, 0};
137 double wc_array[2] {world_coordinate.
m_alpha, world_coordinate.
m_delta};
141 wcss2p(&wcs_copy, 1, 1, wc_array, &phi, &theta, ic_array, pc_array, &status);
142 linfree(&wcs_copy.lin);
151 if (wcshdo(WCSHDO_none,
m_wcs.
get(), &nkeyrec, &raw_header) != 0) {
152 throw Elements::Exception() <<
"Failed to get the FITS headers for the WCS coordinate system";
156 for (
int i = 0; i < nkeyrec; ++i) {
157 char *hptr = &raw_header[80 * i];