IODA Bundle
test_box_functions.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 "eckit/testing/Test.h"
12 #include "eckit/types/FloatCompare.h"
13 
14 #include "odc/Writer.h"
15 #include "odc/Select.h"
16 
17 #include "TemporaryFiles.h"
18 
19 #include <iomanip>
20 
21 using namespace eckit::testing;
22 using eckit::types::is_approximately_equal;
23 
24 // ------------------------------------------------------------------------------------------------------
25 
26 CASE("EQ_BOXLAT and EQ_BOXLON") {
27 
29 
30  // Write some data with a latitude and longitude.
31 
32  {
33  odc::Writer<> oda(f.path());
34  odc::Writer<>::iterator row = oda.begin();
35 
36  row->setNumberOfColumns(2);
37 
38  row->setColumn(0, "lat", odc::api::REAL);
39  row->setColumn(1, "lon", odc::api::REAL);
40 
41  row->writeHeader();
42 
43  // Include some extreme values
44 
45  (*row)[0] = 45.0;
46  (*row)[1] = 0.0;
47  ++row;
48 
49  (*row)[0] = 90.0;
50  (*row)[1] = 180.0;
51  ++row;
52 
53  (*row)[0] = -90.0;
54  (*row)[1] = 360.0;
55  ++row;
56 
57  (*row)[0] = -45.0;
58  (*row)[1] = -90.0;
59  ++row;
60  }
61 
62  // And test that the SQL functions get the right data out!!!
63 
64  const std::string sql = std::string("select eq_boxlat(lat,lon,10.5), eq_boxlon(lat,lon,10.5) ") +
65  "from \"" + f.path() + "\";";
66 
67  const double eps = 7.e-6;
68 
69  {
70  odc::Select oda(sql);
71  odc::Select::iterator it = oda.begin();
72 
73  EXPECT(is_approximately_equal((*it)[0], 47.134066345052e0, eps));
74  EXPECT((*it)[1] == 0);
75 
76  ++it;
77 
78  EXPECT(is_approximately_equal((*it)[0], 87.03598391, eps));
79  EXPECT((*it)[1] == 0);
80 
81  ++it;
82 
83  EXPECT(is_approximately_equal((*it)[0], -87.03598391, eps));
84  EXPECT((*it)[1] == 0);
85 
86  ++it;
87 
88  EXPECT(is_approximately_equal((*it)[0], -47.13406635, eps));
89  EXPECT(is_approximately_equal((*it)[1], -93.91304348, eps));
90 
91  ++it;
92 
93  EXPECT(it == oda.end());
94  }
95 }
96 
97 CASE("RGG_BOXLAT and RGG_BOXLON") {
98 
100 
101  // Write some data with a latitude and longitude.
102 
103  {
104  odc::Writer<> oda(f.path());
105  odc::Writer<>::iterator row = oda.begin();
106 
107  row->setNumberOfColumns(2);
108 
109  row->setColumn(0, "lat", odc::api::REAL);
110  row->setColumn(1, "lon", odc::api::REAL);
111 
112  row->writeHeader();
113 
114  // Include some extreme values
115 
116  (*row)[0] = 45.0;
117  (*row)[1] = 0.0;
118  ++row;
119 
120  (*row)[0] = 90.0;
121  (*row)[1] = 180.0;
122  ++row;
123 
124  (*row)[0] = -90.0;
125  (*row)[1] = 360.0;
126  ++row;
127 
128  (*row)[0] = -45.0;
129  (*row)[1] = -90.0;
130  ++row;
131  }
132 
133  // And test that the SQL functions get the right data out!!!
134 
135  const std::string sql = std::string("select rgg_boxlat(lat,lon,31), rgg_boxlon(lat,lon,31) ") +
136  "from \"" + f.path() + "\";";
137 
138  const double eps = 7.e-6;
139 
140  {
141  odc::Select oda(sql);
142  odc::Select::iterator it = oda.begin();
143 
144  EXPECT(is_approximately_equal((*it)[0], 47.06964206, eps));
145  EXPECT((*it)[1] == 0);
146 
147  ++it;
148 
149  EXPECT(is_approximately_equal((*it)[0], 85.76058712, eps));
150  EXPECT((*it)[1] == 180);
151 
152  ++it;
153 
154  EXPECT(is_approximately_equal((*it)[0], -85.76058712, eps));
155  EXPECT((*it)[1] == 0);
156 
157  ++it;
158 
159  EXPECT(is_approximately_equal((*it)[0], -47.06964206, eps));
160  EXPECT((*it)[1] == -90);
161 
162  ++it;
163 
164  EXPECT(it == oda.end());
165  }
166 }
167 
168 // ------------------------------------------------------------------------------------------------------
169 
170 int main(int argc, char* argv[]) {
171  return run_tests(argc, argv);
172 }
void oda
void writeHeader()
void setNumberOfColumns(size_t n)
Definition: IteratorProxy.h:95
int setColumn(size_t index, const std::string &name, api::ColumnType type)
int main(int argc, char *argv[])
CASE("EQ_BOXLAT and EQ_BOXLON")