26 #include <boost/algorithm/string/trim.hpp>
30 #include <wcslib/wcs.h>
31 #include <wcslib/wcshdr.h>
32 #include <wcslib/wcsfix.h>
33 #include <wcslib/wcsprintf.h>
34 #include <wcslib/getwcstab.h>
41 namespace SourceXtractor {
52 static
int wrapped_lincpy(
int alloc, const struct linprm *linsrc, struct linprm *lindst) {
56 return lincpy(alloc, linsrc, lindst);
61 int number_of_records = 0;
62 auto fits_headers = fits_image_source.
getFitsHeaders(number_of_records);
64 int nreject = 0, nwcs = 0;
66 wcspih(&(*fits_headers)[0], number_of_records, WCSHDR_all, 0, &nreject, &nwcs, &wcs);
69 m_wcs = decltype(
m_wcs)(wcs, [nwcs](wcsprm* wcs) {
72 wcsvfree(&nwcs_copy, &wcs);
84 wcsprm wcs_copy = *
m_wcs;
85 wcs_copy.lin.flag = -1;
87 linset(&wcs_copy.lin);
90 double pc_array[2] {image_coordinate.
m_x + 1, image_coordinate.
m_y + 1};
92 double ic_array[2] {0, 0};
93 double wc_array[2] {0, 0};
97 wcsp2s(&wcs_copy, 1, 1, pc_array, ic_array, &phi, &theta, wc_array, &status);
98 int ret_val = wcsp2s(&wcs_copy, 1, 1, pc_array, ic_array, &phi, &theta, wc_array, &status);
99 linfree(&wcs_copy.lin);
101 logger.
error() <<
"wcslib's wcsp2s returned with error code: " << ret_val;
110 wcsprm wcs_copy = *
m_wcs;
111 wcs_copy.lin.flag = -1;
113 linset(&wcs_copy.lin);
115 double pc_array[2] {0, 0};
116 double ic_array[2] {0, 0};
117 double wc_array[2] {world_coordinate.
m_alpha, world_coordinate.
m_delta};
121 int ret_val = wcss2p(&wcs_copy, 1, 1, wc_array, &phi, &theta, ic_array, pc_array, &status);
122 linfree(&wcs_copy.lin);
124 logger.
error() <<
"wcslib's wcss2p returned with error code: " << ret_val;
135 if (wcshdo(WCSHDO_none,
m_wcs.get(), &nkeyrec, &raw_header) != 0) {
136 throw Elements::Exception() <<
"Failed to get the FITS headers for the WCS coordinate system";
140 for (
int i = 0; i < nkeyrec; ++i) {
141 char *hptr = &raw_header[80 * i];
void error(const std::string &logMessage)
static Logging getLogger(const std::string &name="")