bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BBoxCombFunction.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of bes, A C++ implementation of the OPeNDAP
4// Hyrax data server
5
6// Copyright (c) 2015 OPeNDAP, Inc.
7// Authors: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <cassert>
28#include <sstream>
29#include <memory>
30
31#include <libdap/BaseType.h>
32#include <libdap/Int32.h>
33#include <libdap/Str.h>
34#include <libdap/Array.h>
35#include <libdap/Structure.h>
36
37#include <libdap/D4RValue.h>
38#include <libdap/Error.h>
39#include <libdap/debug.h>
40#include <libdap/util.h>
41#include <libdap/ServerFunctionsList.h>
42
43#include "BBoxCombFunction.h"
44#include "roi_util.h"
45
46using namespace std;
47using namespace libdap;
48
49namespace functions {
50
64
65void
66function_dap2_bbox_comb(int argc, BaseType *argv[], DDS &, BaseType **btpp)
67{
68 const string wrong_args = "Wrong number of arguments to bbox_comb(). Expected two bounding boxes";
69
70 unsigned int rank = 0;
71 unsigned int rnk1= 0;
72 unsigned int rnk2 = 0;
73
74 switch (argc) {
75 case 2:
76 // Rank should be sum of ranks of arguments because names all different,
77 rnk1 = roi_valid_bbox(argv[0]);
78 rnk2 = roi_valid_bbox(argv[1]);
79 break;
80
81 default:
82 throw Error(malformed_expr, wrong_args);
83 break;
84 }
85
86 // Define rank for output result
87 rank = rnk1 + rnk2;
88
89 // Initialize a local data structure - used because it's much
90 // easier to read and write this than the DAP variables.
91 vector<slice> combo(rank); // struct slice is defined in roi_utils.h
92
93 //first arg
94 for (unsigned int i = 0; i < rnk1; ++i) {
95 int start, stop;
96 string name;
97 // start, stop, name are value-result parameters; we know they are Array*
98 // because of the roi_valid_bbox() test.
99 roi_bbox_get_slice_data(static_cast<Array*>(argv[0]), i, start, stop, name);
100
101 combo.at(i).start = start;
102 combo.at(i).stop = stop;
103 combo.at(i).name = name;
104 }
105 //second arg
106 for (unsigned int j = 0; j < rnk2; ++j) {
107 int start, stop;
108 string name;
109 // start, stop, name are value-result parameters; we know they are Array*
110 // because of the roi_valid_bbox() test.
111 roi_bbox_get_slice_data(static_cast<Array*>(argv[1]), j, start, stop, name);
112 if(combo.at(j).name != name){
113 combo.at(rnk1+j).start = start;
114 combo.at(rnk1+j).stop = stop;
115 combo.at(rnk1+j).name = name;
116 }
117 }
118
119 // Build the response; name the result after the operation
120 unique_ptr<Array> response = roi_bbox_build_empty_bbox(rank);
121 for (unsigned int k = 0; k < rank; ++k) {
122 Structure *slice = roi_bbox_build_slice(combo.at(k).start, combo.at(k).stop, combo.at(k).name);
123 response->set_vec_nocopy(k, slice);
124 }
125 // Return the result
126 *btpp = response.release();
127 return;
128}
129
130} /* namespace functions */