OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
GridFunction.cc
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003,2013 OPeNDAP, Inc.
8 // Authors: Nathan Potter <npotter@opendap.org>
9 // James Gallagher <jgallagher@opendap.org>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 #include "config.h"
28 
29 #include <BaseType.h>
30 #include <Str.h>
31 #include <Array.h>
32 #include <Grid.h>
33 #include <Error.h>
34 #include <DDS.h>
35 #include <debug.h>
36 #include <util.h>
37 
38 #include "GridFunction.h"
39 #include "gse_parser.h"
40 #include "grid_utils.h"
41 
42 namespace libdap {
43 
80 void
81 function_grid(int argc, BaseType *argv[], DDS &, BaseType **btpp)
82 {
83  DBG(cerr << "Entering function_grid..." << endl);
84 
85  string info =
86  string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") +
87  "<function name=\"grid\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#grid\">\n" +
88  "</function>\n";
89 
90  if (argc == 0) {
91  Str *response = new Str("info");
92  response->set_value(info);
93  *btpp = response;
94  return;
95  }
96 
97  Grid *original_grid = dynamic_cast < Grid * >(argv[0]);
98  if (!original_grid)
99  throw Error(malformed_expr,"The first argument to grid() must be a Grid variable!");
100 
101  // Duplicate the grid; ResponseBuilder::send_data() will delete the variable
102  // after serializing it.
103  BaseType *btp = original_grid->ptr_duplicate();
104  Grid *l_grid = dynamic_cast < Grid * >(btp);
105  if (!l_grid) {
106  delete btp;
107  throw InternalErr(__FILE__, __LINE__, "Expected a Grid.");
108  }
109 
110  DBG(cerr << "grid: past initialization code" << endl);
111 
112  // Read the maps. Do this before calling parse_gse_expression(). Avoid
113  // reading the array until the constraints have been applied because it
114  // might be really large.
115 
116  // This version makes sure to set the send_p flags which is needed for
117  // the hdf4 handler (and is what should be done in general).
118  Grid::Map_iter i = l_grid->map_begin();
119  while (i != l_grid->map_end())
120  (*i++)->set_send_p(true);
121 
122  l_grid->read();
123 
124  DBG(cerr << "grid: past map read" << endl);
125 
126  // argv[1..n] holds strings; each are little expressions to be parsed.
127  // When each expression is parsed, the parser makes a new instance of
128  // GSEClause. GSEClause checks to make sure the named map really exists
129  // in the Grid and that the range of values given makes sense.
130  vector < GSEClause * > clauses;
131  gse_arg *arg = new gse_arg(l_grid);
132  for (int i = 1; i < argc; ++i) {
133  parse_gse_expression(arg, argv[i]);
134  clauses.push_back(arg->get_gsec());
135  }
136  delete arg;
137  arg = 0;
138 
139  apply_grid_selection_expressions(l_grid, clauses);
140 
141  DBG(cerr << "grid: past gse application" << endl);
142 
143  l_grid->get_array()->set_send_p(true);
144 
145  l_grid->read();
146 
147  // Make a new grid here and copy just the parts of the Grid
148  // that are in the current projection - this means reading
149  // the array slicing information, extracting the correct
150  // values and building destination arrays with just those
151  // values.
152 
153  *btpp = l_grid;
154  return;
155 }
156 
163  //vector<Grid *> *grids = new vector<Grid *>();
164  vector<Grid *> grids;
165  getGrids(dds, &grids);
166 
167  return !grids.empty();
168 #if 0
169  bool usable = !grids->empty();
170 
171  delete grids;
172 
173  return usable;
174 #endif
175 }
176 
177 } // namesspace libdap
void getGrids(BaseType *bt, vector< Grid * > *grids)
Recursively traverses the BaseType bt (if its a constructor type) and collects pointers to all of the...
Definition: grid_utils.cc:54
void apply_grid_selection_expressions(Grid *grid, vector< GSEClause * >clauses)
Definition: grid_utils.cc:166
GSEClause * get_gsec()
Definition: gse_parser.h:60
bool canOperateOn(DDS &dds)
The passed DDS parameter dds is evaluated to see if it contains Grid objects.
Argument to the GSE parser.
Definition: gse_parser.h:43
void function_grid(int argc, BaseType *argv[], DDS &, BaseType **btpp)
The grid function uses a set of relational expressions to form a selection within a Grid variable bas...
Definition: GridFunction.cc:81
#define gse_arg(arg)
Definition: gse.tab.cc:121
gse_arg * arg
Definition: gse.tab.cc:714
void parse_gse_expression(gse_arg *arg, BaseType *expr)
Definition: grid_utils.cc:116