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);
116 fits_create_img(fptr, FLOAT_IMG, 0,
nullptr, &status);
124 fits_create_file(&fptr, (
"!"+filename).c_str(), &status);
126 fits_create_img(fptr, FLOAT_IMG, 0,
nullptr, &status);
132 assert(fptr !=
nullptr);
134 long naxes[2] = {
width, height};
135 fits_create_img(fptr,
getImageType(), 2, naxes, &status);
145 auto headers = coord_system->getFitsHeaders();
146 for (
auto& h : headers) {
151 auto str = serializer.
str();
153 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
156 fits_get_errstatus(status, err_txt);
157 throw Elements::Exception() <<
"Couldn't write the WCS headers (" << err_txt <<
"): " << str;
163 for (
int i = 0; i<
height; i++) {
164 long first_pixel[2] = {1, i+1};
165 fits_write_pix(fptr,
getDataType(), first_pixel, width, &buffer[0], &status);
167 fits_close_file(fptr, &status);
187 long first_pixel[2] = {x + 1, y + 1};
188 long last_pixel[2] = {x +
width, y + height};
189 long increment[2] = {1, 1};
192 fits_read_subset(fptr,
getDataType(), first_pixel, last_pixel, increment,
193 nullptr, tile->getDataPtr(),
nullptr, &status);
210 long first_pixel[2] = {x + 1, y + 1};
211 long last_pixel[2] = {x +
width, y + height};
224 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
229 if (hdu_type != IMAGE_HDU) {
237 number_of_records = 0;
241 for (
auto record : headers) {
242 auto key = record.first;
245 if (record_string.
size() > 8) {
247 }
else if (record_string.
size() < 8) {
251 if (headers.at(key).m_value.type() ==
typeid(
std::string)) {
252 record_string +=
"= '" + VariantCast<std::string>(headers.at(key).m_value) +
"'";
255 record_string +=
"= " + VariantCast<std::string>(headers.at(key).m_value);
258 if (record_string.
size() > 80) {
263 if (record_string.
size() < 80) {
267 records += record_string;
273 records += record_string;
276 buffer->emplace_back(0);
287 serializer << padded_key.
str() <<
"= " << std::left << std::setw(70) << VariantCast<std::string>(value.
m_value);
288 auto str = serializer.
str();
291 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
295 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