OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
MeshDataVariable.cc
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 #include "config.h"
29 
30 #include <gridfields/array.h>
31 
32 #include "Array.h"
33 #include "BESDebug.h"
34 #include "util.h"
35 
36 #include "ugrid_utils.h"
37 #include "LocationType.h"
38 #include "MeshDataVariable.h"
39 #include "TwoDMeshTopology.h"
40 
41 using namespace std;
42 using namespace libdap;
43 using namespace ugrid;
44 using std::endl;
45 
46 namespace ugrid {
47 
48 MeshDataVariable::MeshDataVariable(){
49  myGridLocation = node;
50  meshDataVar = 0;
51  _initialized = false;
52 }
53 
54 
55 static locationType determineLocationType(libdap::Array *rangeVar){
56 
57  string locationString = getAttributeValue(rangeVar,UGRID_LOCATION);
58  BESDEBUG("ugrid", "determineLocationType() - UGRID_LOCATION: " << locationString << endl);
59 
60  if(locationString.empty()){
61  locationString = getAttributeValue(rangeVar,UGRID_GRID_LOCATION);
62  BESDEBUG("ugrid", "determineLocationType() - UGRID_GRID_LOCATION: " << locationString << endl);
63  }
64 
65  if(locationString.empty()){
66  string msg = "MeshDataVariable::determineLocation() - The range variable '" +
67  rangeVar->name() + "' is missing the required attribute named '"+
68  UGRID_LOCATION + "' and its alternate attribute named '" +
69  UGRID_GRID_LOCATION + "'";
70  BESDEBUG("ugrid",msg );
71  throw Error( msg);
72  }
73 
74  locationString = BESUtil::lowercase(locationString);
75 
76 
77  if(locationString.compare(UGRID_NODE) == 0 ){
78  BESDEBUG("ugrid", "determineLocationType() - Location is node. locationString: " << locationString << endl);
79  return node;
80  }
81 
82  if(locationString.compare(UGRID_EDGE) == 0){
83  BESDEBUG("ugrid", "determineLocationType() - Location is edge. locationString: " << locationString << endl);
84  return edge;
85  }
86 
87  if(locationString.compare(UGRID_FACE) == 0){
88  BESDEBUG("ugrid", "determineLocationType() - Location is face. locationString: " << locationString << endl);
89  return face;
90  }
91  string msg = "determineLocation() - The range variable '" + rangeVar->name() +
92  "' has a '" + UGRID_LOCATION + "' attribute with an unrecognized value of '" + locationString +
93  "' The acceptable values are: '" + UGRID_NODE + "', '" + UGRID_EDGE+ "', and '" + UGRID_FACE + "'";
94  BESDEBUG("ugrid",msg );
95  throw Error( msg);
96 
97 }
98 
99 
100 void MeshDataVariable::init(libdap::Array *rangeVar)
101 {
102  if(_initialized)
103  return;
104 
105  meshDataVar = rangeVar;
106  BESDEBUG("ugrid", "MeshDataVariable::init() - The user submitted the range data array: " << rangeVar->name() << endl);
107 
108  locationType rank = determineLocationType(rangeVar);
109 
110  setGridLocation(rank);
111 
112  meshName = getAttributeValue(rangeVar, UGRID_MESH);
113  if(meshName.empty()){
114  string msg = "MeshDataVariable::init() - The range variable '" + rangeVar->name() +
115  "' is missing the required attribute named '" + UGRID_MESH + "' ";
116  BESDEBUG("ugrid",msg );
117  throw Error( msg);
118  }
119 
120  BESDEBUG("ugrid", "MeshDataVariable::init() - Range data array '" << meshDataVar->name() <<
121  "' references the 'mesh' variable '" << meshName << "'" << endl);
122 
123  _initialized = true;
124 }
125 
126 
127 } // namespace gf3
#define UGRID_LOCATION
Definition: ugrid_utils.h:52
static string lowercase(const string &s)
Convert a string to all lower case.
Definition: BESUtil.cc:182
STL namespace.
#define UGRID_EDGE
Definition: ugrid_utils.h:55
static class NCMLUtil overview
#define UGRID_FACE
Definition: ugrid_utils.h:56
#define UGRID_MESH
Definition: ugrid_utils.h:57
#define UGRID_GRID_LOCATION
Definition: ugrid_utils.h:53
locationType
Definition: LocationType.h:31
CURL * init(char *error_buffer)
Get's a new instance of CURL* and performs basic configuration of that instance.
Definition: curl_utils.cc:426
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
#define UGRID_NODE
Definition: ugrid_utils.h:54
string getAttributeValue(BaseType *bt, string aName)
Definition: ugrid_utils.cc:456