IODA Bundle
Examples.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
/// This file contains examples of usage of public APIs.
12
13
#include <string>
14
#include <iostream>
15
#include <vector>
16
17
#include "eckit/filesystem/PathName.h"
18
#include "eckit/io/FileHandle.h"
19
20
#include "
odc/api/Odb.h
"
21
22
#include "
odc/Select.h
"
23
#include "
odc/Reader.h
"
24
#include "
odc/Writer.h
"
25
26
#include "
TestCase.h
"
27
28
using namespace
eckit
;
29
30
namespace
{
31
32
TEST
(example_select_data_read_results)
33
{
34
// Prepare input data
35
const
std::string data =
36
R
"(x:INTEGER,y:INTEGER,v:DOUBLE
37
1,1,0.3
38
1,1,0.2
39
2,2,0.4
40
2,2,0.1)";
41
42
FileHandle out(
"example_select_data_read_results.odb"
);
43
out.openForWrite(0);
44
AutoClose close(out);
45
odc::api::odbFromCSV
(data, out);
46
47
odc::Select
select(
"select x,min(v),max(v);"
,
"example_select_data_read_results.odb"
);
48
49
for
(
odc::Select::iterator
it (select.
begin
()),
50
end (select.
end
());
51
it != end;
52
++it)
53
{
54
double
r0 = (*it)[0],
55
r1 = (*it)[1],
56
r2 = (*it)[2];
57
58
std::cout << r0 <<
", "
<< r1 <<
", "
<< r2 << std::endl;
59
}
60
}
61
62
63
TEST
(example_read_data)
64
{
65
// Prepare input data
66
const
std::string data =
"x:INTEGER,y:INTEGER,v:DOUBLE\n"
"1,1,0.3\n"
"1,1,0.2\n"
"2,2,0.4\n"
"2,2,0.1\n"
;
67
FileHandle out(
"example_read_data.odb"
);
68
out.openForWrite(0);
69
AutoClose close(out);
70
odc::api::odbFromCSV
(data, out);
71
72
odc::Reader
o(
"example_read_data.odb"
);
73
for
(
odc::Reader::iterator
it (o.
begin
()),
74
end (o.
end
());
75
it != end;
76
++it)
77
{
78
double
r0 = (*it)[0],
79
r1 = (*it)[1],
80
r2 = (*it)[2];
81
82
std::cout << r0 <<
", "
<< r1 <<
", "
<< r2 << std::endl;
83
}
84
}
85
86
TEST
(example_write_data)
87
{
88
odc::core::MetaData
metaData;
89
metaData
90
.
addColumn
(
"x"
,
"INTEGER"
)
91
.
addColumn
(
"y"
,
"INTEGER"
)
92
.
addColumn
(
"v"
,
"DOUBLE"
);
93
94
odc::Writer<>
writer
(
"example_write_data.odb"
);
95
odc::Writer<>::iterator
it (
writer
.begin());
96
it->
columns
(metaData);
97
it->
writeHeader
();
98
99
for
(
size_t
i
(1);
i
<= 1000; ++
i
)
100
{
101
(*it)[0] =
i
;
102
(*it)[1] =
i
*2;
103
(*it)[2] =
i
*3;
104
105
// Incrementing iterator moves coursor to the next row.
106
++it;
107
}
108
}
109
110
}
// namespace
111
Odb.h
Reader.h
Select.h
TestCase.h
Writer.h
odc::IteratorProxy< SelectIterator, Select, const double >
odc::Reader
Definition:
Reader.h:32
odc::Reader::end
const iterator end() const
Definition:
Reader.cc:81
odc::Reader::begin
iterator begin()
Definition:
Reader.cc:74
odc::Row_::writeHeader
void writeHeader()
Definition:
IteratorProxy.h:109
odc::Row_::columns
const core::MetaData & columns() const
Definition:
IteratorProxy.h:94
odc::Select
Definition:
Select.h:34
odc::Select::end
const iterator end()
Definition:
Select.cc:77
odc::Select::begin
iterator begin()
Definition:
Select.cc:81
odc::Writer
Definition:
Writer.h:31
odc::core::MetaData
Definition:
MetaData.h:31
odc::core::MetaData::addColumn
MetaData & addColumn(const std::string &name, const std::string &type)
Definition:
MetaData.cc:279
airnow2ioda-nc.writer
writer
Definition:
airnow2ioda-nc.py:123
anonymous_namespace{Examples.cc}::TEST
TEST(example_write_data)
Definition:
Examples.cc:82
eckit
Definition:
DistributionUtils.h:15
odc::api::odbFromCSV
size_t odbFromCSV(DataHandle &dh_in, DataHandle &dh_out, const std::string &delimiter)
odbFromCSV returns number of lines imported
Definition:
Odb.cc:375
proc_gsi_ncdiag.i
i
Definition:
proc_gsi_ncdiag.py:155
odc
src
odc
tools
Examples.cc
Generated on Fri Aug 20 2021 11:49:04 for IODA Bundle by
1.9.1