29 #include <boost/filesystem/path.hpp>
30 #include <boost/filesystem/operations.hpp>
31 #include <boost/regex.hpp>
32 #include <boost/algorithm/string/case_conv.hpp>
33 #include <boost/algorithm/string/trim.hpp>
42 namespace SourceXtractor {
48 : m_filename(filename), m_manager(manager), m_hdu_number(hdu_number) {
51 long naxes[2] = {1,1};
65 fits_get_img_param(fptr, 2, &bitpix, &naxis, naxes, &status);
66 if (status != 0 || naxis != 2) {
102 : m_filename(filename), m_manager(manager), m_width(width), m_height(height), m_image_type(image_type) {
108 fitsfile* fptr =
nullptr;
111 fits_open_image(&fptr, filename.
c_str(), READWRITE, &status);
114 fits_create_file(&fptr, filename.
c_str(), &status);
121 fits_create_file(&fptr, (
"!"+filename).c_str(), &status);
126 assert(fptr !=
nullptr);
128 long naxes[2] = {
width, height};
129 fits_create_img(fptr,
getImageType(), 2, naxes, &status);
139 auto headers = coord_system->getFitsHeaders();
140 for (
auto& h : headers) {
145 auto str = serializer.
str();
147 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
150 fits_get_errstatus(status, err_txt);
151 throw Elements::Exception() <<
"Couldn't write the WCS headers (" << err_txt <<
"): " << str;
157 for (
int i = 0; i<
height; i++) {
158 long first_pixel[2] = {1, i+1};
159 fits_write_pix(fptr,
getDataType(), first_pixel, width, &buffer[0], &status);
161 fits_close_file(fptr, &status);
181 long first_pixel[2] = {x + 1, y + 1};
182 long last_pixel[2] = {x +
width, y + height};
183 long increment[2] = {1, 1};
186 fits_read_subset(fptr,
getDataType(), first_pixel, last_pixel, increment,
187 nullptr, tile->getDataPtr(),
nullptr, &status);
204 long first_pixel[2] = {x + 1, y + 1};
205 long last_pixel[2] = {x +
width, y + height};
218 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
223 if (hdu_type != IMAGE_HDU) {
231 number_of_records = 0;
235 for (
auto record : headers) {
236 auto key = record.first;
239 if (record_string.
size() > 8) {
241 }
else if (record_string.
size() < 8) {
245 if (headers.at(key).m_value.type() ==
typeid(
std::string)) {
246 record_string +=
"= '" + VariantCast<std::string>(headers.at(key).m_value) +
"'";
249 record_string +=
"= " + VariantCast<std::string>(headers.at(key).m_value);
252 if (record_string.
size() > 80) {
257 if (record_string.
size() < 80) {
261 records += record_string;
267 records += record_string;
270 buffer->emplace_back(0);
281 serializer << padded_key.
str() <<
"= " << std::left << std::setw(70) << VariantCast<std::string>(value.
m_value);
282 auto str = serializer.
str();
285 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
289 fits_get_errstatus(status, err_txt);
T shared_from_this(T...args)
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y