OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
ugrid_utils.h
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2002,2003,2011,2012 OPeNDAP, Inc.
7 // Authors: Nathan Potter <ndp@opendap.org>
8 // James Gallagher <jgallagher@opendap.org>
9 // Scott Moe <smeest1@gmail.com>
10 // Bill Howe <billhowe@cs.washington.edu>
11 //
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 //
26 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27 
28 #ifndef _UgridUtilities_h
29 #define _UgridUtilities_h 1
30 
31 #include <gridfields/array.h>
32 
33 using namespace std;
34 using namespace libdap;
35 
36 namespace {
37  class Array;
38 }
39 
40 namespace ugrid {
41 
45 #define CF_ROLE "cf_role"
46 #define CF_STANDARD_NAME "standard_name"
47 #define UGRID_MESH_TOPOLOGY "mesh_topology"
48 #define UGRID_NODE_COORDINATES "node_coordinates"
49 #define UGRID_FACE_NODE_CONNECTIVITY "face_node_connectivity"
50 
51 #define UGRID_TOPOLOGY_DIMENSION "topology_dimension"
52 #define UGRID_LOCATION "location"
53 #define UGRID_GRID_LOCATION "grid_location"
54 #define UGRID_NODE "node"
55 #define UGRID_EDGE "edge"
56 #define UGRID_FACE "face"
57 #define UGRID_MESH "mesh"
58 #define UGRID_START_INDEX "start_index"
59 
63 #define UGRID_EDGE_NODE_CONNECTIVITY "edge_node_connectivity"
64 
65 
66 #define UGRID_FACE_COORDINATES "face_coordinates"
67 #define UGRID_EDGE_COORDINATES "edge_coordinates"
68 #define UGRID_FACE_EDGE_CONNECTIVITY "face_edge_connectivity"
69 #define UGRID_FACE_FACE_CONNECTIVITY "face_face_connectivity"
70 
71 GF::Array *extractGridFieldArray(libdap::Array *a, vector<int*> *sharedIntArrays, vector<float*> *sharedFloatArrays);
72 GF::Array *newGFIndexArray(string name, long size, vector<int*> *sharedIntArrays);
73 
77 template<typename DODS, typename T>T *extract_array_helper(libdap::Array *a) {
78  int length = a->length();
79 
80  DODS *src = new DODS[length];
81 
82  a->value(src);
83 
84  T *dest = new T[length];
85 
86  for (int i = 0; i < length; ++i)
87  dest[i] = (T) src[i];
88 
89  delete [] src;
90 
91  return dest;
92 }
93 
98 template<typename T> T *extractArray(libdap::Array *a) {
99 
100  // Simple types are Byte, ..., Float64, String and Url.
101  if ((a->type() == dods_array_c && !a->var()->is_simple_type())
102  || a->var()->type() == dods_str_c || a->var()->type() == dods_url_c)
103  throw Error(malformed_expr,
104  "The function requires a DAP numeric-type array argument.");
105 
106  a->set_send_p(true);
107  a->read();
108  // This test should never pass due to the previous two lines;
109  // reading here seems to make
110  // sense rather than letting the caller forget to do so.
111  // is read() idemopotent?
112  if (!a->read_p())
113  throw InternalErr(__FILE__, __LINE__,
114  string("The Array '") + a->name()
115  + "'does not contain values. send_read_p() not called?");
116 
117 
118 
119  // The types of arguments that the CE Parser will build for numeric
120  // constants are limited to Uint32, Int32 and Float64. See ce_expr.y.
121  // Expanded to work for any numeric type so it can be used for more than
122  // just arguments.
123  switch (a->var()->type()) {
124  case dods_byte_c:
125  return extract_array_helper<dods_byte, T>(a);
126 
127  case dods_uint16_c:
128  return extract_array_helper<dods_uint16, T>(a);
129 
130  case dods_int16_c:
131  return extract_array_helper<dods_int16, T>(a);
132 
133  case dods_uint32_c:
134  return extract_array_helper<dods_uint32, T>(a);
135 
136  case dods_int32_c:
137  return extract_array_helper<dods_int32, T>(a);
138 
139  case dods_float32_c:
140  // Added the following line. jhrg 8/7/12
141  return extract_array_helper<dods_float32, T>(a);
142 
143  case dods_float64_c:
144  return extract_array_helper<dods_float64, T>(a);
145 
146  default:
147  throw InternalErr(__FILE__, __LINE__,
148  "The argument list built by the CE parser contained an unsupported numeric type.");
149  }
150 }
151 
152 //template<typename T> T *extractArray(libdap::Array * a);
153 //template<typename DODS, typename T> T *extract_array_helper(libdap::Array *a);
154 
155 
156 string getAttributeValue(libdap::BaseType *bt, string aName) ;
157 bool matchesCfRoleOrStandardName(libdap::BaseType *bt, string aValue);
158 
159 bool checkAttributeValue(libdap::BaseType *bt, string aName, string aValue);
160 
161 
162 vector<string> split(const string &s, char delim);
163 vector<string> &split(const string &s, char delim, vector<string> &elems);
164 
165 
166 int getNfrom3byNArray(libdap::Array *array);
167 
168 libdap::Type getGridfieldsReturnType(libdap::Type type);
169 
170 
171 
172 
173 }// namespace ugrid
174 
175 #endif // _UgridUtilities_h
libdap::Type getGridfieldsReturnType(libdap::Type type)
STL namespace.
GF::Array * extractGridFieldArray(libdap::Array *a, vector< int * > *sharedIntArrays, vector< float * > *sharedFloatArrays)
Extract data from a DAP array and return those values in a gridfields array.
Definition: ugrid_utils.cc:287
GF::Array * newGFIndexArray(string name, long size, vector< int * > *sharedIntArrays)
Definition: ugrid_utils.cc:265
static class NCMLUtil overview
int getNfrom3byNArray(libdap::Array *array)
Retrieves the size of the second dimension from a 3xN array.
Definition: ugrid_utils.cc:522
bool checkAttributeValue(libdap::BaseType *bt, string aName, string aValue)
T * extractArray(libdap::Array *a)
Given a pointer to an Array that holds a numeric type, extract the values and return in an array of T...
Definition: ugrid_utils.h:98
T * extract_array_helper(libdap::Array *a)
DAP Array data extraction helper method.
Definition: ugrid_utils.h:77
string getAttributeValue(libdap::BaseType *bt, string aName)
bool matchesCfRoleOrStandardName(libdap::BaseType *bt, string aValue)