43 #include "Eigen/Dense"
47 #include "unsupported/Eigen/CXX11/Tensor"
49 int main(
int argc,
char** argv) {
79 intvar1.write<
int>({1, 2, 3, 4, 5, 6});
86 g.vars.create<
float>(
"var-2", {2, 3, 4}).write<float>({1.1f, 2.2f, 3.14159f, 4, 5, 6,
87 7, 8, 9, 10, 11.5f, 12.6f,
88 13, 14, 15, 16, 17, 18,
89 19, 20, 21, 22, 23, 24});
100 p1.chunks = {200, 3};
101 p1.setFillValue<
int>(-999);
102 p1.compressWithGZIP();
105 g.vars.create<
int>(
"var-3", {200, 3}, {2000, 3},
p1);
114 std::vector<int> v_data_4{1, 2, 3, 4, 5, 6, 7, 8, 9};
115 std::array<int, 6> a_data_5{1, 2, 3, 4, 5, 6};
116 std::valarray<int> va_data_6{1, 2, 3, 4};
117 const size_t sz_ca_data_7 = 7;
118 const int ca_data_7[sz_ca_data_7]
119 = {1, 2, 3, 4, 5, 6, 7};
121 g.vars.create<
int>(
"var-4", {gsl::narrow<ioda::Dimensions_t>(v_data_4.size())})
122 .write<int>(gsl::make_span(v_data_4));
123 g.vars.create<
int>(
"var-5", {gsl::narrow<ioda::Dimensions_t>(a_data_5.size())})
124 .write<int>(gsl::make_span(a_data_5));
125 g.vars.create<
int>(
"var-6", {gsl::narrow<ioda::Dimensions_t>(va_data_6.size())})
126 .write<int>(gsl::make_span(std::begin(va_data_6), std::end(va_data_6)));
128 g.vars.create<
int>(
"exgroup/var-7", {sz_ca_data_7})
129 .write<int>(gsl::make_span(ca_data_7, sz_ca_data_7));
144 Expects(
g.exists(
"exgroup"));
145 Expects(
g.open(
"exgroup").vars.exists(
"var-7"));
146 Expects(
g.vars.exists(
"exgroup/var-7"));
151 auto bad_1 =
g.vars.create<
int>(
"bad-int-1", {1});
152 bad_1.write<
float>(std::vector<float>{2.2f});
153 }
catch (std::exception) {
166 const int num_i = 30, num_j = 30;
167 Eigen::ArrayXXi x(num_i, num_j);
169 for (
int i = 0; i < num_i; ++i)
170 for (
int j = 0; j < num_j; ++j) x(i, j) = j + 3 * i;
179 Eigen::ArrayXXi y(num_i, num_j);
180 for (
int i = 0; i < num_i; ++i)
181 for (
int j = 0; j < num_j; ++j) y(i, j) = (i * i) - j;
184 Eigen::ArrayXXi z = (2 * y) - x;
187 g.vars.create<
int>(
"var-y", {num_i, num_j}).writeWithEigenRegular(y);
188 g.vars.create<
int>(
"var-z", {num_i, num_j}).writeWithEigenRegular(z);
191 Eigen::Tensor<int, 3, Eigen::RowMajor> data_4d(3, 3, 3);
192 for (
int i = 0; i < 3; ++i)
193 for (
int j = 0; j < 3; ++j)
194 for (
int k = 0; k < 3; ++k) data_4d(i, j, k) = i + j - k;
195 g.vars.create<
int>(
"var-4d", {3, 3, 3}).writeWithEigenTensor(data_4d);
205 std::vector<std::string> varList =
g.vars.list();
206 if (varList.size() != 11)
209 .
add(
"Actual", varList.size());
212 if (!
g.vars.exists(
"var-2"))
214 g.vars.create<
int>(
"removable-int-1", {1});
215 g.vars.remove(
"removable-int-1");
226 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
228 z2 =
g.vars.open(
"var-z-2");
229 }
catch (std::exception) {
238 Expects(y1_dims.
dimsCur[0] == num_i);
239 Expects(y1_dims.
dimsCur[1] == num_j);
244 Expects(y1_dims.
dimsMax[0] == num_i);
250 Expects(y1.
isA<
int>() ==
true);
255 std::vector<int> v_data_4_check;
256 g.vars[
"var-4"].read<
int>(v_data_4_check);
257 Expects(v_data_4_check[3] == 4);
260 std::valarray<int> va_data_4_check;
261 g.vars[
"var-4"].read<
int>(va_data_4_check);
262 Expects(va_data_4_check[3] == 4);
265 std::array<int, 6> check_a_data_5;
266 g.vars[
"var-5"].read<
int>(gsl::make_span(check_a_data_5));
267 Expects(check_a_data_5[3] == 4);
270 Eigen::ArrayXXi y1_check;
272 Expects(y1_check(0, 0) == 0);
273 Expects(y1_check(2, 1) == 3);
274 Expects(y1_check(1, 2) == -1);
275 Expects(y1_check(2, 2) == 2);
278 Eigen::Tensor<int, 3, Eigen::RowMajor> data_4d_check(v4d_dims.
dimsCur[0], v4d_dims.
dimsCur[1],
280 g.vars[
"var-4d"].readWithEigenTensor(data_4d_check);
281 Expects(data_4d_check(0, 0, 0) == 0);
282 Expects(data_4d_check(1, 0, 0) == 1);
283 Expects(data_4d_check(0, 1, 0) == 1);
284 Expects(data_4d_check(0, 0, 1) == -1);
288 std::vector<double> y1_check_bad;
289 y1.
read<
double>(y1_check_bad);
294 }
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.
Variable_Implementation writeWithEigenRegular(const EigenClass &d, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all)
Write an Eigen object (a Matrix, an Array, a Block, a Map).
bool isA() const
Convenience function to check a Variable's storage type.
virtual Dimensions getDimensions() const
virtual Variable read(gsl::span< char > data, const Type &in_memory_dataType, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all) const
Read the Variable - as char array. Ordering is row-major.
Variable_Implementation readWithEigenRegular(EigenClass &res, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all) const
Read data into an Eigen::Array, Eigen::Matrix, Eigen::Map, etc.
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...
int main(int argc, char **argv)
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.
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.
std::vector< Dimensions_t > dimsMax
This must always equal dimsCur for Attribute.
Used to specify Variable creation-time properties.