11 #ifndef TEST_INTERFACE_OBSSPACE_H_ 12 #define TEST_INTERFACE_OBSSPACE_H_ 17 #define BOOST_TEST_NO_MAIN 18 #define BOOST_TEST_ALTERNATIVE_INIT_API 19 #define BOOST_TEST_DYN_LINK 20 #include <boost/test/unit_test.hpp> 22 #include <boost/noncopyable.hpp> 24 #include "eckit/config/LocalConfiguration.h" 26 #include "oops/util/Logger.h" 29 #include "fileio/IodaIO.h" 39 std::vector<eckit::LocalConfiguration> obstypes;
42 std::string TestObsType;
43 std::unique_ptr<ioda::IodaIO> TestIO;
49 std::size_t ExpectedNobs;
50 std::size_t ExpectedNlocs;
51 std::size_t ExpectedNrecs;
52 std::size_t ExpectedNvars;
55 conf.get(
"ObsTypes", obstypes);
56 for (std::size_t
i = 0;
i < obstypes.size(); ++
i) {
59 TestObsType = obstypes[
i].getString(
"ObsType");
62 FileName = obstypes[
i].getString(
"Input.filename");
64 BOOST_CHECK(TestIO.get());
67 ExpectedNlocs = obstypes[
i].getInt(
"Input.metadata.nlocs");
68 ExpectedNobs = obstypes[
i].getInt(
"Input.metadata.nobs");
69 ExpectedNrecs = obstypes[
i].getInt(
"Input.metadata.nrecs");
70 ExpectedNvars = obstypes[
i].getInt(
"Input.metadata.nvars");
71 Nlocs = TestIO->nlocs();
72 Nobs = TestIO->nobs();
73 Nrecs = TestIO->nrecs();
74 Nvars = TestIO->nvars();
76 BOOST_CHECK_EQUAL(ExpectedNlocs, Nlocs);
77 BOOST_CHECK_EQUAL(ExpectedNobs, Nobs);
78 BOOST_CHECK_EQUAL(ExpectedNrecs, Nrecs);
79 BOOST_CHECK_EQUAL(ExpectedNvars, Nvars);
81 if (obstypes[
i].has(
"Output.filename")) {
82 FileName = obstypes[
i].getString(
"Output.filename");
83 ExpectedNlocs = obstypes[
i].getInt(
"Output.metadata.nlocs");
84 ExpectedNobs = obstypes[
i].getInt(
"Output.metadata.nobs");
85 ExpectedNrecs = obstypes[
i].getInt(
"Output.metadata.nrecs");
86 ExpectedNvars = obstypes[
i].getInt(
"Output.metadata.nvars");
89 BOOST_CHECK(TestIO.get());
91 Nlocs = TestIO->nlocs();
92 Nobs = TestIO->nobs();
93 Nrecs = TestIO->nrecs();
94 Nvars = TestIO->nvars();
96 BOOST_CHECK_EQUAL(ExpectedNlocs, Nlocs);
97 BOOST_CHECK_EQUAL(ExpectedNobs, Nobs);
98 BOOST_CHECK_EQUAL(ExpectedNrecs, Nrecs);
99 BOOST_CHECK_EQUAL(ExpectedNvars, Nvars);
109 std::vector<eckit::LocalConfiguration> obstypes;
110 std::vector<std::string> varnames;
111 std::vector<float> ExpectedVnorms;
113 std::string FileName;
114 std::string TestObsType;
115 std::unique_ptr<ioda::IodaIO> TestIO;
117 std::unique_ptr<float[]> TestVarData;
122 conf.get(
"ObsTypes", obstypes);
123 for (std::size_t
i = 0;
i < obstypes.size(); ++
i) {
126 TestObsType = obstypes[
i].getString(
"ObsType");
129 FileName = obstypes[
i].getString(
"Input.filename");
133 varnames = obstypes[
i].getStringVector(
"Input.variables");
134 ExpectedVnorms = obstypes[
i].getFloatVector(
"Input.metadata.norms");
135 Tol = obstypes[
i].getFloat(
"Input.metadata.tolerance");
136 Vsize = TestIO->nlocs();
137 TestVarData.reset(
new float[Vsize]);
138 for(std::size_t
j = 0;
j < varnames.size(); ++
j) {
139 TestIO->ReadVar(varnames[
j], TestVarData.get());
143 for(std::size_t
k = 0;
k < Vsize; ++
k) {
144 Vnorm += pow(TestVarData.get()[
k], 2.0);
148 BOOST_CHECK_CLOSE(Vnorm, ExpectedVnorms[
j], Tol);
157 std::vector<eckit::LocalConfiguration> obstypes;
158 std::vector<std::string> varnames;
160 std::string FileName;
161 std::string TestObsType;
162 std::unique_ptr<ioda::IodaIO> TestIO;
167 std::unique_ptr<float[]> TestVarData;
169 std::size_t TestNlocs;
170 std::size_t TestNobs;
171 std::size_t TestNrecs;
172 std::size_t TestNvars;
178 conf.get(
"ObsTypes", obstypes);
179 for (std::size_t
i = 0;
i < obstypes.size(); ++
i) {
182 TestObsType = obstypes[
i].getString(
"ObsType");
186 if (obstypes[
i].has(
"Output.filename")) {
187 FileName = obstypes[
i].getString(
"Output.filename");
188 Nlocs = obstypes[
i].getInt(
"Output.metadata.nlocs");
189 Nobs = obstypes[
i].getInt(
"Output.metadata.nobs");
190 Nrecs = obstypes[
i].getInt(
"Output.metadata.nrecs");
191 Nvars = obstypes[
i].getInt(
"Output.metadata.nvars");
195 varnames = obstypes[
i].getStringVector(
"Output.variables");
196 TestVarData.reset(
new float[Nlocs]);
198 for (std::size_t
j = 0;
j < Nlocs; ++
j) {
199 TestVarData.get()[
j] = float(
j);
202 ExpectedSum *= varnames.size();
204 for(std::size_t
j = 0;
j < varnames.size(); ++
j) {
205 TestIO->WriteVar(varnames[
j], TestVarData.get());
211 TestNlocs = TestIO->nlocs();
212 TestNobs = TestIO->nobs();
213 TestNrecs = TestIO->nrecs();
214 TestNvars = TestIO->nvars();
216 BOOST_CHECK_EQUAL(TestNlocs, Nlocs);
217 BOOST_CHECK_EQUAL(TestNobs, Nobs);
218 BOOST_CHECK_EQUAL(TestNrecs, Nrecs);
219 BOOST_CHECK_EQUAL(TestNvars, Nvars);
222 for(std::size_t
j = 0;
j < varnames.size(); ++
j) {
223 TestIO->ReadVar(varnames[
j], TestVarData.get());
224 for(std::size_t
k = 0;
k < Nlocs; ++
k) {
225 VarSum += int(TestVarData.get()[
k]);
229 BOOST_CHECK_EQUAL(VarSum, ExpectedSum);
239 std::vector<eckit::LocalConfiguration> obstypes;
241 std::string FileName;
242 std::string TestObsType;
243 std::unique_ptr<ioda::IodaIO> TestIO;
245 std::unique_ptr<int[]> TestVarDate;
246 std::unique_ptr<int[]> TestVarTime;
254 conf.get(
"ObsTypes", obstypes);
255 for (std::size_t
i = 0;
i < obstypes.size(); ++
i) {
258 TestObsType = obstypes[
i].getString(
"ObsType");
261 FileName = obstypes[
i].getString(
"Input.filename");
265 Vsize = TestIO->nlocs();
266 TestVarDate.reset(
new int[Vsize]);
267 TestVarTime.reset(
new int[Vsize]);
268 TestIO->ReadDateTime(TestVarDate.get(), TestVarTime.get());
273 for(std::size_t
k = 0;
k < Vsize; ++
k) {
274 Dnorm += pow(
float(TestVarDate.get()[
k]), 2.0);
275 Tnorm += pow(
float(TestVarTime.get()[
k]), 2.0);
280 ExpectedDnorm = obstypes[
i].getFloat(
"Input.datetime.dnorm");
281 ExpectedTnorm = obstypes[
i].getFloat(
"Input.datetime.tnorm");
282 Tol = obstypes[
i].getFloat(
"Input.datetime.tolerance");
284 BOOST_CHECK_CLOSE(Dnorm, ExpectedDnorm, Tol);
285 BOOST_CHECK_CLOSE(Tnorm, ExpectedTnorm, Tol);
296 std::string
testid()
const {
return "test::IodaIO";}
299 boost::unit_test::test_suite * ts = BOOST_TEST_SUITE(
"IodaIO");
306 boost::unit_test::framework::master_test_suite().add(ts);
315 #endif // TEST_INTERFACE_OBSSPACE_H_ l_size ! loop over number of fields ke do je do i
static const eckit::Configuration & config()
l_size ! loop over number of fields ke do j
void register_tests() const
std::string testid() const
static ioda::IodaIO * Create(const std::string &FileName, const std::string &FileMode)
Instantiate a IodaIO object in read mode.