bes  Updated for version 3.20.6
ugrid_utils.h
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 libdap;
34 
35 namespace {
36 class Array;
37 }
38 
39 namespace ugrid {
40 
44 #define CF_ROLE "cf_role"
45 #define CF_STANDARD_NAME "standard_name"
46 #define UGRID_MESH_TOPOLOGY "mesh_topology"
47 #define UGRID_NODE_COORDINATES "node_coordinates"
48 #define UGRID_FACE_NODE_CONNECTIVITY "face_node_connectivity"
49 
50 #define UGRID_TOPOLOGY_DIMENSION "topology_dimension"
51 #define UGRID_DIMENSION "dimension" // Old-style; still using in some ugrids. jhrg 5/19/15
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 #define UGRID_FACE_COORDINATES "face_coordinates"
66 #define UGRID_EDGE_COORDINATES "edge_coordinates"
67 #define UGRID_FACE_EDGE_CONNECTIVITY "face_edge_connectivity"
68 #define UGRID_FACE_FACE_CONNECTIVITY "face_face_connectivity"
69 
70 GF::Array *extractGridFieldArray(libdap::Array *a, vector<int*> *sharedIntArrays, vector<float*> *sharedFloatArrays);
71 GF::Array *newGFIndexArray(string name, long size, vector<int*> *sharedIntArrays);
72 
73 string getAttributeValue(libdap::BaseType *bt, string aName);
74 bool matchesCfRoleOrStandardName(libdap::BaseType *bt, string aValue);
75 
76 bool checkAttributeValue(libdap::BaseType *bt, string aName, string aValue);
77 
78 vector<string> split(const string &s, char delim);
79 vector<string> &split(const string &s, char delim, vector<string> &elems);
80 
81 int getNfrom3byNArray(libdap::Array *array);
82 
83 libdap::Type getGridfieldsReturnType(libdap::Type type);
84 
90 template<typename DODS, typename T> T *extract_array_helper(libdap::Array *a)
91 {
92  int length = a->length();
93 
94  DODS *src = new DODS[length];
95 
96  a->value(src);
97 
98  T *dest = new T[length];
99 
100  for (int i = 0; i < length; ++i)
101  dest[i] = (T) src[i];
102 
103  delete[] src;
104 
105  return dest;
106 }
107 
125 template<typename T> T *extractArray(libdap::Array *a)
126 {
127 
128  // Simple types are Byte, ..., Float64, String and Url.
129  if ((a->type() == libdap::dods_array_c && !a->var()->is_simple_type()) || a->var()->type() == libdap::dods_str_c
130  || a->var()->type() == libdap::dods_url_c)
131  throw libdap::Error(malformed_expr, "The function requires a DAP numeric-type array argument.");
132 
133  a->read();
134 
135  // The types of arguments that the CE Parser will build for numeric
136  // constants are limited to Uint32, Int32 and Float64. See ce_expr.y.
137  // Expanded to work for any numeric type so it can be used for more than
138  // just arguments.
139  switch (a->var()->type()) {
140  case libdap::dods_byte_c:
141  return extract_array_helper<libdap::dods_byte, T>(a);
142 
143  case libdap::dods_uint16_c:
144  return extract_array_helper<libdap::dods_uint16, T>(a);
145 
146  case libdap::dods_int16_c:
147  return extract_array_helper<libdap::dods_int16, T>(a);
148 
149  case libdap::dods_uint32_c:
150  return extract_array_helper<libdap::dods_uint32, T>(a);
151 
152  case libdap::dods_int32_c:
153  return extract_array_helper<libdap::dods_int32, T>(a);
154 
155  case libdap::dods_float32_c:
156  // Added the following line. jhrg 8/7/12
157  return extract_array_helper<libdap::dods_float32, T>(a);
158 
159  case libdap::dods_float64_c:
160  return extract_array_helper<libdap::dods_float64, T>(a);
161 
162  default:
163  throw libdap::InternalErr(__FILE__, __LINE__,
164  "The argument list built by the CE parser contained an unsupported numeric type.");
165  }
166 }
167 
168 } // namespace ugrid
169 
170 #endif // _UgridUtilities_h
Type
Type
Type of JSON value.
Definition: cmr_module/rapidjson/rapidjson.h:603