28 #include <Structure.h>
34 #include "grid_utils.h"
35 #include "gse_parser.h"
36 #include "GSEClause.h"
37 #include "GridGeoConstraint.h"
42 void gse_restart(FILE * in);
45 void gse_delete_buffer(
void *buffer);
46 void *gse_string(
const char *yy_str);
56 void get_grids(BaseType *bt, vector<Grid *> *grids)
62 grids->push_back(
static_cast<Grid*
>(bt));
65 case dods_structure_c: {
67 Structure &s =
static_cast<Structure&
>(*bt);
68 for (Structure::Vars_iter i = s.var_begin(); i != s.var_begin(); i++) {
87 void get_grids(DDS &dds, vector<Grid *> *grids)
89 for (DDS::Vars_iter i = dds.var_begin(); i != dds.var_end(); i++) {
103 bool is_geo_grid(Grid *grid)
106 GridGeoConstraint gc(grid);
115 void parse_gse_expression(gse_arg *arg, BaseType *expr)
118 void *cls = gse_string(extract_string_argument(expr).c_str());
120 bool status = gse_parse(arg) == 0;
121 gse_delete_buffer(cls);
123 throw Error(malformed_expr,
"Error parsing grid selection.");
126 static void apply_grid_selection_expr(Grid *grid, GSEClause *clause)
130 Grid::Map_iter map_i = grid->map_begin();
131 while (map_i != grid->map_end() && (*map_i)->name() != clause->get_map_name())
134 if (map_i == grid->map_end())
135 throw Error(malformed_expr,
"The map vector '" + clause->get_map_name()
136 +
"' is not in the grid '" + grid->name() +
"'.");
139 Array::Dim_iter grid_dim = (grid->get_array()->dim_begin() + (map_i - grid->map_begin()));
141 Array *map =
dynamic_cast < Array *
>((*map_i));
143 throw InternalErr(__FILE__, __LINE__,
"Expected an Array");
144 int start = max(map->dimension_start(map->dim_begin()), clause->get_start());
145 int stop = min(map->dimension_stop(map->dim_begin()), clause->get_stop());
150 <<
"The expressions passed to grid() do not result in an inclusive \n"
151 <<
"subset of '" << clause->get_map_name()
152 <<
"'. The map's values range " <<
"from "
153 << clause->get_map_min_value() <<
" to "
154 << clause->get_map_max_value() <<
".";
155 throw Error(malformed_expr,msg.str());
158 BESDEBUG(
"GeoGrid",
"Setting constraint on " << map->name() <<
"[" << start <<
":" << stop <<
"]" << endl);
161 map->add_constraint(map->dim_begin(), start, 1, stop);
162 grid->get_array()->add_constraint(grid_dim, start, 1, stop);
165 void apply_grid_selection_expressions(Grid * grid, vector < GSEClause * >clauses)
167 vector < GSEClause * >::iterator clause_i = clauses.begin();
168 while (clause_i != clauses.end())
169 apply_grid_selection_expr(grid, *clause_i++);
171 grid->set_read_p(
false);