IODA Bundle
import.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 #include "eckit/io/MemoryHandle.h"
15 
16 #include "odc/api/Odb.h"
17 
18 using namespace eckit::testing;
19 
20 // ------------------------------------------------------------------------------------------------------
21 
22 CASE("We can import data") {
23 
24  const char* SOURCE_DATA =
25  R"(col1:INTEGER,col2:REAL,col3:DOUBLE,col4:INTEGER,col5:BITFIELD[a:1;b:2;c:5]
26  1,1.23,4.56,7,999
27  123,0.0,0.0,321,888
28  321,0.0,0.0,123,777
29  0,3.25,0.0,0,666
30  0,0.0,3.25,0,555)";
31 
32  eckit::MemoryHandle dh_out;
33  size_t importedSize;
34 
35  {
36  dh_out.openForWrite(0);
37  eckit::AutoClose close(dh_out);
38  ::odc::api::odbFromCSV(SOURCE_DATA, dh_out);
39  importedSize = dh_out.position();
40  }
41 
42  eckit::Log::info() << "Imported length: " << importedSize << std::endl;
43 
44  eckit::MemoryHandle readAgain(dh_out.data(), importedSize);
45  readAgain.openForRead();
46  odc::api::Reader r(readAgain);
47 
48  odc::api::Frame f(r);
49  while (f.next(false)) {
50  eckit::Log::info() << "Frame: " << f.rowCount() << std::endl;
51  }
52 
53 
54 
55 }
56 
57 // ------------------------------------------------------------------------------------------------------
58 
59 int main(int argc, char* argv[]) {
60  return run_tests(argc, argv);
61 }
int main(int argc, char *argv[])
Definition: import.cc:54
CASE("We can import data")
Definition: import.cc:22
size_t odbFromCSV(DataHandle &dh_in, DataHandle &dh_out, const std::string &delimiter)
odbFromCSV returns number of lines imported
Definition: Odb.cc:375