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>
50 : m_filename(
filename), m_handler(manager->getFileHandler(
filename)), m_hdu_number(hdu_number) {
53 long naxes[2] = {1, 1};
67 fits_get_img_param(fptr, 2, &bitpix, &naxis, naxes, &status);
68 if (status != 0 || naxis != 2) {
108 , m_handler(manager->getFileHandler(
filename))
111 , m_image_type(image_type) {
114 fitsfile* fptr =
nullptr;
125 assert(fptr !=
nullptr);
127 if (empty_primary && acc->m_fd.getImageHdus().size() == 0) {
128 fits_create_img(fptr, FLOAT_IMG, 0,
nullptr, &status);
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 <<
" status: " << status;
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);
192 long first_pixel[2] = {
x + 1,
y + 1};
193 long last_pixel[2] = {
x + width,
y + height};
194 long increment[2] = {1, 1};
197 fits_read_subset(fptr,
getDataType(), first_pixel, last_pixel, increment,
198 nullptr, tile->getDataPtr(),
nullptr, &status);
216 long first_pixel[2] = {
x + 1,
y + 1};
217 long last_pixel[2] = {
x + width,
y + height};
224 fits_flush_buffer(fptr, 0, &status);
231 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
237 if (hdu_type != IMAGE_HDU) {
244 number_of_records = 0;
248 for (
auto record : headers) {
249 auto key = record.first;
252 if (record_string.
size() > 8) {
255 else if (record_string.
size() < 8) {
259 if (headers.at(key).m_value.type() ==
typeid(
std::string)) {
260 record_string +=
"= '" + VariantCast<std::string>(headers.at(key).m_value) +
"'";
263 record_string +=
"= " + VariantCast<std::string>(headers.at(key).m_value);
266 if (record_string.
size() > 80) {
271 if (record_string.
size() < 80) {
275 records += record_string;
281 records += record_string;
284 buffer->emplace_back(0);
302 << VariantCast<std::string>(value.
m_value);
303 auto str = serializer.
str();
306 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
310 fits_get_errstatus(status, err_txt);
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
T shared_from_this(T... args)