40 m_type = fitsType<std::string>();
59 m_type = fitsType<fitsCommentType>();
68 m_type = fitsType<fitsHistoryType>();
87 memcpy( &m_value, &card.m_value,
sizeof(
values ) );
98 memcpy( &m_value, &card.m_value,
sizeof(
values ) );
112 "fitsHeaderCard::convertToString()",
113 "no value to convert for " +
m_keyword );
117 if(
m_type == fitsType<char *>() ||
m_type == fitsType<std::string>() )
128 case fitsType<char>():
129 m_valueStr << static_cast<int>( m_value.
Char );
131 case fitsType<unsigned char>():
132 m_valueStr << static_cast<int>( m_value.
UChar );
134 case fitsType<short>():
137 case fitsType<unsigned short>():
140 case fitsType<int>():
143 case fitsType<unsigned int>():
146 case fitsType<long>():
149 case fitsType<unsigned long>():
152 case fitsType<long long>():
155 case fitsType<unsigned long long>():
158 case fitsType<float>():
161 case fitsType<std::complex<float>>():
164 case fitsType<double>():
167 case fitsType<std::complex<double>>():
170 case fitsType<fitsCommentType>():
172 case fitsType<fitsHistoryType>():
175 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertToString()",
"Unknown FITS type" );
183void fitsHeaderCard::convertFromString<char>()
185 m_type = fitsType<char>();
190 catch(
const std::exception &e )
192 std::string msg =
"exception from std::stoi. no value for ";
196 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertFromString<char>", msg );
202void fitsHeaderCard::convertFromString<unsigned char>()
204 m_type = fitsType<unsigned char>();
209 catch(
const std::exception &e )
211 std::string msg =
"exception from std::stoi. no value for ";
215 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<unsigned char>", msg );
221void fitsHeaderCard::convertFromString<short>()
223 m_type = fitsType<short>();
228 catch(
const std::exception &e )
230 std::string msg =
"exception from std::stoi. no value for ";
234 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<short>", msg );
240void fitsHeaderCard::convertFromString<unsigned short>()
242 m_type = fitsType<unsigned short>();
247 catch(
const std::exception &e )
249 std::string msg =
"exception from std::stoi. no value for ";
253 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<unsigned short>", msg );
259void fitsHeaderCard::convertFromString<int>()
266 catch(
const std::exception &e )
268 std::string msg =
"exception from std::stoi. no value for ";
272 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<int>", msg );
278void fitsHeaderCard::convertFromString<unsigned int>()
280 m_type = fitsType<unsigned int>();
285 catch(
const std::exception &e )
287 std::string msg =
"exception from std::stoi. no value for ";
291 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<unsigned int>", msg );
297void fitsHeaderCard::convertFromString<long>()
299 m_type = fitsType<long>();
304 catch(
const std::exception &e )
306 std::string msg =
"exception from std::stoi. no value for ";
310 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<long>", msg );
316void fitsHeaderCard::convertFromString<unsigned long>()
318 m_type = fitsType<unsigned long>();
323 catch(
const std::exception &e )
325 std::string msg =
"exception from std::stoi. no value for ";
329 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<unsigned long>", msg );
335void fitsHeaderCard::convertFromString<long long>()
337 m_type = fitsType<long long>();
342 catch(
const std::exception &e )
344 std::string msg =
"exception from std::stoi. no value for ";
348 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<long long>", msg );
354void fitsHeaderCard::convertFromString<unsigned long long>()
356 m_type = fitsType<unsigned long long>();
361 catch(
const std::exception &e )
363 std::string msg =
"exception from std::stoi. no value for ";
367 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<unsigned long long>", msg );
373void fitsHeaderCard::convertFromString<float>()
375 m_type = fitsType<float>();
380 catch(
const std::exception &e )
382 std::string msg =
"exception from std::stof. no value for ";
386 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<float>", msg );
392void fitsHeaderCard::convertFromString<std::complex<float>>()
394 mxThrowException( err::notimpl,
395 "fitsHeaderCard::convertFromString<std::complex<float>>",
396 "no conversion from string to std::complex<float>" );
397 m_type = fitsType<std::complex<float>>();
398 m_value.complexFloat = std::stof( m_valueStr.str() );
403void fitsHeaderCard::convertFromString<double>()
406 m_type = fitsType<double>();
412 catch(
const std::exception &e )
414 std::string msg =
"exception from std::stod. no value for ";
418 mxThrowException( err::invalidarg,
"fitsHeaderCard::convertFromString<float>", msg );
424void fitsHeaderCard::convertFromString<std::complex<double>>()
426 mxThrowException( err::notimpl,
427 "fitsHeaderCard::convertFromString<std::complex<double>>",
428 "no conversion from string to std::complex<double>" );
429 m_type = fitsType<std::complex<double>>();
430 m_value.complexDouble = std::stof( m_valueStr.str() );
434template <
typename typeT>
439 case fitsType<unsigned char>():
441 return m_value.
UChar;
443 case fitsType<char>():
447 case fitsType<short>():
449 return m_value.
Short;
451 case fitsType<unsigned short>():
455 case fitsType<int>():
459 case fitsType<unsigned int>():
463 case fitsType<long>():
467 case fitsType<unsigned long>():
469 return m_value.
ULong;
471 case fitsType<long long>():
475 case fitsType<unsigned long long>():
479 case fitsType<float>():
481 return m_value.
Float;
483 case fitsType<std::complex<float>>():
486 "fitsHeaderCard::convertedValue<typeT>",
487 std::string(
"conversions no supported for complex types in " ) +
m_keyword );
489 case fitsType<double>():
493 case fitsType<std::complex<double>>():
496 "fitsHeaderCard::convertedValue<typeT>",
497 std::string(
"conversions no supported for complex types in " ) +
m_keyword );
499 case fitsType<fitsCommentType>():
502 "fitsHeaderCard::convertedValue<typeT>",
503 "cannot convert comment to numeric type" );
505 case fitsType<fitsHistoryType>():
508 "fitsHeaderCard::convertedValue<typeT>",
509 "cannot convert history to numeric type" );
514 "fitsHeaderCard::convertedValue<typeT>",
515 std::string(
"cannot convert string to numeric type in " ) +
m_keyword );
520 "fitsHeaderCard::convertedValue<typeT>",
521 std::string(
"invalid FITS type for conversion in " ) +
m_keyword );
536 case fitsType<unsigned char>():
538 m_value.
UChar = convertedValue<unsigned char>();
541 case fitsType<char>():
543 m_value.
Char = convertedValue<char>();
546 case fitsType<short>():
548 m_value.
Short = convertedValue<short>();
551 case fitsType<unsigned short>():
553 m_value.
UShort = convertedValue<unsigned short>();
556 case fitsType<int>():
558 m_value.
Int = convertedValue<int>();
561 case fitsType<unsigned int>():
563 m_value.
UInt = convertedValue<unsigned int>();
566 case fitsType<long>():
568 m_value.
Long = convertedValue<long>();
571 case fitsType<unsigned long>():
573 m_value.
ULong = convertedValue<unsigned long>();
576 case fitsType<long long>():
578 m_value.
LongLong = convertedValue<long long>();
581 case fitsType<unsigned long long>():
583 m_value.
ULongLong = convertedValue<unsigned long long>();
586 case fitsType<float>():
588 m_value.
Float = convertedValue<float>();
591 case fitsType<std::complex<float>>():
594 "fitsHeaderCard::convertValue",
595 std::string(
"conversions not supported for complex types in " ) +
m_keyword );
597 case fitsType<double>():
599 m_value.
Double = convertedValue<double>();
602 case fitsType<std::complex<double>>():
605 "fitsHeaderCard::convertValue",
606 std::string(
"conversions not supported for complex types in " ) +
m_keyword );
608 case fitsType<fitsCommentType>():
610 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertValue",
"cannot convert comment to numeric type" );
612 case fitsType<fitsHistoryType>():
614 mxThrowException(
err::invalidarg,
"fitsHeaderCard::convertValue",
"cannot convert history to numeric type" );
626 "fitsHeaderCard::convertValue",
627 std::string(
"invalid FITS type for conversion in " ) +
m_keyword );
646std::string fitsHeaderCard::value<std::string>()
648 if( m_valueStrGood ==
false )
654 std::string str = m_valueStr.str();
661 if( str[str.size() - 1] ==
'\'' )
663 str.erase( str.size() - 1, 1 );
670char fitsHeaderCard::value<char>()
674 convertFromString<char>();
677 if(
m_type != fitsType<char>() )
679 return convertedValue<char>();
686unsigned char fitsHeaderCard::value<unsigned char>()
690 convertFromString<unsigned char>();
693 if(
m_type != fitsType<unsigned char>() )
695 return convertedValue<unsigned char>();
698 return m_value.
UChar;
702short fitsHeaderCard::value<short>()
706 convertFromString<short>();
709 if(
m_type != fitsType<short>() )
711 return convertedValue<short>();
714 return m_value.
Short;
718unsigned short fitsHeaderCard::value<unsigned short>()
722 convertFromString<unsigned short>();
725 if(
m_type != fitsType<unsigned short>() )
727 return convertedValue<unsigned short>();
734int fitsHeaderCard::value<int>()
738 convertFromString<int>();
741 if(
m_type != fitsType<int>() )
743 return convertedValue<int>();
750unsigned int fitsHeaderCard::value<unsigned int>()
754 convertFromString<unsigned int>();
757 if(
m_type != fitsType<unsigned int>() )
759 return convertedValue<unsigned int>();
766long fitsHeaderCard::value<long>()
770 convertFromString<long>();
773 if(
m_type != fitsType<long>() )
775 return convertedValue<long>();
782unsigned long fitsHeaderCard::value<unsigned long>()
786 convertFromString<unsigned long>();
789 if(
m_type != fitsType<unsigned long>() )
791 return convertedValue<unsigned long>();
794 return m_value.
ULong;
798long long fitsHeaderCard::value<long long>()
802 convertFromString<long long>();
805 if(
m_type != fitsType<long long>() )
807 return convertedValue<long long>();
814unsigned long long fitsHeaderCard::value<unsigned long long>()
818 convertFromString<unsigned long long>();
821 if(
m_type != fitsType<unsigned long long>() )
823 return convertedValue<unsigned long long>();
830float fitsHeaderCard::value<float>()
834 convertFromString<float>();
837 if(
m_type != fitsType<float>() )
839 return convertedValue<float>();
842 return m_value.
Float;
846std::complex<float> fitsHeaderCard::value<std::complex<float>>()
848 if( m_valueGood ==
false )
850 convertFromString<std::complex<float>>();
853 if( m_type !=
fitsType<std::complex<float>>() )
855 return convertedValue<std::complex<float>>();
858 return m_value.complexFloat;
862double fitsHeaderCard::value<double>()
866 convertFromString<double>();
869 if(
m_type != fitsType<double>() )
871 return convertedValue<double>();
878std::complex<double> fitsHeaderCard::value<std::complex<double>>()
880 if( m_valueGood ==
false )
882 convertFromString<std::complex<double>>();
885 if( m_type !=
fitsType<std::complex<double>>() )
887 return convertedValue<std::complex<double>>();
890 return m_value.complexDouble;
895 return value<std::string>();
900 return value<char>();
905 return value<unsigned char>();
910 return value<short>();
915 return value<unsigned short>();
925 return value<unsigned int>();
930 return value<long>();
935 return value<unsigned long>();
940 return value<long long>();
945 return value<unsigned long long>();
950 return value<float>();
955 return value<std::complex<float>>();
960 return value<double>();
965 return value<std::complex<double>>();
978 if( str[str.size() - 1] ==
'\'' )
980 str.erase( str.size() - 1, 1 );
987 m_type = fitsType<char *>();
1000 if( str[str.size() - 1] ==
'\'' )
1002 str.erase( str.size() - 1, 1 );
1008 m_type = fitsType<std::string>();
1016 m_type = fitsType<char>();
1024 m_type = fitsType<unsigned char>();
1032 m_type = fitsType<short>();
1040 m_type = fitsType<unsigned short>();
1048 m_type = fitsType<int>();
1056 m_type = fitsType<unsigned int>();
1064 m_type = fitsType<long>();
1072 m_type = fitsType<unsigned long>();
1080 m_type = fitsType<long long>();
1088 m_type = fitsType<unsigned long long>();
1096 m_type = fitsType<float>();
1104 m_type = fitsType<std::complex<float>>();
1112 m_type = fitsType<double>();
1120 m_type = fitsType<std::complex<double>>();
1147std::string fitsHeaderCard::valueStr()
1158bool fitsHeaderCard::valueGood()
1163bool fitsHeaderCard::valueStrGood()
1180 if(
m_type == fitsType<char *>() ||
m_type == fitsType<std::string>() )
1182 return fits_write_key<char *>( fptr,
1192 return fits_write_key<fitsUnknownType>( fptr,
1201 case fitsType<unsigned char>():
1203 return fits_write_key<unsigned char>( fptr,
1208 case fitsType<char>():
1210 return fits_write_key<char>( fptr, (
char *)
m_keyword.c_str(), &m_value.
Char, (
char *)
m_comment.c_str() );
1212 case fitsType<short>():
1216 case fitsType<unsigned short>():
1218 return fits_write_key<unsigned short>( fptr,
1223 case fitsType<int>():
1225 return fits_write_key<int>( fptr, (
char *)
m_keyword.c_str(), &m_value.
Int, (
char *)
m_comment.c_str() );
1227 case fitsType<unsigned int>():
1229 return fits_write_key<unsigned int>( fptr,
1234 case fitsType<long>():
1236 return fits_write_key<long>( fptr, (
char *)
m_keyword.c_str(), &m_value.
Long, (
char *)
m_comment.c_str() );
1238 case fitsType<unsigned long>():
1240 return fits_write_key<unsigned long>( fptr,
1245 case fitsType<long long>():
1247 return fits_write_key<long long>( fptr,
1252 case fitsType<unsigned long long>():
1254 return fits_write_key<unsigned long long>( fptr,
1259 case fitsType<float>():
1263 case fitsType<double>():
1267 case fitsType<fitsCommentType>():
1269 return fits_write_comment( fptr, (
char *)
m_comment.c_str() );
1271 case fitsType<fitsHistoryType>():
1273 return fits_write_history( fptr, (
char *)
m_comment.c_str() );
1278 "fitsHeaderCard::write",
1279 std::string(
"invalid FITS type for " ) +
m_keyword );
mxException for invalid arguments
mxException for not implemented features
mxException for parameters which aren't set
constexpr int fitsType()
Return the cfitsio constant for a given data type.