28 #ifndef _UgridUtilities_h
29 #define _UgridUtilities_h 1
31 #include <gridfields/array.h>
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"
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"
63 #define UGRID_EDGE_NODE_CONNECTIVITY "edge_node_connectivity"
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"
70 GF::Array *extractGridFieldArray(libdap::Array *a, vector<int*> *sharedIntArrays, vector<float*> *sharedFloatArrays);
71 GF::Array *newGFIndexArray(
string name,
long size, vector<int*> *sharedIntArrays);
73 string getAttributeValue(libdap::BaseType *bt,
string aName);
74 bool matchesCfRoleOrStandardName(libdap::BaseType *bt,
string aValue);
76 bool checkAttributeValue(libdap::BaseType *bt,
string aName,
string aValue);
78 vector<string> split(
const string &s,
char delim);
79 vector<string> &split(
const string &s,
char delim, vector<string> &elems);
81 int getNfrom3byNArray(libdap::Array *array);
90 template<
typename DODS,
typename T> T *extract_array_helper(libdap::Array *a)
92 int length = a->length();
94 DODS *src =
new DODS[length];
98 T *dest =
new T[length];
100 for (
int i = 0; i < length; ++i)
101 dest[i] = (T) src[i];
125 template<
typename T> T *extractArray(libdap::Array *a)
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.");
139 switch (a->var()->type()) {
140 case libdap::dods_byte_c:
141 return extract_array_helper<libdap::dods_byte, T>(a);
143 case libdap::dods_uint16_c:
144 return extract_array_helper<libdap::dods_uint16, T>(a);
146 case libdap::dods_int16_c:
147 return extract_array_helper<libdap::dods_int16, T>(a);
149 case libdap::dods_uint32_c:
150 return extract_array_helper<libdap::dods_uint32, T>(a);
152 case libdap::dods_int32_c:
153 return extract_array_helper<libdap::dods_int32, T>(a);
155 case libdap::dods_float32_c:
157 return extract_array_helper<libdap::dods_float32, T>(a);
159 case libdap::dods_float64_c:
160 return extract_array_helper<libdap::dods_float64, T>(a);
163 throw libdap::InternalErr(__FILE__, __LINE__,
164 "The argument list built by the CE parser contained an unsupported numeric type.");
170 #endif // _UgridUtilities_h