8 #ifndef CORE_IODAUTILS_H_
9 #define CORE_IODAUTILS_H_
15 #include "oops/util/abor1_cpp.h"
16 #include "oops/util/missingValues.h"
23 const std::vector<std::string> & StringVector);
26 const std::vector<std::size_t> & CharShape);
29 const std::vector<std::size_t> & CharShape,
char * CharData);
33 std::string
TypeIdName(
const std::type_info & TypeId);
47 template<
typename FromType,
typename ToType>
48 void ConvertVarType(
const std::vector<FromType> & FromVar, std::vector<ToType> & ToVar) {
49 std::string FromTypeName =
TypeIdName(
typeid(FromType));
50 std::string ToTypeName =
TypeIdName(
typeid(ToType));
51 const FromType FromMiss = util::missingValue(FromMiss);
52 const ToType ToMiss = util::missingValue(ToMiss);
61 bool FromTypeOkay = ((
typeid(FromType) ==
typeid(
int)) ||
62 (
typeid(FromType) ==
typeid(float)) ||
63 (
typeid(FromType) ==
typeid(
double)));
65 bool ToTypeOkay = ((
typeid(ToType) ==
typeid(
int)) ||
66 (
typeid(ToType) ==
typeid(float)) ||
67 (
typeid(ToType) ==
typeid(
double)));
69 if (FromTypeOkay && ToTypeOkay) {
70 for (std::size_t i = 0; i < FromVar.size(); i++) {
71 if (FromVar[i] == FromMiss) {
74 ToVar[i] =
static_cast<ToType
>(FromVar[i]);
78 std::string ErrorMsg =
"Unsupported variable data type conversion: " +
79 FromTypeName +
" to " + ToTypeName;
85 #endif // CORE_IODAUTILS_H_