IODA Bundle
c_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 
17 using namespace eckit::testing;
18 
19 // Specialise custom deletion for odb_t
20 
21 #define CHECK_RETURN(x) EXPECT((x) == ODC_SUCCESS)
22 
23 namespace std {
24 template <> struct default_delete<odc_reader_t> {
25  void operator() (const odc_reader_t* reader) { CHECK_RETURN(odc_close(reader)); }
26 };
27 
28 template <> struct default_delete<odc_frame_t> {
29  void operator() (const odc_frame_t* frame) { CHECK_RETURN(odc_free_frame(frame)); }
30 };
31 
32 template <> struct default_delete<odc_decoder_t> {
33  void operator() (odc_decoder_t* t) { CHECK_RETURN(odc_free_decoder(t)); }
34 };
35 }
36 
37 // ------------------------------------------------------------------------------------------------------
38 
39 CASE("Count lines in an existing ODB file") {
40 
41  odc_reader_t* reader = nullptr;
42  CHECK_RETURN(odc_open_path(&reader, "../2000010106.odb"));
43  std::unique_ptr<odc_reader_t> reader_deleter(reader);
44 
45  odc_frame_t* frame = nullptr;
46  CHECK_RETURN(odc_new_frame(&frame, reader));
47  std::unique_ptr<odc_frame_t> frame_deleter(frame);
48 
49  size_t ntables = 0;
50  size_t totalRows = 0;
51 
52  int ierr;
53  while ((ierr = odc_next_frame(frame)) == ODC_SUCCESS) {
54 
55  long nrows;
56  CHECK_RETURN(odc_frame_row_count(frame, &nrows));
57  totalRows += nrows;
58 
59  int ncols;
60  CHECK_RETURN(odc_frame_column_count(frame, &ncols));
61  EXPECT(ncols == 51);
62 
63  ++ntables;
64  }
65 
66  EXPECT(ierr == ODC_ITERATION_COMPLETE);
67  EXPECT(ntables == 333);
68  EXPECT(totalRows == 3321753);
69 }
70 
71 // ------------------------------------------------------------------------------------------------------
72 
73 CASE("Decode an entire ODB file") {
74 
75 
76 // std::unique_ptr<odb_t> o(odc_open_path("../2000010106.odb"));
77 //
78 // size_t ntables = 0;
79 //
80 // std::unique_ptr<odb_frame_t> table;
81 // while (table.reset(odc_alloc_next_frame(o.get())), table) {
82 //
83 // std::unique_ptr<const odb_decoded_t> decoded(odc_frame_decode_all(table.get()));
84 // EXPECT(decoded->nrows == odc_frame_row_count(table.get()));
85 // EXPECT(decoded->ncolumns == 51);
86 //
87 // ++ntables;
88 // }
89 }
90 
91 // ------------------------------------------------------------------------------------------------------
92 
93 CASE("Decode an entire ODB file preallocated data structures") {
94 //
95 // std::unique_ptr<odb_t> o(odc_open_path("../2000010106.odb"));
96 //
97 // int ntables = odc_num_frames(o.get());
98 // EXPECT(ntables == 333);
99 //
100 // odb_decoded_t decoded;
101 // odb_strided_data_t strided_data[51];
102 //
103 // for (int i = 0; i < ntables; i++) {
104 //
105 // std::unique_ptr<odb_frame_t> table(odc_get_frame(o.get(), i));
106 //
107 // ASSERT(odc_frame_column_count(table.get()) == 51);
108 //
109 // decoded.ncolumns = 51;
110 // decoded.nrows = 10000;
111 // decoded.columnData = strided_data;
112 //
113 // /// odc_frame_decode(table.get(), &decoded);
114 //
115 // ///EXPECT(decoded.nrows == odc_frame_row_count(table.get()));
116 // ///EXPECT(decoded.ncolumns == 51);
117 //
118 // ///eckit::Log::info() << "Decoded: ncolumns = " << decoded.ncolumns << std::endl;
119 // ///eckit::Log::info() << "Decoded: nrows = " << decoded.nrows << std::endl;
120 // ///eckit::Log::info() << "Decoded: data = " << decoded.columnData << std::endl;
121 // }
122 }
123 
124 // ------------------------------------------------------------------------------------------------------
125 
126 int main(int argc, char* argv[]) {
127  return run_tests(argc, argv);
128 }
int odc_frame_column_count(const odc_frame_t *frame, int *count)
Definition: api/odc.cc:396
int odc_free_frame(const odc_frame_t *frame)
Definition: api/odc.cc:352
int odc_next_frame(odc_frame_t *frame)
Definition: api/odc.cc:359
int odc_open_path(odc_reader_t **reader, const char *filename)
Definition: api/odc.cc:285
int odc_frame_row_count(const odc_frame_t *frame, long *count)
Definition: api/odc.cc:388
int odc_new_frame(odc_frame_t **frame, odc_reader_t *reader)
Definition: api/odc.cc:345
int odc_close(const odc_reader_t *reader)
Definition: api/odc.cc:332
int odc_free_decoder(const odc_decoder_t *decoder)
Definition: api/odc.cc:447
int main(int argc, char *argv[])
Definition: c_api/read.cc:126
#define CHECK_RETURN(x)
Definition: c_api/read.cc:21
CASE("Count lines in an existing ODB file")
Definition: c_api/read.cc:39
Definition: encode.cc:30
@ ODC_ITERATION_COMPLETE
@ ODC_SUCCESS