8 #ifndef CORE_IODAUTILS_H_
9 #define CORE_IODAUTILS_H_
17 #include "eckit/config/LocalConfiguration.h"
23 #include "oops/util/abor1_cpp.h"
24 #include "oops/util/DateTime.h"
25 #include "oops/util/Duration.h"
26 #include "oops/util/missingValues.h"
30 class ObsSpaceParameters;
36 typedef std::map<std::string, std::vector<std::string>>
VarDimMap;
41 const std::vector<std::string> & StringVector);
44 const std::vector<std::size_t> & CharShape);
47 const std::vector<std::size_t> & CharShape,
char * CharData);
50 std::string
TypeIdName(
const std::type_info & TypeId);
57 std::string
fullVarName(
const std::string & groupName,
const std::string & varName);
77 Dimensions_t & maxVarSize0);
80 std::type_index
varDtype(
const Group & group,
const std::string & varName);
89 const std::vector<float> & timeOffsets);
101 const std::vector<std::string> & arrayData,
102 const std::vector<Dimensions_t> & arrayShape);
120 std::string
uniquifyFileName(
const std::string & fileName,
const std::size_t rankNum,
121 const int timeRankNum);
129 const std::vector<std::string> & varList,
130 const std::vector<std::string> & dimVarList);
147 template<
typename FromType,
typename ToType>
148 void ConvertVarType(
const std::vector<FromType> & FromVar, std::vector<ToType> & ToVar) {
149 ToVar.resize(FromVar.size());
151 std::string FromTypeName =
TypeIdName(
typeid(FromType));
152 std::string ToTypeName =
TypeIdName(
typeid(ToType));
153 const FromType FromMiss = util::missingValue(FromMiss);
154 const ToType ToMiss = util::missingValue(ToMiss);
160 bool FromTypeOkay = ((
typeid(FromType) ==
typeid(
int)) ||
161 (
typeid(FromType) ==
typeid(float)) ||
162 (
typeid(FromType) ==
typeid(
double)));
164 bool ToTypeOkay = ((
typeid(ToType) ==
typeid(
int)) ||
165 (
typeid(ToType) ==
typeid(float)) ||
166 (
typeid(ToType) ==
typeid(
double)));
168 if (FromTypeOkay && ToTypeOkay) {
169 for (std::size_t i = 0; i < FromVar.size(); i++) {
170 if (FromVar[i] == FromMiss) {
173 ToVar[i] =
static_cast<ToType
>(FromVar[i]);
177 std::string ErrorMsg =
"Unsupported variable data type conversion: " +
178 FromTypeName +
" to " + ToTypeName;
Describe the dimensions of a ioda::Attribute or ioda::Variable.
Interfaces for ioda::ObsGroup and related classes.
Interfaces for ioda::Variable and related classes.
Groups are a new implementation of ObsSpaces.
This class exists inside of ioda::Group and provides the interface to manipulating Variables.
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
void StringVectorToCharArray(const std::vector< std::string > &StringVector, const std::vector< std::size_t > &CharShape, char *CharData)
std::vector< std::size_t > CharShapeFromStringVector(const std::vector< std::string > &StringVector)
std::vector< std::pair< std::string, Variable > > VarNameObjectList
typedef for holding list of variable names with associated variable object
std::string fullVarName(const std::string &groupName, const std::string &varName)
form full variable name given individual group and variable names
void ConvertVarType(const std::vector< FromType > &FromVar, std::vector< ToType > &ToVar)
VarDimMap genDimsAttachedToVars(const Has_Variables &varContainer, const std::vector< std::string > &varList, const std::vector< std::string > &dimVarList)
form a map containing lists of dimension variables that are attached to each variable
std::map< std::string, std::vector< std::string > > VarDimMap
typedef for holding dim names attached to variables
std::type_index varDtype(const Group &group, const std::string &varName)
get variable data type
std::vector< std::string > CharArrayToStringVector(const char *CharData, const std::vector< std::size_t > &CharShape)
std::string uniquifyFileName(const std::string &fileName, const std::size_t rankNum, const int timeRankNum)
uniquify the output file name
void collectVarDimInfo(const ObsGroup &obsGroup, VarNameObjectList &varObjectList, VarNameObjectList &dimVarObjectList, VarDimMap &dimsAttachedToVars, Dimensions_t &maxVarSize0)
collect variable and dimension information from a ioda ObsGroup
std::vector< util::DateTime > convertRefOffsetToDtime(const int refIntDtime, const std::vector< float > &timeOffsets)
convert reference, time to DateTime object
bool varIsDimScale(const Group &group, const std::string &varName)
true if variable is a dimension scale
std::size_t FindMaxStringLength(const std::vector< std::string > &StringVector)
std::string TypeIdName(const std::type_info &TypeId)
void setOfileParamsFromTestConfig(const eckit::LocalConfiguration &obsConfig, ioda::ObsSpaceParameters &obsParams)
set params for output file construction from test YAML configuration
std::vector< util::DateTime > convertDtStringsToDtime(const std::vector< std::string > &dtStrings)
convert datetime strings to DateTime object
std::string convertNewVnameToOldVname(const std::string &varName)
convert the new format varible name to the old format
std::vector< std::string > StringArrayToStringVector(const std::vector< std::string > &arrayData, const std::vector< Dimensions_t > &arrayShape)
convert 2D string array to a vector of strings