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);
167 fits_close_file(fptr, &status);
193 long first_pixel[2] = {
x + 1,
y + 1};
194 long last_pixel[2] = {
x + width,
y + height};
195 long increment[2] = {1, 1};
198 fits_read_subset(fptr,
getDataType(), first_pixel, last_pixel, increment,
199 nullptr, tile->getDataPtr(),
nullptr, &status);
217 long first_pixel[2] = {
x + 1,
y + 1};
218 long last_pixel[2] = {
x + width,
y + height};
225 fits_flush_buffer(fptr, 0, &status);
232 fits_movabs_hdu(fptr, hdu_number, &hdu_type, &status);
238 if (hdu_type != IMAGE_HDU) {
245 number_of_records = 0;
249 for (
auto record : headers) {
250 auto key = record.first;
253 if (record_string.
size() > 8) {
256 else if (record_string.
size() < 8) {
260 if (headers.at(key).m_value.type() ==
typeid(
std::string)) {
261 record_string +=
"= '" + VariantCast<std::string>(headers.at(key).m_value) +
"'";
264 record_string +=
"= " + VariantCast<std::string>(headers.at(key).m_value);
267 if (record_string.
size() > 80) {
272 if (record_string.
size() < 80) {
276 records += record_string;
282 records += record_string;
285 buffer->emplace_back(0);
303 << VariantCast<std::string>(value.
m_value);
304 auto str = serializer.
str();
307 fits_update_card(fptr, padded_key.
str().c_str(), str.c_str(), &status);
311 fits_get_errstatus(status, err_txt);