41 #include <D4Dimensions.h>
51 string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") +
52 "<function name=\"make_array\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#bind_shape\">\n" +
64 Array *array =
dynamic_cast<Array*
>(btp);
66 throw Error(malformed_expr,
"bind_shape() requires an Array as its second argument.");
68 unsigned long vector_size = array->length();
69 DBG(cerr <<
"bind_shape_worker() - vector_size: " << long_to_string(vector_size) << endl);
72 array->clear_all_dims();
74 unsigned long number_of_elements = 1;
75 vector<int>::iterator i = dims.begin();
76 while (i != dims.end()) {
78 number_of_elements *= dimSize;
80 DBG(cerr <<
"bind_shape_worker() - Adding DAP4 dimension." << endl);
91 D4Dimension *this_dim =
new D4Dimension(
"",dimSize);
92 array->append_dim(this_dim);
96 DBG(cerr <<
"bind_shape_worker() - Adding DAP2 dimension." << endl);
97 array->append_dim(dimSize);
101 DBG(cerr <<
"bind_shape_worker() - number_of_elements: " << long_to_string(number_of_elements) << endl);
103 if (number_of_elements != vector_size)
104 throw Error(malformed_expr,
"bind_shape(): The product of the new dimensions must match the size of the Array's internal storage vector.");
131 Str *response =
new Str(
"info");
132 response->set_value(bind_shape_info);
139 throw Error(malformed_expr,
"bind_shape(shape,variable) requires two arguments.");
141 string shape = extract_string_argument(argv[0]);
143 BaseType *btp = argv[1];
168 if (args == 0 || args->size() == 0) {
169 Str *response =
new Str(
"info");
170 response->set_value(bind_shape_info);
177 DBG(cerr <<
"args.size() = " << args.size() << endl);
178 if (args->size() != 2)
179 throw Error(malformed_expr,
"bind_shape(shape,variable) requires two arguments.");
181 string shape = extract_string_argument(args->get_rvalue(0)->value(dmr));
183 BaseType *btp = args->get_rvalue(1)->value(dmr);
BaseType * function_bind_shape_dap4(D4RValueList *args, DMR &dmr)
Bind a shape to a DAP4 Array that is a vector.
vector< int > parse_dims(const string &shape)
Parse the shape 'expression'.
BaseType * bind_shape_worker(string shape, BaseType *btp)
static class NCMLUtil overview
void function_bind_shape_dap2(int argc, BaseType *argv[], DDS &, BaseType **btpp)
Bind a shape to a DAP2 Array that is a vector.