20 const std::vector<ioda::Dimensions_t>& exp_dims) {
25 if (dims.
dimensionality != gsl::narrow<ioda::Dimensions_t>(exp_dims.size())) {
26 err_msg =
name + std::string(
": dimensionality not equal to expected value");
27 exp_msg = std::string(
" expected dimensionality");
28 res_msg = std::string(
" ") +
name + std::string(
": dimensionality");
30 .
add(exp_msg, exp_dims.size())
35 for (std::size_t i = 0; i < exp_dims.size(); ++i) {
36 if (dims.
dimsCur[i] != exp_dims[i]) {
38 name + std::string(
": dimension ") + std::to_string(i) + std::string(
" not equal to expected value");
39 exp_msg = std::string(
" expected dimsCur[") + std::to_string(i) + std::string(
"]");
40 res_msg = std::string(
" ") +
name + std::string(
": dimsCur[") + std::to_string(i) + std::string(
"]");
42 .
add(exp_msg, exp_dims[i])
50 const std::vector<double>& exp_data) {
55 if (data.size() != exp_data.size()) {
56 err_msg =
name + std::string(
": data size not equal to expected value");
57 exp_msg = std::string(
" expected size");
58 res_msg = std::string(
" ") +
name + std::string(
": size");
60 .
add(exp_msg, exp_data.size())
61 .
add(res_msg, data.size());
65 for (std::size_t i = 0; i < exp_data.size(); ++i) {
66 double check = fabs((data[i] / exp_data[i]) - 1.0);
68 err_msg =
name + std::string(
": element ") + std::to_string(i) +
69 std::string(
" not within tolerence (1e-3) of expected value");
70 exp_msg = std::string(
" expected data[") + std::to_string(i) + std::string(
"]");
71 res_msg = std::string(
" ") +
name + std::string(
": data[") + std::to_string(i) + std::string(
"]");
73 .
add(exp_msg, exp_data[i])
74 .
add(res_msg, data[i]);
80 void check_data(
const std::string&
name,
const std::vector<int>& data,
const std::vector<int>& exp_data) {
85 if (data.size() != exp_data.size()) {
86 err_msg =
name + std::string(
": data size not equal to expected value");
87 exp_msg = std::string(
" expected size");
88 res_msg = std::string(
" ") +
name + std::string(
": size");
90 .
add(exp_msg, exp_data.size())
91 .
add(res_msg, data.size());
95 for (std::size_t i = 0; i < exp_data.size(); ++i) {
96 if (data[i] != exp_data[i]) {
98 name + std::string(
": element ") + std::to_string(i) + std::string(
" not equal to expected value");
99 exp_msg = std::string(
" expected data[") + std::to_string(i) + std::string(
"]");
100 res_msg = std::string(
" ") +
name + std::string(
": data[") + std::to_string(i) + std::string(
"]");
102 .
add(exp_msg, exp_data[i])
103 .
add(res_msg, data[i]);
111 auto g_c1 =
g.create(
"Child1");
112 auto g_c2 =
g.create(
"Child2");
115 g_c1.atts.template add<double>(
"double_single", {3.14159}, {1});
117 g_c2.atts.template add<int>(
"int_2x2", {1, 2, 3, 4}, {2, 2});
122 params_1.
chunk =
true;
123 params_1.compressWithGZIP();
124 auto v_double = g_c1.vars.template create<double>(
"double", {2, 2}, {2, 2}, params_1);
125 v_double.write<
double>({10.0, 11.0, 12.0, 13.0});
126 v_double.atts.template add<int>(
"int_2x3", {-2, -1, 0, 1, 2, 3}, {2, 3});
131 std::vector<ioda::Dimensions_t> exp_dims;
132 std::vector<double> exp_data_d;
133 std::vector<int> exp_data_i;
137 auto g_c1 =
g.open(
"Child1");
138 auto g_c2 =
g.open(
"Child2");
141 auto attr = g_c1.atts.open(
"double_single");
145 std::vector<double> a_data_d;
147 exp_data_d = {3.14159};
148 check_data(
"group attribute: double_single", a_data_d, exp_data_d);
150 attr = g_c2.atts.open(
"int_2x2");
151 a_dims = attr.getDimensions();
154 std::vector<int> a_data_i;
156 exp_data_i = {1, 2, 3, 4};
157 check_data(
"group attribute: int_2x2", a_data_i, exp_data_i);
160 auto var = g_c1.vars.open(
"double");
164 std::vector<double> v_data_d;
165 var.read<
double>(v_data_d);
166 exp_data_d = {10.0, 11.0, 12.0, 13.0};
167 check_data(
"variable: double", v_data_d, exp_data_d);
169 attr = var.atts.open(
"int_2x3");
170 a_dims = attr.getDimensions();
174 exp_data_i = {-2, -1, 0, 1, 2, 3};
175 check_data(
"variable attribute: int_2x3", a_data_i, exp_data_i);
178 int main(
int argc,
char** argv) {
179 using namespace ioda;
191 }
catch (
const std::exception& e) {
Definitions for setting up backends with file and memory I/O.
Interfaces for ioda::Group and related classes.
The ioda exception class.
Exception & add(const std::string &key, const T value)
Add a key-value pair to the error message.
Groups are a new implementation of ObsSpaces.
IODA_DL Group constructFromCmdLine(int argc, char **argv, const std::string &defaultFilename)
This is a wrapper function around the constructBackend function for creating a backend based on comma...
IODA_DL void unwind_exception_stack(const std::exception &e, std::ostream &out=std::cerr, int level=0)
Convenience function for unwinding an exception stack.
int main(int argc, char **argv)
void check_data(const std::string &name, const std::vector< double > &data, const std::vector< double > &exp_data)
void check_dimensions(const std::string &name, const ioda::Dimensions &dims, const std::vector< ioda::Dimensions_t > &exp_dims)
void check_group_structure(ioda::Group g)
void build_group_structure(ioda::Group g)
Describes the dimensions of an Attribute or Variable.
std::vector< Dimensions_t > dimsCur
The dimensions of the data.
Dimensions_t dimensionality
The dimensionality (rank) of the data.
Used to specify Variable creation-time properties.
VariableCreationParameters & setFillValue(DataType fill)
bool chunk
Do we chunk this variable? Required for extendible / compressible Variables.