mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Class to manage the three components of a FITS header card.
Since FITS does not provide the type in keyword=value pairs in a FITS header, it is up to the user to determine the type. Futhermore, since we want to read values from files, type must be set at runtime. The result is that we must be able to accept a string, which is converted to a given type on demand at determined at runtime.
Conversion from string to native type, or vice versa, only occurs when needed. So if you set the value to, say, a double, the value is not converted to string format unless specifically requested. If the write function is called when in this state, the cfitsio routine is called directly. This converson only on demand is most important for values read from a file, then written to another file. In this case, no conversion to its double (etc) representation. occurs.
Note that because of the checks to determine the type and appropriate return values, accessing the value in a card is possibly slower than accessing a variable due to various if statements. This means that you should typically do so once and use a local variable for repeated use.
Definition at line 56 of file fitsHeaderCard.hpp.
#include <ioutils/fits/fitsHeaderCard.hpp>
Classes | |
union | values |
The native type is held in a union. More... | |
Public Member Functions | |
Constructors | |
fitsHeaderCard () | |
Basic c'tor. More... | |
fitsHeaderCard (const std::string &k, const std::string &v, const std::string &c="") | |
Construct from the three components for a value of string type. More... | |
fitsHeaderCard (const std::string &k, const std::string &v, const int &type, const std::string &c="") | |
Construct from the three components, when already in a string format. More... | |
fitsHeaderCard (const std::string &k, fitsCommentType v, const std::string &c) | |
Construct from the three components, when it's really a comment card. More... | |
fitsHeaderCard (const std::string &k, fitsHistoryType v, const std::string &c) | |
Construct from the three components, when it's really a history card. More... | |
fitsHeaderCard (const std::string &k) | |
Construct from just keyword, when value's type is unknown. More... | |
fitsHeaderCard (const std::string &k, const int type) | |
Construct from just keyword, when value's type known. More... | |
template<typename typeT > | |
fitsHeaderCard (const std::string &k, const typeT v, const std::string &c="") | |
Construct from the three components for a char. More... | |
fitsHeaderCard (const fitsHeaderCard &card) | |
Copy constructor. More... | |
fitsHeaderCard & | operator= (const fitsHeaderCard &card) |
Assignment. More... | |
Accessors | |
const std::string & | keyword () |
Get the keyword. More... | |
void | keyword (const std::string &kw) |
Set the keyword. More... | |
int | type () |
Get the type. More... | |
void | type (const int &t) |
Set the type. More... | |
template<typename typeT > | |
typeT | value () |
Get the value. More... | |
std::string | String () |
Get the value as a string. More... | |
char | Char () |
Get the value as a char. More... | |
unsigned char | UChar () |
Get the value as an unsigned char. More... | |
short | Short () |
Get the value as a short. More... | |
unsigned short | UShort () |
Get the value as an unsigned short. More... | |
int | Int () |
Get the value as a int. More... | |
unsigned int | UInt () |
Get the value as an unsigned int. More... | |
long | Long () |
Get the value as a long. More... | |
unsigned long | ULong () |
Get the value as an unsigned long. More... | |
long long | LongLong () |
Get the value as a long long. More... | |
unsigned long long | ULongLong () |
Get the value as an unsigned long long. More... | |
float | Float () |
Get the value as a float. More... | |
std::complex< float > | complexFloat () |
Get the value as a std::complex<float> More... | |
double | Double () |
Get the value as a double. More... | |
std::complex< double > | complexDouble () |
Get the value as a std::complex<double> More... | |
void | value (const char *v) |
Set the value to a char * string. More... | |
void | value (const std::string &v) |
Set the value to a std::string. More... | |
void | value (const char &v) |
Set the value to a char. More... | |
void | value (const unsigned char &v) |
Set the value to an unsigned char. More... | |
void | value (const short int &v) |
Set the value to a short int. More... | |
void | value (const unsigned short int &v) |
Set the value to an unsigned short int. More... | |
void | value (const int &v) |
Set the value to an int. More... | |
void | value (const unsigned int &v) |
Set the value to an unsigned int. More... | |
void | value (const long &v) |
Set the value to a long int. More... | |
void | value (const unsigned long int &v) |
Set the value to an unsigned long int. More... | |
void | value (const long long &v) |
Set the value to a long long int. More... | |
void | value (const unsigned long long int &v) |
Set the value to an unsigned long long int. More... | |
void | value (const float &v) |
Set the value to a float. More... | |
void | value (const std::complex< float > &v) |
Set the value to a complex float. More... | |
void | value (const double &v) |
Set the value to a double. More... | |
void | value (const std::complex< double > &v) |
Set the value to a complex double. More... | |
std::string | valueStr () |
bool | valueGood () |
bool | valueStrGood () |
const std::string & | comment () |
Get the comment. More... | |
void | comment (const std::string &c) |
Set the comment. More... | |
Output | |
int | write (fitsfile *fptr) |
Writes this card to a FITS file, using mx::improc::fits_write_key<typename typeT>(fitsfile * fptr, char * keyword, void * value, char * comment). More... | |
Protected Member Functions | |
Converters | |
void | convertToString () |
Convert from the type to a string. More... | |
template<typename typeT > | |
void | convertFromString () |
Convert from string to the type. More... | |
template<typename typeT > | |
typeT | convertedValue () |
Get the value from its type converted to a different type. More... | |
void | convertValue (int newtype) |
Convert the value from its type to a different type. More... | |
Protected Attributes | |
std::string | m_keyword |
The keyword. More... | |
int | m_type {fitsType<fitsUnknownType>()} |
The FITS type of the value, and indicates which member of m_values to access. More... | |
std::stringstream | m_valueStr |
The value in string form. More... | |
bool | m_valueGood {false} |
Flag indicating if the value is valid. More... | |
bool | m_valueStrGood {false} |
Flag indicating if the value string is valid. More... | |
std::string | m_comment |
The comment. More... | |
|
inline |
Basic c'tor.
Definition at line 108 of file fitsHeaderCard.hpp.
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const std::string & | k, |
const std::string & | v, | ||
const std::string & | c = "" |
||
) |
Construct from the three components for a value of string type.
[in] | k | the keyword |
[in] | v | the value string |
[in] | c | the comment |
Definition at line 34 of file fitsHeaderCard.cpp.
References mx::astro::constants::c(), mx::astro::constants::k(), m_comment, m_keyword, m_type, m_valueGood, m_valueStr, and m_valueStrGood.
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const std::string & | k, |
const std::string & | v, | ||
const int & | type, | ||
const std::string & | c = "" |
||
) |
Construct from the three components, when already in a string format.
Use this when the value is not a string
[in] | k | the keyword |
[in] | v | the value string |
[in] | type | the type of the value |
[in] | c | the comment |
Definition at line 47 of file fitsHeaderCard.cpp.
References mx::astro::constants::c(), mx::astro::constants::k(), m_comment, m_keyword, m_type, m_valueGood, m_valueStr, m_valueStrGood, and type().
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const std::string & | k, |
fitsCommentType | v, | ||
const std::string & | c | ||
) |
Construct from the three components, when it's really a comment card.
This overload is provided to facilitate handling of comments when re-writing the file.
[in] | k | the keyword |
[in] | v | an object of type fitsCommentType |
[in] | c | the comment |
Definition at line 61 of file fitsHeaderCard.cpp.
References mx::astro::constants::k(), m_keyword, m_type, m_valueGood, and m_valueStrGood.
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const std::string & | k, |
fitsHistoryType | v, | ||
const std::string & | c | ||
) |
Construct from the three components, when it's really a history card.
This overload is provided to facilitate handling of history when re-writing the file.
[in] | k | the keyword |
[in] | v | an object of type fitsHistoryType |
[in] | c | the comment |
Definition at line 73 of file fitsHeaderCard.cpp.
References mx::astro::constants::k(), m_keyword, m_type, m_valueGood, and m_valueStrGood.
|
explicit |
Construct from just keyword, when value's type is unknown.
[in] | k | the keyword |
Definition at line 85 of file fitsHeaderCard.cpp.
References mx::astro::constants::k(), and m_keyword.
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const std::string & | k, |
const int | type | ||
) |
Construct from just keyword, when value's type known.
[in] | k | the keyword |
[in] | type | the type |
Definition at line 90 of file fitsHeaderCard.cpp.
References mx::astro::constants::k(), m_keyword, m_type, and type().
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const std::string & | k, |
const typeT | v, | ||
const std::string & | c = "" |
||
) |
Construct from the three components for a char.
[in] | k | they keyword |
[in] | v | the value |
[in] | c | the comment |
Definition at line 482 of file fitsHeaderCard.hpp.
References mx::astro::constants::c(), mx::astro::constants::k(), m_comment, m_keyword, and value().
mx::fits::fitsHeaderCard::fitsHeaderCard | ( | const fitsHeaderCard & | card | ) |
Copy constructor.
Definition at line 99 of file fitsHeaderCard.cpp.
References m_comment, m_keyword, m_type, m_valueGood, m_valueStr, and m_valueStrGood.
char mx::fits::fitsHeaderCard::Char | ( | ) |
Get the value as a char.
This calls value<char>().
if | the value can't be converted to char |
Definition at line 758 of file fitsHeaderCard.cpp.
const std::string & mx::fits::fitsHeaderCard::comment | ( | ) |
Get the comment.
Definition at line 1027 of file fitsHeaderCard.cpp.
References m_comment.
void mx::fits::fitsHeaderCard::comment | ( | const std::string & | c | ) |
Set the comment.
[in] | c | the new comment |
Definition at line 1032 of file fitsHeaderCard.cpp.
References mx::astro::constants::c(), and m_comment.
std::complex< double > mx::fits::fitsHeaderCard::complexDouble | ( | ) |
Get the value as a std::complex<double>
This calls value<std::complex<double>>().
if | the value can't be converted to std::complex<double> |
Definition at line 823 of file fitsHeaderCard.cpp.
std::complex< float > mx::fits::fitsHeaderCard::complexFloat | ( | ) |
Get the value as a std::complex<float>
This calls value<std::complex<float>>().
if | the value can't be converted to std::complex<float> |
Definition at line 813 of file fitsHeaderCard.cpp.
|
protected |
Get the value from its type converted to a different type.
Definition at line 313 of file fitsHeaderCard.cpp.
References m_type.
|
protected |
Convert from string to the type.
This populates the appropriate union field and sets m_valueGood so that this conversion only occurs once.
|
protected |
Convert from the type to a string.
This populates m_valueStr and sets m_valueStrGood so that this conversion only occurs once.
Definition at line 123 of file fitsHeaderCard.cpp.
References m_keyword, m_type, and m_valueGood.
|
protected |
Convert the value from its type to a different type.
[in] | newtype | the new type |
Definition at line 392 of file fitsHeaderCard.cpp.
References m_type, and m_valueGood.
Referenced by type().
double mx::fits::fitsHeaderCard::Double | ( | ) |
Get the value as a double.
This calls value<double>().
if | the value can't be converted to double |
Definition at line 818 of file fitsHeaderCard.cpp.
float mx::fits::fitsHeaderCard::Float | ( | ) |
Get the value as a float.
This calls value<float>().
if | the value can't be converted to float |
Definition at line 808 of file fitsHeaderCard.cpp.
int mx::fits::fitsHeaderCard::Int | ( | ) |
Get the value as a int.
This calls value<int>().
if | the value can't be converted to int |
Definition at line 778 of file fitsHeaderCard.cpp.
const std::string & mx::fits::fitsHeaderCard::keyword | ( | ) |
Get the keyword.
Definition at line 495 of file fitsHeaderCard.cpp.
References m_keyword.
Referenced by mx::fits::fitsHeader::append(), mx::fits::fitsHeader::insert_after(), and mx::fits::fitsHeader::insert_before().
void mx::fits::fitsHeaderCard::keyword | ( | const std::string & | kw | ) |
Set the keyword.
[in] | kw | the new keyword |
Definition at line 500 of file fitsHeaderCard.cpp.
References m_keyword.
long mx::fits::fitsHeaderCard::Long | ( | ) |
Get the value as a long.
This calls value<long>().
if | the value can't be converted to long |
Definition at line 788 of file fitsHeaderCard.cpp.
long long mx::fits::fitsHeaderCard::LongLong | ( | ) |
Get the value as a long long.
This calls value<long long>().
if | the value can't be converted to long long |
Definition at line 798 of file fitsHeaderCard.cpp.
fitsHeaderCard & mx::fits::fitsHeaderCard::operator= | ( | const fitsHeaderCard & | card | ) |
Assignment.
Definition at line 110 of file fitsHeaderCard.cpp.
References m_comment, m_keyword, m_type, m_valueGood, m_valueStr, and m_valueStrGood.
short mx::fits::fitsHeaderCard::Short | ( | ) |
Get the value as a short.
This calls value<short>().
if | the value can't be converted to short |
Definition at line 768 of file fitsHeaderCard.cpp.
std::string mx::fits::fitsHeaderCard::String | ( | ) |
Get the value as a string.
This calls value<string>().
if | the value can't be converted to a string |
Definition at line 753 of file fitsHeaderCard.cpp.
int mx::fits::fitsHeaderCard::type | ( | ) |
Get the type.
Definition at line 984 of file fitsHeaderCard.cpp.
References m_type.
Referenced by fitsHeaderCard(), mx::fits::fitsHeader::append(), mx::fits::fitsHeader::insert_after(), and mx::fits::fitsHeader::insert_before().
void mx::fits::fitsHeaderCard::type | ( | const int & | t | ) |
Set the type.
If this is a change in type and the native type is set in m_value (indicated by m_valueGood == true) then it is converted to the new type. Otherwise, no conversion occurs.
[in] | t | the new type |
Definition at line 989 of file fitsHeaderCard.cpp.
References convertValue(), m_type, m_valueGood, and m_valueStrGood.
unsigned char mx::fits::fitsHeaderCard::UChar | ( | ) |
Get the value as an unsigned char.
This calls value<unsigned char>().
if | the value can't be converted to unsigned char |
Definition at line 763 of file fitsHeaderCard.cpp.
unsigned int mx::fits::fitsHeaderCard::UInt | ( | ) |
Get the value as an unsigned int.
This calls value<unsigned int>().
if | the value can't be converted to unsigned int |
Definition at line 783 of file fitsHeaderCard.cpp.
unsigned long mx::fits::fitsHeaderCard::ULong | ( | ) |
Get the value as an unsigned long.
This calls value<unsigned long>().
if | the value can't be converted to unsigned long |
Definition at line 793 of file fitsHeaderCard.cpp.
unsigned long long mx::fits::fitsHeaderCard::ULongLong | ( | ) |
Get the value as an unsigned long long.
This calls value<unsigned long long>().
if | the value can't be converted to unsigned long long |
Definition at line 803 of file fitsHeaderCard.cpp.
unsigned short mx::fits::fitsHeaderCard::UShort | ( | ) |
Get the value as an unsigned short.
This calls value<unsigned short>().
if | the value can't be converted to unsigned short |
Definition at line 773 of file fitsHeaderCard.cpp.
typeT mx::fits::fitsHeaderCard::value | ( | ) |
Get the value.
Returns the value as typeT. Conversions occur automatically if necessary.
if | the value can't be converted to typeT |
Referenced by fitsHeaderCard().
void mx::fits::fitsHeaderCard::value | ( | const char & | v | ) |
Set the value to a char.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a char |
Definition at line 871 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::Char, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const char * | v | ) |
Set the value to a char * string.
[in] | v | a character string |
Definition at line 828 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStr, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const double & | v | ) |
Set the value to a double.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a double |
Definition at line 968 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::Double, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const float & | v | ) |
Set the value to a float.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a float |
Definition at line 951 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::Float, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const int & | v | ) |
Set the value to an int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | an int |
Definition at line 903 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::Int, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const long & | v | ) |
Set the value to a long int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a long int |
Definition at line 919 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::Long, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const long long & | v | ) |
Set the value to a long long int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a long long int |
Definition at line 935 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::LongLong, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const short int & | v | ) |
Set the value to a short int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a short int |
Definition at line 887 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStrGood, and mx::fits::fitsHeaderCard::values::Short.
void mx::fits::fitsHeaderCard::value | ( | const std::complex< double > & | v | ) |
Set the value to a complex double.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a complex double |
Definition at line 976 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::complexDouble, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const std::complex< float > & | v | ) |
Set the value to a complex float.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a complex float |
Definition at line 960 of file fitsHeaderCard.cpp.
References mx::fits::fitsHeaderCard::values::complexFloat, m_type, m_valueGood, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const std::string & | v | ) |
Set the value to a std::string.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | a std::string |
Definition at line 850 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStr, and m_valueStrGood.
void mx::fits::fitsHeaderCard::value | ( | const unsigned char & | v | ) |
Set the value to an unsigned char.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | an unsigned char |
Definition at line 879 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStrGood, and mx::fits::fitsHeaderCard::values::UChar.
void mx::fits::fitsHeaderCard::value | ( | const unsigned int & | v | ) |
Set the value to an unsigned int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | an unsigned int |
Definition at line 911 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStrGood, and mx::fits::fitsHeaderCard::values::UInt.
void mx::fits::fitsHeaderCard::value | ( | const unsigned long int & | v | ) |
Set the value to an unsigned long int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | an unsigned long int |
Definition at line 927 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStrGood, and mx::fits::fitsHeaderCard::values::ULong.
void mx::fits::fitsHeaderCard::value | ( | const unsigned long long int & | v | ) |
Set the value to an unsigned long long int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | an unsigned long long int |
Definition at line 943 of file fitsHeaderCard.cpp.
References m_type, m_valueGood, m_valueStrGood, and mx::fits::fitsHeaderCard::values::ULongLong.
void mx::fits::fitsHeaderCard::value | ( | const unsigned short int & | v | ) |
Set the value to an unsigned short int.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | v | an unsigned short int |
int mx::fits::fitsHeaderCard::write | ( | fitsfile * | fptr | ) |
Writes this card to a FITS file, using mx::improc::fits_write_key<typename typeT>(fitsfile * fptr, char * keyword, void * value, char * comment).
Definition at line 1037 of file fitsHeaderCard.cpp.
References m_type.
|
protected |
The comment.
Definition at line 99 of file fitsHeaderCard.hpp.
Referenced by fitsHeaderCard(), comment(), and operator=().
|
protected |
The keyword.
Definition at line 61 of file fitsHeaderCard.hpp.
Referenced by fitsHeaderCard(), convertToString(), keyword(), and operator=().
|
protected |
The FITS type of the value, and indicates which member of m_values to access.
Definition at line 64 of file fitsHeaderCard.hpp.
Referenced by fitsHeaderCard(), convertedValue(), convertToString(), convertValue(), operator=(), type(), value(), and write().
|
protected |
Flag indicating if the value is valid.
Definition at line 95 of file fitsHeaderCard.hpp.
Referenced by fitsHeaderCard(), convertToString(), convertValue(), operator=(), type(), and value().
|
protected |
The value in string form.
Definition at line 93 of file fitsHeaderCard.hpp.
Referenced by fitsHeaderCard(), operator=(), and value().
|
protected |
Flag indicating if the value string is valid.
Definition at line 96 of file fitsHeaderCard.hpp.
Referenced by fitsHeaderCard(), operator=(), type(), and value().