33#include <libdap/BaseType.h>
34#include <libdap/Array.h>
35#include <libdap/Grid.h>
36#include <libdap/Str.h>
37#include <libdap/Error.h>
38#include <libdap/util.h>
42#include "functions_util.h"
43#include "GridGeoConstraint.h"
45#define DEBUG_KEY "geo"
65void function_scale_grid(
int argc, BaseType *argv[], DDS &, BaseType **btpp)
69 string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") +
70 "<function name=\"scale_grid\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_grid\">\n" +
74 unique_ptr<Str> response(
new Str(
"info"));
75 response->set_value(info);
76 *btpp = response.release();
80 if (argc < 3 || argc > 5) {
81 throw Error(
"The scale_grid() function requires three arguments: a Grid and the new lon, lat extents (got " + long_to_string(argc) +
" args).\n\
82 See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_grid");
85 Grid *src =
dynamic_cast < Grid *
>(argv[0]);
87 throw Error(malformed_expr,
"The first argument to scale_grid() must be a Grid variable!");
90 if(!gc.is_longitude_rightmost()){
91 throw Error(malformed_expr,
"The last argument to scale_grid() must be a longitude variable!");
94 BESDEBUG(DEBUG_KEY,
"function_scale_grid() - Evaluating grid '"<< src->name() <<
"'" << endl);
95 unsigned long y = extract_uint_value(argv[1]);
96 unsigned long x = extract_uint_value(argv[2]);
99 string interp =
"nearest";
101 crs = extract_string_argument(argv[3]);
104 interp = extract_string_argument(argv[4]);
107 BESDEBUG(DEBUG_KEY,
"function_scale_grid() - CRS '"<< crs <<
"'" << endl);
108 BESDEBUG(DEBUG_KEY,
"function_scale_grid() - Interpolation Method '"<< interp <<
"'" << endl);
111 *btpp = scale_dap_grid(src, size, crs, interp);
130void function_scale_array(
int argc, BaseType *argv[], DDS &, BaseType **btpp)
134 string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") +
135 "<function name=\"scale_array\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_array\">\n" +
139 unique_ptr<Str> response(
new Str(
"info"));
140 response->set_value(info);
141 *btpp = response.release();
145 if (!(argc > 4 && argc < 8)) {
146 throw Error(
"The scale_array() function requires five arguments: three Arrays and the new lat and lon extents.\n\
147 See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_array");
150 Array *data =
dynamic_cast <Array *
>(argv[0]);
152 throw Error(malformed_expr,
"The first argument to scale_array() must be an Array variable!");
153 Array *x =
dynamic_cast <Array *
>(argv[2]);
155 throw Error(malformed_expr,
"The second argument to scale_array() must be an Array variable!");
156 Array *y =
dynamic_cast <Array *
>(argv[1]);
158 throw Error(malformed_expr,
"The third argument to scale_array() must be an Array variable!");
160 unsigned long new_x = extract_uint_value(argv[4]);
161 unsigned long new_y = extract_uint_value(argv[3]);
163 string crs =
"WGS84";
164 string interp =
"nearest";
166 crs = extract_string_argument(argv[5]);
170 interp = extract_string_argument(argv[6]);
174 *btpp = scale_dap_array(data, x, y, size, crs, interp);
193void function_scale_array_3D(
int argc, BaseType *argv[], DDS &, BaseType **btpp)
197 string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
198 +
"<function name=\"scale_array\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_3D_array\">\n"
201 BESDEBUG(DEBUG_KEY,
"function_scale_array_3D() - argc = " << argc << endl);
204 unique_ptr<Str> response(
new Str(
"info"));
205 response->set_value(info);
206 *btpp = response.release();
210 if (!(argc > 5 && argc < 9)) {
212 "The scale_array_3D() function requires six arguments: four Arrays and the new lat and lon extents.\n\
213 See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_array");
216 BESDEBUG(DEBUG_KEY,
"function_scale_array_3D() - arg[0] name: " << argv[0]->name() << endl);
218 Array *data =
dynamic_cast<Array *
>(argv[0]);
219 if (!data)
throw Error(malformed_expr,
"The first argument to scale_array_3D() must be an Array variable!");
220 Array *t =
dynamic_cast<Array *
>(argv[1]);
221 if (!t)
throw Error(malformed_expr,
"The second argument to scale_array_3D() must be an Array variable!");
222 Array *y =
dynamic_cast<Array *
>(argv[2]);
223 if (!y)
throw Error(malformed_expr,
"The third argument to scale_array_3D() must be an Array variable!");
224 Array *x =
dynamic_cast<Array *
>(argv[3]);
225 if (!x)
throw Error(malformed_expr,
"The fourth argument to scale_array_3D() must be an Array variable!");
227 unsigned long new_x = extract_uint_value(argv[5]);
228 unsigned long new_y = extract_uint_value(argv[4]);
230 string crs =
"WGS84";
231 string interp =
"nearest";
233 crs = extract_string_argument(argv[6]);
237 interp = extract_string_argument(argv[7]);
241 *btpp = scale_dap_array_3D(data, t, x, y, size, crs, interp);