6 #ifndef IFW_DIT_FITS_HPP_
7 #define IFW_DIT_FITS_HPP_
12 #include <CCfits/CCfits.h>
13 #include <CCfits/FITS.h>
14 #include <CCfits/PHDU.h>
48 const int cfitsio_status);
79 void CreateFile(std::shared_ptr<CCfits::FITS>& fits_handle,
80 const std::string& filename,
83 const std::vector<int32_t>& naxes,
84 std::string& target_filename,
85 const bool remove_if_exists =
false,
86 const uint16_t nb_of_hdr_blocks = 1);
95 void OpenFitsFile(std::shared_ptr<CCfits::FITS>& fits_handle,
96 const std::string& filename,
97 std::string& target_filename,
98 CCfits::RWmode mode = CCfits::Read);
107 bool KeyInHdu(std::shared_ptr<CCfits::FITS>& fits_handle,
108 const int16_t hdu_nb,
109 const std::string& key);
116 void MoveToHdu(std::shared_ptr<CCfits::FITS>& fits_handle,
117 const int16_t hdu_nb);
139 const std::string& key,
140 const int16_t hdu_nb,
142 std::string& target_key,
156 template <
class TYPE>
157 void AddKey(std::shared_ptr<CCfits::FITS>& fits_handle,
159 const std::string& key,
161 const int16_t hdu_nb =
CUR_HDU) {
162 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
164 LOG4CPLUS_DEBUG(
Logger(),
"Keyword to add: \"" << key <<
"\". Type: "
165 <<
typeid(value).name());
167 if ((
typeid(TYPE) ==
typeid(
double)) || (
typeid(TYPE) ==
typeid(
float))) {
168 throw std::runtime_error(
"Use dit::fits::AddDoubleKey() for floating point type keyword "
169 "cards (" + key +
")");
173 std::string target_key;
175 PrepForAddingKey(fits_handle, dictionary, key, hdu_nb, did_record, target_key, key_in_hdu);
178 fits_get_hdu_num(fits_handle.get()->fitsPointer(), &cur_hdu);
181 fits_handle.get()->pHDU().addKey(target_key, value, did_record.
GetComment());
183 fits_handle.get()->extension(cur_hdu-1).addKey(target_key, value, did_record.
GetComment());
185 }
catch (CCfits::FitsException& ex) {
186 throw std::runtime_error(fmt::format(
"Error adding key: \"{}\". Diagnostics: {}.",
191 int ReadIntKey(std::shared_ptr<CCfits::FITS>& fits_handle,
192 const std::string& key);
202 void AddDoubleKey(std::shared_ptr<CCfits::FITS>& fits_handle,
204 const std::string& key,
206 const uint16_t hdu_nb);
217 std::string& target_filename,
218 std::string& hdr_buf,
228 std::string& hdr_buf,
240 void StoreImage(std::shared_ptr<CCfits::FITS>& fits_handle,
243 const void* image_buffer,
258 void addHDU(std::shared_ptr<CCfits::FITS>& fits_handle, std::string extensionName,
259 int8_t bitpix,
const std::vector<int32_t>& naxes);
Data Interface Dictionary class.
Definition: did.hpp:32
Data Interface Dictionary keyword record class.
Definition: record.hpp:46
const std::string & GetComment() const
Get the comment defined.
Definition: record.cpp:107
log4cplus::Logger & Logger()
Definition: defines.cpp:13
const int BITS_PER_PIXEL
Definition: fits.hpp:33
int32_t CfitsioType
Definition: fits.hpp:26
int ReadIntKey(std::shared_ptr< CCfits::FITS > &fits_handle, const std::string &key)
Definition: fits.cpp:178
const int16_t ALL_HEADERS
Definition: fits.hpp:32
const int CUR_HDU
Definition: fits.hpp:28
void AddKey(std::shared_ptr< CCfits::FITS > &fits_handle, const dit::did::Did &dictionary, const std::string &key, const TYPE &value, const int16_t hdu_nb=CUR_HDU)
Template function to add a keyword card in an existing FITS file.
Definition: fits.hpp:157
log4cplus::Logger & Logger()
Definition: fits.cpp:18
int BitpixToCfitsioDataType(const int8_t bitpix)
Definition: fits.cpp:446
const std::string FITS_KEY_ESO_HIERARCH
Definition: fits.hpp:31
const int APPEND
Definition: fits.hpp:29
void CreateFile(std::shared_ptr< CCfits::FITS > &fits_handle, const std::string &filename, const dit::did::Did &dictionary, const int32_t bitpix, const std::vector< int32_t > &naxes, std::string &target_filename, const bool remove_if_exists, const uint16_t nb_of_hdr_blocks)
Create a new FITS file.
Definition: fits.cpp:65
void ExtractHeaders(std::shared_ptr< CCfits::FITS > &fits_handle, std::string &hdr_buf, const int16_t hdr_ref)
Extract the keyword cards in one or more HDU's in an ASCII format (newline terminated).
Definition: fits.cpp:275
std::string GenerateKey(const std::string &key, const std::string &hierarch_prefix)
Generates an ESO hierarchical keyword.
Definition: fits.cpp:53
void addHDU(std::shared_ptr< CCfits::FITS > &fits_handle, std::string extensionName, int8_t bitpix, const std::vector< int32_t > &naxes)
Definition: fits.cpp:435
void OpenFitsFile(std::shared_ptr< CCfits::FITS > &fits_handle, const std::string &filename, std::string &target_filename, CCfits::RWmode mode)
Open an existing FITS file.
Definition: fits.cpp:340
void HandleCfitsioError(const std::string &operation, const int cfitsio_status)
Convert an ELT ICS data type to the corresponding cfitsio data type.
Definition: fits.cpp:30
void PrepForAddingKey(std::shared_ptr< CCfits::FITS > &fits_handle, const dit::did::Did &dictionary, const std::string &key, const int16_t hdu_nb, dit::did::Record &did_record, std::string &target_key, bool &key_in_hdu)
Used to prepare for adding a keyword card in a FITS file (mostly internal usage).
Definition: fits.cpp:245
bool KeyInHdu(std::shared_ptr< CCfits::FITS > &fits_handle, const int16_t hdu_nb, const std::string &key)
Check if a given key is contained in the referenced HDU (primary HDU = 1).
Definition: fits.cpp:140
void StoreImage(std::shared_ptr< CCfits::FITS > &fits_handle, int8_t bitpix, uint32_t image_size, const void *image_buffer, int16_t hdu_nb, int16_t naxis3)
Definition: fits.cpp:372
void MoveToHdu(std::shared_ptr< CCfits::FITS > &fits_handle, const int16_t hdu_nb)
Move to the given HDU.
Definition: fits.cpp:124
void AddDoubleKey(std::shared_ptr< CCfits::FITS > &fits_handle, const dit::did::Did &dictionary, const std::string &key, const double value, const uint16_t hdu_nb)
Add a double type key in an existing FITS file.
Definition: fits.cpp:185