bes  Updated for version 3.20.10
FONcMap.cc
1 // FONcMap.cc
2 
3 // This file is part of BES Netcdf File Out Module
4 
5 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
6 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact University Corporation for Atmospheric Research at
23 // 3080 Center Green Drive, Boulder, CO 80301
24 
25 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
26 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
27 //
28 // Authors:
29 // pwest Patrick West <pwest@ucar.edu>
30 // jgarcia Jose Garcia <jgarcia@ucar.edu>
31 
32 #include "config.h"
33 
34 #include <cstring>
35 
36 #include <libdap/Array.h>
37 
38 #include <BESDebug.h>
39 
40 #include "FONcArray.h"
41 #include "FONcMap.h"
42 #include "FONcUtils.h"
43 
57 FONcMap::FONcMap(FONcArray *a, bool ingrid)
58  : _arr(a), _ingrid(ingrid), _defined(false), _ref(1)
59 {
60 }
61 
70 {
71  if (_ingrid) {
72  delete _arr;
73  _arr = 0;
74  }
75 }
76 
84 void
86 {
87  _ref--;
88  if (!_ref) delete this;
89 }
90 
104 bool FONcMap::compare(libdap::Array *tomap)
105 {
106  bool isequal = true;
107 
108  libdap::Array *map = _arr->array();
109 
110  BESDEBUG("fonc", "FONcMap::compare - comparing " << tomap->name()
111  << " to " << map->name() << endl);
112 
113  // compare the name
114  if (isequal && tomap->name() != map->name()) {
115  isequal = false;
116  }
117 
118  // compare the type
119  if (isequal && tomap->var()->type() != map->var()->type()) {
120  isequal = false;
121  }
122 
123  // compare the length of the array
124  if (isequal && tomap->length() != map->length()) {
125  isequal = false;
126  }
127 
128  // compare the number of dimensions
129  if (isequal && tomap->dimensions() != map->dimensions()) {
130  isequal = false;
131  }
132 
133  // the variable name needs to be the same as the dimension name
134  if (isequal && map->dimension_name(map->dim_begin()) != map->name()) {
135  isequal = false;
136  }
137 
138  // compare the dimension name
139  if (isequal && tomap->dimension_name(tomap->dim_begin()) != map->dimension_name(map->dim_begin())) {
140  isequal = false;
141  }
142 
143  // compare the dimension size. Is this the same as the length of the array
144  if (isequal && tomap->dimension_size(tomap->dim_begin(), true) != map->dimension_size(map->dim_begin(), true)) {
145  isequal = false;
146  }
147 
148  if (isequal) {
149  // compare the values of the array
150  char *map_buf = map->get_buf();
151  char *tomap_buf = tomap->get_buf();
152 
153  // Only compare the values if both the value vectors are not null.
154  // Optimizations in this handler might cause one of these to be
155  // null, resulting in a segmenation fault. If one or both are null,
156  // assume that by this point in the series of tests, the two maps
157  // are equal. jhrg 6/8/21
158  if (map_buf && tomap_buf && 0 != memcmp(map_buf, tomap_buf, map->width()))
159  isequal = false;
160  }
161 
162  BESDEBUG("fonc",
163  "FONcMap::compare - done comparing " << tomap->name() << " to " << map->name() << ": " << isequal << endl);
164  return isequal;
165 }
166 
169 void
170 FONcMap::add_grid(const string &name)
171 {
172  _shared_by.push_back(name);
173 }
174 
178 void
180 {
181  _arr->clear_embedded();
182 }
183 
189 void
191 {
192  if (!_defined) {
193  _arr->define(ncid);
194  _defined = true;
195  }
196 }
197 
203 void
204 FONcMap::write(int ncid)
205 {
206  _arr->write(ncid);
207 }
208 
216 void
217 FONcMap::dump(ostream &strm) const
218 {
219  strm << BESIndent::LMarg << "FONcMap::dump - ("
220  << (void *) this << ")" << endl;
221  BESIndent::Indent();
222  strm << BESIndent::LMarg << "array:";
223  if (_arr) {
224  strm << endl;
225  BESIndent::Indent();
226  _arr->dump(strm);
227  BESIndent::UnIndent();
228  }
229  else {
230  strm << " not set" << endl;
231  }
232  strm << BESIndent::LMarg << "shared by: ";
233  vector<string>::const_iterator i = _shared_by.begin();
234  vector<string>::const_iterator e = _shared_by.end();
235  bool first = true;
236  for (; i != e; i++) {
237  if (!first) strm << ", ";
238  strm << (*i);
239  first = false;
240  }
241  strm << endl;
242  BESIndent::UnIndent();
243 }
244 
A DAP Array with file out netcdf information included.
Definition: FONcArray.h:57
virtual void dump(std::ostream &strm) const override
dumps information about this object for debugging purposes
Definition: FONcArray.cc:754
virtual void define(int ncid) override
define the DAP Array in the netcdf file
Definition: FONcArray.cc:382
virtual void write(int ncid) override
Write the array out to the netcdf file.
Definition: FONcArray.cc:574
virtual void clear_embedded()
Clears the list of embedded variable names.
Definition: FONcBaseType.cc:93
virtual void clear_embedded()
clear the embedded names for the FONcArray kept by this instance
Definition: FONcMap.cc:179
virtual void dump(std::ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcMap.cc:217
virtual ~FONcMap()
Destructor that cleans up the map.
Definition: FONcMap.cc:69
virtual void decref()
decrements the reference count for this map
Definition: FONcMap.cc:85
virtual void add_grid(const std::string &name)
Add the name of the grid as a grid that uses this map.
Definition: FONcMap.cc:170
virtual void write(int ncid)
writes out the vallues of the map to the netcdf file by calling write on the FONcArray
Definition: FONcMap.cc:204
virtual bool compare(libdap::Array *arr)
a method to compare two grid maps, or possible grid maps.
Definition: FONcMap.cc:104
virtual void define(int ncid)
define the map in the netcdf file by calling define on the FONcArray
Definition: FONcMap.cc:190