29#include <libdap/BaseType.h>
30#include <libdap/Str.h>
31#include <libdap/Array.h>
32#include <libdap/Grid.h>
33#include <libdap/Error.h>
34#include <libdap/DDS.h>
35#include <libdap/debug.h>
36#include <libdap/util.h>
38#include "GeoGridFunction.h"
39#include "GridGeoConstraint.h"
40#include "gse_parser.h"
41#include "grid_utils.h"
82function_geogrid(
int argc, BaseType *argv[], DDS &, BaseType **btpp)
85 string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") +
86 "<function name=\"geogrid\" version=\"1.2\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#geogrid\">\n"+
90 Str *response =
new Str(
"version");
91 response->set_value(info);
105 if (argc < 1 || !(l_grid =
dynamic_cast < Grid *
>(argv[0]->ptr_duplicate())))
106 throw Error(malformed_expr,
"The first argument to geogrid() must be a Grid variable!");
110 throw Error(malformed_expr,
"Wrong number of arguments to geogrid() (expected at least 5 args). See geogrid() for more information.");
112 bool grid_lat_lon_form;
115 if (!(l_lat =
dynamic_cast < Array *
>(argv[1])))
116 grid_lat_lon_form =
false;
117 else if (!(l_lon =
dynamic_cast < Array *
>(argv[2])))
118 throw Error(malformed_expr,
"When using the Grid, Lat, Lon form of geogrid() both the lat and lon maps must be given (lon map missing)!");
120 grid_lat_lon_form =
true;
122 if (grid_lat_lon_form && argc < 7)
123 throw Error(malformed_expr,
"Wrong number of arguments to geogrid() (expected at least 7 args). See geogrid() for more information.");
126 Grid *l_grid =
dynamic_cast < Grid *
>(argv[0]->ptr_duplicate());
128 throw Error(malformed_expr,
"The first argument to geogrid() must be a Grid variable!");
140 Grid::Map_iter i = l_grid->map_begin();
141 while (i != l_grid->map_end())
142 (*i++)->set_send_p(
true);
148 l_grid->get_array()->set_read_p(
false);
152 int min_arg_count = (grid_lat_lon_form) ? 7 : 5;
153 if (argc > min_arg_count) {
156 vector < GSEClause * > clauses;
157 gse_arg *arg =
new gse_arg(l_grid);
158 for (
int i = min_arg_count; i < argc; ++i) {
159 parse_gse_expression(arg, argv[i]);
160 clauses.push_back(arg->get_gsec());
165 apply_grid_selection_expressions(l_grid, clauses);
171 GridGeoConstraint gc(l_grid);
175 int box_index_offset = (grid_lat_lon_form) ? 3 : 1;
176 double top = extract_double_value(argv[box_index_offset]);
177 double left = extract_double_value(argv[box_index_offset + 1]);
178 double bottom = extract_double_value(argv[box_index_offset + 2]);
179 double right = extract_double_value(argv[box_index_offset + 3]);
180 gc.set_bounding_box(top, left, bottom, right);
181 DBG(cerr <<
"geogrid: past bounding box set" << endl);
184 gc.apply_constraint_to_data();
185 DBG(cerr <<
"geogrid: past apply constraint" << endl);
189 *btpp = gc.get_constrained_grid();
195 catch (exception & e) {
198 (
"A C++ exception was thrown from inside geogrid(): ")
217 get_grids(dds, &grids);
224 vector<Grid *>::iterator git;
225 for(git=grids.begin(); !usable && git!=grids.end() ; git++){
227 usable = is_geo_grid(grid);
bool canOperateOn(libdap::DDS &dds)