IODA Bundle
api/read.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <memory>
12 
13 #include "eckit/testing/Test.h"
14 
15 #include "odc/api/odc.h"
16 #include "odc/api/Odb.h"
17 
18 using namespace eckit::testing;
19 
20 // ------------------------------------------------------------------------------------------------------
21 
22 CASE("Count lines in an existing ODB file") {
23 
24  odc::api::Reader o("../2000010106.odb");
25 
26  size_t nframes = 0;
27  size_t totalRows = 0;
28 
29  odc::api::Frame frame(o);
30 
31  while (frame.next(false)) {
32  totalRows += frame.rowCount();
33  EXPECT(frame.columnCount() == 51);
34  ++nframes;
35  }
36 
37  EXPECT(nframes == 333);
38  EXPECT(totalRows == 3321753);
39 }
40 
41 // ------------------------------------------------------------------------------------------------------
42 
43 //CASE("Decode an entire ODB file") {
44 //
45 // odc::api::Odb o("../2000010106.odb");
46 //
47 // size_t ntables = 0;
48 //
49 // while (const auto& table = o.next()) {
50 //
51 // DecodeTarget decoded;
52 // table.get().decode();
53 //
54 // EXPECT(decoded.rows() == table.get().rowCount());
55 // EXPECT(decoded.columns() == 51);
56 //
57 // ++ntables;
58 // }
59 //}
60 //
61 //// ------------------------------------------------------------------------------------------------------
62 //
63 //CASE("Decode only some columns") {
64 //
65 // odc::api::Odb o("../2000010106.odb");
66 //
67 // size_t ntables = 0;
68 //
69 // while (const auto& table = o.next()) {
70 //
71 // DecodeTarget decoded;
72 // decoded.addColumn("statid");
73 // decoded.addColumn("expver");
74 // decoded.addColumn("andate");
75 // decoded.addColumn("obsvalue");
76 //
77 // DecodeTarget decoded = table.get().decode();
78 //
79 // EXPECT(decoded.rows() == table.get().rowCount());
80 // EXPECT(decoded.columns() == 51);
81 //
82 // ++ntables;
83 // }
84 //}
85 // ------------------------------------------------------------------------------------------------------
86 
87 CASE("Decode an entire ODB file preallocated data structures") {
88 //
89 // std::unique_ptr<odb_t> o(odc_open_for_read("../2000010106.odb"));
90 //
91 // int ntables = odc_num_tables(o.get());
92 // EXPECT(ntables == 333);
93 //
94 // odb_decoded_t decoded;
95 // odb_strided_data_t strided_data[51];
96 //
97 // for (int i = 0; i < ntables; i++) {
98 //
99 // std::unique_ptr<odb_table_t> table(odc_get_table(o.get(), i));
100 //
101 // ASSERT(odc_table_num_columns(table.get()) == 51);
102 //
103 // decoded.ncolumns = 51;
104 // decoded.nrows = 10000;
105 // decoded.columnData = strided_data;
106 //
107 // /// odc_table_decode(table.get(), &decoded);
108 //
109 // ///EXPECT(decoded.nrows == odc_table_num_rows(table.get()));
110 // ///EXPECT(decoded.ncolumns == 51);
111 //
112 // ///eckit::Log::info() << "Decoded: ncolumns = " << decoded.ncolumns << std::endl;
113 // ///eckit::Log::info() << "Decoded: nrows = " << decoded.nrows << std::endl;
114 // ///eckit::Log::info() << "Decoded: data = " << decoded.columnData << std::endl;
115 // }
116 }
117 
118 // ------------------------------------------------------------------------------------------------------
119 
120 int main(int argc, char* argv[]) {
121  return run_tests(argc, argv);
122 }
int main(int argc, char *argv[])
Definition: api/read.cc:120
CASE("Count lines in an existing ODB file")
Definition: api/read.cc:22
bool next(bool aggregated=true, long rowlimit=-1)
Definition: Odb.cc:311
size_t rowCount() const
Definition: Odb.cc:316
size_t columnCount() const
Definition: Odb.cc:321