35 const std::string & v,
43 m_type = fitsType<std::string>();
48 const std::string & v,
69 m_type = fitsType<fitsCommentType>();
81 m_type = fitsType<fitsHistoryType>();
103 memcpy( &m_value, &card.m_value,
sizeof(
values));
114 memcpy( &m_value, &card.m_value,
sizeof(
values));
131 if(
m_type == fitsType<char *>()||
m_type == fitsType<std::string>())
142 case fitsType<char>():
143 m_valueStr << static_cast<int>(m_value.
Char);
145 case fitsType<unsigned char>():
146 m_valueStr << static_cast<int>(m_value.
UChar);
148 case fitsType<short>():
151 case fitsType<unsigned short>():
154 case fitsType<int>():
157 case fitsType<unsigned int>():
160 case fitsType<long>():
163 case fitsType<unsigned long>():
166 case fitsType<long long>():
169 case fitsType<unsigned long long>():
172 case fitsType<float>():
175 case fitsType<std::complex<float>>():
178 case fitsType<double>():
181 case fitsType<std::complex<double>>():
184 case fitsType<fitsCommentType>():
186 case fitsType<fitsHistoryType>():
189 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertToString()",
"Unknown FITS type");
198 void fitsHeaderCard::convertFromString<char>()
200 m_type = fitsType<char>();
206 void fitsHeaderCard::convertFromString<unsigned char>()
208 m_type = fitsType<unsigned char>();
214 void fitsHeaderCard::convertFromString<short>()
216 m_type = fitsType<short>();
222 void fitsHeaderCard::convertFromString<unsigned short>()
224 m_type = fitsType<unsigned short>();
230 void fitsHeaderCard::convertFromString<int>()
238 void fitsHeaderCard::convertFromString<unsigned int>()
240 m_type = fitsType<unsigned int>();
247 void fitsHeaderCard::convertFromString<long>()
249 m_type = fitsType<long>();
255 void fitsHeaderCard::convertFromString<unsigned long>()
257 m_type = fitsType<unsigned long>();
263 void fitsHeaderCard::convertFromString<long long>()
265 m_type = fitsType<long long>();
271 void fitsHeaderCard::convertFromString<unsigned long long>()
273 m_type = fitsType<unsigned long long>();
279 void fitsHeaderCard::convertFromString<float>()
281 m_type = fitsType<float>();
287 void fitsHeaderCard::convertFromString<std::complex<float>>()
289 mxThrowException(err::notimpl,
"fitsHeaderCard::convertFromString<std::complex<float>>",
"no conversion from string to std::complex<float>");
290 m_type = fitsType<std::complex<float>>();
291 m_value.complexFloat = std::stof(m_valueStr.str());
296 void fitsHeaderCard::convertFromString<double>()
298 m_type = fitsType<double>();
304 void fitsHeaderCard::convertFromString<std::complex<double>>()
306 mxThrowException(err::notimpl,
"fitsHeaderCard::convertFromString<std::complex<double>>",
"no conversion from string to std::complex<double>");
307 m_type = fitsType<std::complex<double>>();
308 m_value.complexDouble = std::stof(m_valueStr.str());
312 template<
typename typeT>
317 case fitsType<unsigned char>():
319 return m_value.
UChar;
321 case fitsType<char>():
325 case fitsType<short>():
327 return m_value.
Short;
329 case fitsType<unsigned short>():
333 case fitsType<int>():
337 case fitsType<unsigned int>():
341 case fitsType<long>():
345 case fitsType<unsigned long>():
347 return m_value.
ULong;
349 case fitsType<long long>():
353 case fitsType<unsigned long long>():
357 case fitsType<float>():
359 return m_value.
Float;
361 case fitsType<std::complex<float>>():
363 mxThrowException(
err::notimpl,
"fitsHeaderCard::convertedValue<typeT>", std::string(
"conversions no supported for complex types in ") +
m_keyword);
365 case fitsType<double>():
369 case fitsType<std::complex<double>>():
371 mxThrowException(
err::notimpl,
"fitsHeaderCard::convertedValue<typeT>", std::string(
"conversions no supported for complex types in ") +
m_keyword);
373 case fitsType<fitsCommentType>():
375 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertedValue<typeT>",
"cannot convert comment to numeric type");
377 case fitsType<fitsHistoryType>():
379 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertedValue<typeT>",
"cannot convert history to numeric type");
383 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertedValue<typeT>", std::string(
"cannot convert string to numeric type in ") +
m_keyword);
387 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertedValue<typeT>", std::string(
"invalid FITS type for conversion in ") +
m_keyword);
402 case fitsType<unsigned char>():
404 m_value.
UChar = convertedValue<unsigned char>();
407 case fitsType<char>():
409 m_value.
Char = convertedValue<char>();
412 case fitsType<short>():
414 m_value.
Short = convertedValue<short>();
417 case fitsType<unsigned short>():
419 m_value.
UShort = convertedValue<unsigned short>();
422 case fitsType<int>():
424 m_value.
Int = convertedValue<int>();
427 case fitsType<unsigned int>():
429 m_value.
UInt = convertedValue<unsigned int>();
432 case fitsType<long>():
434 m_value.
Long = convertedValue<long>();
437 case fitsType<unsigned long>():
439 m_value.
ULong = convertedValue<unsigned long>();
442 case fitsType<long long>():
444 m_value.
LongLong = convertedValue<long long>();
447 case fitsType<unsigned long long>():
449 m_value.
ULongLong = convertedValue<unsigned long long>();
452 case fitsType<float>():
454 m_value.
Float = convertedValue<float>();
457 case fitsType<std::complex<float>>():
459 mxThrowException(
err::notimpl,
"fitsHeaderCard::convertValue", std::string(
"conversions not supported for complex types in ") +
m_keyword);
461 case fitsType<double>():
463 m_value.
Double = convertedValue<double>();
466 case fitsType<std::complex<double>>():
468 mxThrowException(
err::notimpl,
"fitsHeaderCard::convertValue", std::string(
"conversions not supported for complex types in ") +
m_keyword);
470 case fitsType<fitsCommentType>():
472 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertValue",
"cannot convert comment to numeric type");
474 case fitsType<fitsHistoryType>():
476 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertValue",
"cannot convert history to numeric type");
487 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertValue", std::string(
"invalid FITS type for conversion in ") +
m_keyword);
506 std::string fitsHeaderCard::value<std::string>()
508 if(m_valueStrGood ==
false)
514 std::string str = m_valueStr.str();
521 if(str[str.size()-1] ==
'\'')
523 str.erase(str.size()-1,1);
530 char fitsHeaderCard::value<char>()
534 convertFromString<char>();
537 if(
m_type != fitsType<char>())
539 return convertedValue<char>();
546 unsigned char fitsHeaderCard::value<unsigned char>()
550 convertFromString<unsigned char>();
553 if(
m_type != fitsType<unsigned char>())
555 return convertedValue<unsigned char>();
558 return m_value.
UChar;
562 short fitsHeaderCard::value<short>()
566 convertFromString<short>();
569 if(
m_type != fitsType<short>())
571 return convertedValue<short>();
574 return m_value.
Short;
578 unsigned short fitsHeaderCard::value<unsigned short>()
582 convertFromString<unsigned short>();
585 if(
m_type != fitsType<unsigned short>())
587 return convertedValue<unsigned short>();
594 int fitsHeaderCard::value<int>()
598 convertFromString<int>();
601 if(
m_type != fitsType<int>())
603 return convertedValue<int>();
610 unsigned int fitsHeaderCard::value<unsigned int>()
614 convertFromString<unsigned int>();
617 if(
m_type != fitsType<unsigned int>())
619 return convertedValue<unsigned int>();
626 long fitsHeaderCard::value<long>()
630 convertFromString<long>();
633 if(
m_type != fitsType<long>())
635 return convertedValue<long>();
642 unsigned long fitsHeaderCard::value<unsigned long>()
646 convertFromString<unsigned long>();
649 if(
m_type != fitsType<unsigned long>())
651 return convertedValue<unsigned long>();
654 return m_value.
ULong;
658 long long fitsHeaderCard::value<long long>()
662 convertFromString<long long>();
665 if(
m_type != fitsType<long long>())
667 return convertedValue<long long>();
674 unsigned long long fitsHeaderCard::value<unsigned long long>()
678 convertFromString<unsigned long long>();
681 if(
m_type != fitsType<unsigned long long>())
683 return convertedValue<unsigned long long>();
690 float fitsHeaderCard::value<float>()
694 convertFromString<float>();
697 if(
m_type != fitsType<float>())
699 return convertedValue<float>();
702 return m_value.
Float;
706 std::complex<float> fitsHeaderCard::value<std::complex<float>>()
708 if(m_valueGood ==
false)
710 convertFromString<std::complex<float>>();
713 if(m_type !=
fitsType<std::complex<float>>())
715 return convertedValue<std::complex<float>>();
718 return m_value.complexFloat;
722 double fitsHeaderCard::value<double>()
726 convertFromString<double>();
729 if(
m_type != fitsType<double>())
731 return convertedValue<double>();
738 std::complex<double> fitsHeaderCard::value<std::complex<double>>()
740 if(m_valueGood ==
false)
742 convertFromString<std::complex<double>>();
745 if(m_type !=
fitsType<std::complex<double>>())
747 return convertedValue<std::complex<double>>();
750 return m_value.complexDouble;
755 return value<std::string>();
760 return value<char>();
765 return value<unsigned char>();
770 return value<short>();
775 return value<unsigned short>();
785 return value<unsigned int>();
790 return value<long>();
795 return value<unsigned long>();
800 return value<long long>();
805 return value<unsigned long long>();
810 return value<float>();
815 return value<std::complex<float>>();
820 return value<double>();
825 return value<std::complex<double>>();
838 if(str[str.size()-1] ==
'\'')
840 str.erase(str.size()-1,1);
847 m_type = fitsType<char *>();
860 if(str[str.size()-1] ==
'\'')
862 str.erase(str.size()-1,1);
868 m_type = fitsType<std::string>();
876 m_type = fitsType<char>();
884 m_type = fitsType<unsigned char>();
892 m_type = fitsType<short>();
900 m_type = fitsType<unsigned short>();
916 m_type = fitsType<unsigned int>();
924 m_type = fitsType<long>();
932 m_type = fitsType<unsigned long>();
940 m_type = fitsType<long long>();
948 m_type = fitsType<unsigned long long>();
956 m_type = fitsType<float>();
965 m_type = fitsType<std::complex<float>>();
973 m_type = fitsType<double>();
981 m_type = fitsType<std::complex<double>>();
1006 std::string fitsHeaderCard::valueStr()
1017 bool fitsHeaderCard::valueGood()
1022 bool fitsHeaderCard::valueStrGood()
1039 if(
m_type == fitsType<char *>() ||
m_type == fitsType<std::string>())
1048 return fits_write_key<fitsUnknownType>(fptr, (
char *)
m_keyword.c_str(), (
void *)
m_valueStr.str().c_str(), (
char *)
m_comment.c_str());
1054 case fitsType<unsigned char>():
1056 return fits_write_key<unsigned char>(fptr, (
char *)
m_keyword.c_str(), &m_value.
UChar, (
char *)
m_comment.c_str());
1058 case fitsType<char>():
1060 return fits_write_key<char>(fptr, (
char *)
m_keyword.c_str(), &m_value.
Char, (
char *)
m_comment.c_str());
1062 case fitsType<short>():
1066 case fitsType<unsigned short>():
1068 return fits_write_key<unsigned short>(fptr, (
char *)
m_keyword.c_str(), &m_value.
UShort, (
char *)
m_comment.c_str());
1070 case fitsType<int>():
1072 return fits_write_key<int>(fptr, (
char *)
m_keyword.c_str(), &m_value.
Int, (
char *)
m_comment.c_str());
1074 case fitsType<unsigned int>():
1076 return fits_write_key<unsigned int>(fptr, (
char *)
m_keyword.c_str(), &m_value.
UInt, (
char *)
m_comment.c_str());
1078 case fitsType<long>():
1080 return fits_write_key<long>(fptr, (
char *)
m_keyword.c_str(), &m_value.
Long, (
char *)
m_comment.c_str());
1082 case fitsType<unsigned long>():
1084 return fits_write_key<unsigned long>(fptr, (
char *)
m_keyword.c_str(), &m_value.
ULong, (
char *)
m_comment.c_str());
1086 case fitsType<long long>():
1090 case fitsType<unsigned long long>():
1094 case fitsType<float>():
1098 case fitsType<double>():
1102 case fitsType<fitsCommentType>():
1104 return fits_write_comment(fptr, (
char *)
m_comment.c_str());
1106 case fitsType<fitsHistoryType>():
1108 return fits_write_history(fptr, (
char *)
m_comment.c_str());
mxException for invalid arguments
mxException for not implemented features
mxException for parameters which aren't set
constexpr units::realT c()
The speed of light.
constexpr units::realT k()
Boltzmann Constant.
constexpr int fitsType()
Return the cfitsio constant for a given data type.
std::string convertToString(const typeT &value, int precision=0)
Convert a numerical value to a string.