9 #ifndef IFW_DIT_FITS_HPP_
10 #define IFW_DIT_FITS_HPP_
15 #include <CCfits/CCfits.h>
16 #include <CCfits/FITS.h>
17 #include <CCfits/PHDU.h>
44 const int cfitsio_status);
72 void CreateFile(std::shared_ptr<CCfits::FITS>& fits_handle,
73 const std::string& filename,
76 const std::vector<int32_t>& naxes,
77 std::string& target_filename,
78 const bool remove_if_exists =
false,
79 const uint16_t nb_of_hdr_blocks = 1);
88 void OpenFitsFile(std::shared_ptr<CCfits::FITS>& fits_handle,
89 const std::string& filename,
90 std::string& target_filename,
91 CCfits::RWmode mode = CCfits::Read);
100 bool KeyInHdu(std::shared_ptr<CCfits::FITS>& fits_handle,
101 const int16_t hdu_nb,
102 const std::string& key);
109 void MoveToHdu(std::shared_ptr<CCfits::FITS>& fits_handle,
110 const int16_t hdu_nb);
128 const std::string& key,
129 const int16_t hdu_nb,
131 std::string& target_key,
147 template <
class TYPE>
148 void AddKey(std::shared_ptr<CCfits::FITS>& fits_handle,
150 const std::string& key,
152 const int16_t hdu_nb) {
155 RAD_LOG_DEBUG1() <<
"Keyword to add: \"" << key <<
"\". Type: " <<
typeid(value).name();
157 if ((
typeid(TYPE) ==
typeid(
double)) || (
typeid(TYPE) ==
typeid(
float))) {
159 throw rad::Exception(
"Use dit::fits::AddDoubleKey() for floating point "
160 "type keyword cards");
164 std::string target_key;
168 PrepForAddingKey(fits_handle, dictionary, key, hdu_nb, did_record, target_key, key_in_hdu,
169 cfitsio_type, format_spec);
173 fits_handle.get()->pHDU().addKey(target_key, value, did_record.
GetComment());
175 fits_handle.get()->extension(hdu_nb).addKey(target_key, value, did_record.
GetComment());
177 }
catch (CCfits::FitsException& ex) {
178 throw rad::Exception(
ifw::Write(
"Error adding key: \"%s\". Diagnostics: %s.",
179 key.c_str(), ex.message().c_str()));
192 void AddDoubleKey(std::shared_ptr<CCfits::FITS>& fits_handle,
194 const std::string& key,
196 const uint16_t hdu_nb);
217 void Verify(
const std::string& filename,
218 std::string& target_filename,
228 void Verify(
const std::string& filename,
229 std::string& target_filename,
242 std::string& target_filename,
243 std::string& hdr_buf,
253 std::string& hdr_buf,
259 #endif // IFW_DIT_FITS_HPP_
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:331
const std::string & GetComment() const
Get the comment defined.
Definition: Record.cpp:306
void MoveToHdu(std::shared_ptr< CCfits::FITS > &fits_handle, const int16_t hdu_nb)
Move to the given HDU.
Definition: fits.cpp:136
DataType
Data types numeric representations.
Definition: types.hpp:34
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:189
void Verify(const std::string &filename, std::string &target_filename, dit::fits::FitsReport &report)
Function to carry out a verification check on a FITS file.
Definition: fits.cpp:72
CfitsioType DidToCfitsioType(ctd::defines::DataType did_type)
Convert an ELT ICS data type to the corresponding cfitsio data type.
Definition: fits.cpp:14
std::string GenerateKey(const std::string &key, const std::string &hierarch_prefix)
Generates an ESO hierarchical keyword.
Definition: fits.cpp:58
const std::string FITS_KEY_ESO_HIERARCH
Definition: fits.hpp:29
~FitsReport()
Definition: fits.hpp:202
FitsReport()
Definition: fits.hpp:201
std::string Write(const char *format,...)
Create formatted string, return formatted string (C formatting convention).
Definition: defines.cpp:54
Class to handle Data Interface Dictionaries.
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:150
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)
Template function to add a keyword card in an existing FITS file.
Definition: fits.hpp:148
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:91
void HandleCfitsioError(const std::string &operation, const int cfitsio_status)
Throw an exception, extracting the relevant info from cfitsio, if status != 0.
Definition: fits.cpp:33
Data Interface Dictionary keyword record class.
Definition: Record.hpp:158
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, CfitsioType &cfitsio_type, dit::did::FormatSpecifier &format_specifier)
Used to prepare for adding a keyword card in a FITS file (mostly internal usage). ...
Definition: fits.cpp:241
const int16_t ALL_HEADERS
Definition: fits.hpp:30
Data Interface Dictionary class.
Definition: Did.hpp:36
int32_t CfitsioType
Definition: fits.hpp:27
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:269