bes  Updated for version 3.20.6
MeshDataVariable.cc
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 <util.h>
34 
35 #include <BESDebug.h>
36 #include <BESUtil.h>
37 
38 #include "ugrid_utils.h"
39 #include "LocationType.h"
40 #include "MeshDataVariable.h"
41 #include "TwoDMeshTopology.h"
42 
43 #ifdef NDEBUG
44 #undef BESDEBUG
45 #define BESDEBUG( x, y )
46 #endif
47 
48 using namespace std;
49 
50 namespace ugrid {
51 
52 MeshDataVariable::MeshDataVariable()
53 {
54  myGridLocation = node;
55  meshDataVar = 0;
56  _initialized = false;
57 }
58 
59 static locationType determineLocationType(libdap::Array *rangeVar)
60 {
61 
62  string locationString = getAttributeValue(rangeVar, UGRID_LOCATION);
63  BESDEBUG("ugrid", "determineLocationType() - UGRID_LOCATION: " << locationString << endl);
64 
65  if (locationString.empty()) {
66  locationString = getAttributeValue(rangeVar, UGRID_GRID_LOCATION);
67  BESDEBUG("ugrid", "determineLocationType() - UGRID_GRID_LOCATION: " << locationString << endl);
68  }
69 
70  if (locationString.empty()) {
71  string msg = "MeshDataVariable::determineLocation() - The range variable '" + rangeVar->name()
72  + "' is missing the required attribute named '" +
73  UGRID_LOCATION + "' and its alternate attribute named '" +
74  UGRID_GRID_LOCATION + "'";
75  BESDEBUG("ugrid", msg);
76  throw Error(msg);
77  }
78 
79  locationString = BESUtil::lowercase(locationString);
80 
81  if (locationString.compare(UGRID_NODE) == 0) {
82  BESDEBUG("ugrid", "determineLocationType() - Location is node. locationString: " << locationString << endl);
83  return node;
84  }
85 
86  if (locationString.compare(UGRID_EDGE) == 0) {
87  BESDEBUG("ugrid", "determineLocationType() - Location is edge. locationString: " << locationString << endl);
88  return edge;
89  }
90 
91  if (locationString.compare(UGRID_FACE) == 0) {
92  BESDEBUG("ugrid", "determineLocationType() - Location is face. locationString: " << locationString << endl);
93  return face;
94  }
95  string msg = "determineLocation() - The range variable '" + rangeVar->name() + "' has a '" + UGRID_LOCATION
96  + "' attribute with an unrecognized value of '" + locationString + "' The acceptable values are: '"
97  + UGRID_NODE + "', '" + UGRID_EDGE + "', and '" + UGRID_FACE + "'";
98  BESDEBUG("ugrid", msg);
99  throw Error(msg);
100 
101 }
102 
103 void MeshDataVariable::init(libdap::Array *rangeVar)
104 {
105  if (_initialized) return;
106 
107  meshDataVar = rangeVar;
108  BESDEBUG("ugrid",
109  "MeshDataVariable::init() - The user submitted the range data array: " << rangeVar->name() << endl);
110 
111  locationType rank = determineLocationType(rangeVar);
112 
113  setGridLocation(rank);
114 
115  meshName = getAttributeValue(rangeVar, UGRID_MESH);
116  if (meshName.empty()) {
117  string msg = "MeshDataVariable::init() - The range variable '" + rangeVar->name()
118  + "' is missing the required attribute named '" + UGRID_MESH + "' ";
119  BESDEBUG("ugrid", msg);
120  throw Error(msg);
121  }
122 
123  BESDEBUG("ugrid",
124  "MeshDataVariable::init() - Range data array '" << meshDataVar->name() << "' references the 'mesh' variable '" << meshName << "'" << endl);
125 
126  _initialized = true;
127 }
128 
129 } // namespace gf3
Error
BESUtil::lowercase
static std::string lowercase(const std::string &s)
Definition: BESUtil.cc:200