18 void check_equal(
const std::string&
name,
const std::vector<T>& vals,
const std::vector<T>& ref) {
19 std::ostringstream outerr;
20 outerr <<
"Check of " <<
name <<
" failed. Error: ";
23 if (vals.size() != ref.size()) {
24 outerr <<
"check_equal failed. vals.size() = " << vals.size() <<
", and ref.size() = " << ref.size()
28 for (
size_t i = 0; i < vals.size(); ++i) {
29 if (vals[i] != ref[i]) {
30 outerr <<
"check_equal failed at index " << i <<
". vals[" << i <<
"] = " << vals[i] <<
", and ref["
31 << i <<
"] = " << ref[i] <<
".\n";
36 throw std::logic_error(outerr.str().c_str());
40 int main(
int argc,
char** argv) {
92 f.atts.add<
string>(
"Str_1", {
"String 1"});
93 f.atts.add<
string>(
"Str_2", {
"Hi Steve!",
"Hi Ryan!"});
95 vector<string> v_data;
96 f.atts.read<
string>(
"Str_1", v_data);
99 f.atts.read<
string>(
"Str_2", v_data);
100 check_equal(
"Str_2", v_data, {
"Hi Steve!",
"Hi Ryan!"});
103 f.vars.create<
string>(
"v_Str_1", {1}).write<string>(std::vector<std::string>{
"var String 1"});
104 f.vars.create<
string>(
"v_Str_2", {2})
105 .write<string>(std::vector<std::string>{
"var String 2.1",
"var String 2.2"});
106 f.vars.create<
string>(
"v_Str_3", {2, 2})
107 .write<string>(std::vector<std::string>{
"var String 3 [0,0]",
"var String 3 [0,1]",
108 "var String 3 [1,0]",
"var String 3 [1,1]"});
110 vector<string> v_data;
111 f.vars[
"v_Str_1"].read(v_data);
114 f.vars[
"v_Str_2"].read(v_data);
115 check_equal(
"v_Str_2", v_data, {
"var String 2.1",
"var String 2.2"});
117 f.vars[
"v_Str_3"].read(v_data);
119 {
"var String 3 [0,0]",
"var String 3 [0,1]",
"var String 3 [1,0]",
"var String 3 [1,1]"});
124 string fillString(
"I_am_fill");
125 params.setFillValue<
string>(fillString);
126 f.vars.create<
string>(
"Str_w_fill", {2, 2}, {2, 2},
params);
128 vector<string> v_data;
129 f.vars[
"Str_w_fill"].read(v_data);
130 check_equal(
"Str_w_fill", v_data, {
"I_am_fill",
"I_am_fill",
"I_am_fill",
"I_am_fill"});
132 }
catch (
const std::exception& e) {
Definitions for setting up backends with file and memory I/O.
Interfaces for ioda::Group and related classes.
int main(int argc, char **argv)
void check_equal(const std::string &name, const std::vector< T > &vals, const std::vector< T > &ref)
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.
Used to specify Variable creation-time properties.