40#include <libdap/Array.h>
41#include <libdap/Grid.h>
42#include <libdap/D4Maps.h>
43#include <libdap/dods-datatypes.h>
46#include <libdap/debug.h>
48#include "BESInternalError.h"
51#include <libdap/parser.h>
63compare(T elem, relop op,
double value)
68 case dods_greater_equal_op:
72 case dods_less_equal_op:
76 case dods_not_equal_op:
79 throw Error(malformed_expr,
"Attempt to use NOP in Grid selection.");
81 throw Error(malformed_expr,
"Unknown relational operator in Grid selection.");
88GSEClause::set_map_min_max_value(T min, T max)
90 DBG(cerr <<
"Inside set map min max value " << min <<
", " << max << endl);
91 std::ostringstream oss1;
93 d_map_min_value = oss1.str();
95 std::ostringstream oss2;
97 d_map_max_value = oss2.str();
107GSEClause::set_start_stop()
109 vector<T> vals(d_map->length());
110 d_map->value(vals.data());
112 if (!((
unsigned long)d_start < vals.size() && (
unsigned long)d_stop < vals.size()))
113 throw BESInternalError(
"Access beyond the bounds of a Grid Map.", __FILE__, __LINE__);
117 set_map_min_max_value<T>(vals[d_start], vals[d_stop]);
126 while (i <= end && !compare<T>(vals[i], d_op1, d_value1))
133 while (i >= 0 && !compare<T>(vals[i], d_op1, d_value1))
141 if (d_op2 != dods_nop_op) {
144 while (i <= end && !compare<T>(vals[i], d_op2, d_value2))
150 while (i >= 0 && !compare<T>(vals[i], d_op2, d_value2))
158GSEClause::compute_indices()
160 switch (d_map->var()->type()) {
162 set_start_stop<dods_byte>();
165 set_start_stop<dods_int16>();
168 set_start_stop<dods_uint16>();
171 set_start_stop<dods_int32>();
174 set_start_stop<dods_uint32>();
177 set_start_stop<dods_float32>();
180 set_start_stop<dods_float64>();
183 throw Error(malformed_expr,
184 "Grid selection using non-numeric map vectors is not supported");
192GSEClause::GSEClause(Grid *grid,
const string &map,
const double value,
195 d_value1(value), d_value2(0), d_op1(op), d_op2(dods_nop_op),
196 d_map_min_value(
""), d_map_max_value(
"")
198 d_map =
dynamic_cast<Array *
>(grid->var(map));
200 throw Error(
string(
"The map variable '") + map
201 +
string(
"' does not exist in the grid '")
202 + grid->name() +
string(
"'."));
204 DBG(cerr << d_map->toString());
207 Array::Dim_iter iter = d_map->dim_begin();
208 d_start = d_map->dimension_start(iter);
209 d_stop = d_map->dimension_stop(iter);
215GSEClause::GSEClause(Grid *grid,
const string &map,
const double value1,
216 const relop op1,
const double value2,
const relop op2)
218 d_value1(value1), d_value2(value2), d_op1(op1), d_op2(op2),
219 d_map_min_value(
""), d_map_max_value(
"")
221 d_map =
dynamic_cast<Array *
>(grid->var(map));
223 throw Error(
string(
"The map variable '") + map
224 +
string(
"' does not exist in the grid '")
225 + grid->name() +
string(
"'."));
227 DBG(cerr << d_map->toString());
230 Array::Dim_iter iter = d_map->dim_begin();
231 d_start = d_map->dimension_start(iter);
232 d_stop = d_map->dimension_stop(iter);
238GSEClause::GSEClause(Array *coverage,
const string &map,
const double value,
const relop op)
240 d_value1(value), d_value2(0), d_op1(op), d_op2(dods_nop_op),
241 d_map_min_value(
""), d_map_max_value(
"")
243 if (!coverage->is_dap2_grid())
244 throw Error(
string(
"The grid function cannot be applied to the array variable '")
245 + coverage->name() +
string(
"'."));
248 bool mapFound =
false;
249 D4Maps *d4_maps = coverage->maps();
250 D4Maps::D4MapsIter miter = d4_maps->map_begin();
251 D4Maps::D4MapsIter end = d4_maps->map_end();
252 for (; miter != end; miter++) {
253 D4Map *d4_map = (*miter);
254 if (d4_map->name() == map) {
256 d_map =
const_cast<Array *
>(d4_map->array());
262 throw Error(
string(
"The map variable '") + map
263 +
string(
"' does not exist in the array '")
264 + coverage->name() +
string(
"'."));
266 DBG(cerr << d_map->toString());
269 Array::Dim_iter iter = d_map->dim_begin();
270 d_start = d_map->dimension_start(iter);
271 d_stop = d_map->dimension_stop(iter);
278GSEClause::GSEClause(Array *coverage,
const string &map,
const double value1,
279 const relop op1,
const double value2,
const relop op2)
281 d_value1(value1), d_value2(value2), d_op1(op1), d_op2(op2),
282 d_map_min_value(
""), d_map_max_value(
"")
285 if (!coverage->is_dap2_grid())
286 throw Error(
string(
"The grid function cannot be applied to the array variable '")
287 + coverage->name() +
string(
"'."));
290 bool mapFound =
false;
291 D4Maps *d4_maps = coverage->maps();
292 D4Maps::D4MapsIter miter = d4_maps->map_begin();
293 D4Maps::D4MapsIter end = d4_maps->map_end();
294 for (; miter != end; miter++) {
295 D4Map *d4_map = (*miter);
296 if (d4_map->name() == map) {
298 d_map =
const_cast<Array *
>(d4_map->array());
304 throw Error(
string(
"The map variable '") + map
305 +
string(
"' does not exist in the array '")
306 + coverage->name() +
string(
"'."));
308 DBG(cerr << d_map->toString());
311 Array::Dim_iter iter = d_map->dim_begin();
312 d_start = d_map->dimension_start(iter);
313 d_stop = d_map->dimension_stop(iter);
318GSEClause::~GSEClause()
359 return d_map->name();
385 DBG(cerr <<
"Returning stop index value of: " << d_stop << endl);
404 return d_map_min_value;
414 return d_map_max_value;
string get_map_name() const
Get the name of the map variable constrained by this clause.
libdap::Array * get_map() const
Get a pointer to the map variable constrained by this clause.
void set_stop(int stop)
Set the stopping index.
int get_stop() const
Get the stopping index of the clause's map variable as constrained by this clause.
void set_start(int start)
Set the starting index.
string get_map_max_value() const
Get the maximum map vector value.
int get_start() const
Get the starting index of the clause's map variable as constrained by this clause.
string get_map_min_value() const
Get the minimum map vector value.
void set_map(libdap::Array *map)
Set the pointer to the map vector contrained by this clause.