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>
38 #include <boost/algorithm/string/trim.hpp>
40 namespace SourceXtractor {
42 using namespace wcslib;
45 fitsfile *fptr = NULL;
47 fits_open_file(&fptr, fits_file_path.
c_str(), READONLY, &status);
50 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
52 if (status != 0 || hdu_type != IMAGE_HDU) {
53 throw Elements::Exception() <<
"Can't read WCS information from " << fits_file_path <<
" HDU " << hdu_number;
58 fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status);
60 if (hdu_type == IMAGE_HDU) {
61 int nreject = 0, nwcs = 0;
73 fits_close_file(fptr, &status);
82 double pc_array[2] {image_coordinate.
m_x + 1, image_coordinate.
m_y + 1};
84 double ic_array[2] {0, 0};
85 double wc_array[2] {0, 0};
89 wcsp2s(
m_wcs.get(), 1, 1, pc_array, ic_array, &phi, &theta, wc_array, &status);
95 double pc_array[2] {0, 0};
96 double ic_array[2] {0, 0};
97 double wc_array[2] {world_coordinate.
m_alpha, world_coordinate.
m_delta};
101 wcss2p(
m_wcs.get(), 1, 1, wc_array, &phi, &theta, ic_array, pc_array, &status);
111 throw Elements::Exception() <<
"Failed to get the FITS headers for the WCS coordinate system";
115 for (
int i = 0; i < nkeyrec; ++i) {
116 char *hptr = &raw_header[80 * i];
int wcspih(char *header, int nkeyrec, int relax, int ctrl, int *nreject, int *nwcs, struct wcsprm **wcs)
int wcsvfree(int *nwcs, struct wcsprm **wcs)
int wcshdo(int relax, struct wcsprm *wcs, int *nkeyrec, char **header)
int wcsp2s(struct wcsprm *wcs, int ncoord, int nelem, const double pixcrd[], double imgcrd[], double phi[], double theta[], double world[], int stat[])
int wcss2p(struct wcsprm *wcs, int ncoord, int nelem, const double world[], double phi[], double theta[], double imgcrd[], double pixcrd[], int stat[])
int wcsset(struct wcsprm *wcs)