OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
FONcMap.cc
Go to the documentation of this file.
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 <BESDebug.h>
33 
34 #include "FONcMap.h"
35 #include "FONcUtils.h"
36 
50 FONcMap::FONcMap( FONcArray *a, bool ingrid )
51  : _arr( a ), _ingrid( ingrid ), _defined( false ), _ref( 1 )
52 {
53 }
54 
63 {
64  if( _ingrid )
65  {
66  delete _arr ;
67  _arr = 0 ;
68  }
69 }
70 
78 void
80 {
81  _ref-- ;
82  if( !_ref ) delete this ;
83 }
84 
98 bool
99 FONcMap::compare( Array *tomap )
100 {
101  bool isequal = true ;
102 
103  Array *map = _arr->array() ;
104 
105  BESDEBUG( "fonc", "FONcMap::compare - comparing " << tomap->name()
106  << " to " << map->name() << endl ) ;
107 
108  // compare the name
109  if( isequal && tomap->name() != map->name() )
110  {
111  isequal = false ;
112  }
113 
114  // compare the type
115  if( isequal && tomap->var()->type() != map->var()->type() )
116  {
117  isequal =false ;
118  }
119 
120  // compare the length of the array
121  if( isequal && tomap->length() != map->length() )
122  {
123  isequal = false ;
124  }
125 
126  // compare the number of dimensions
127  if( isequal && tomap->dimensions() != map->dimensions() )
128  {
129  isequal = false ;
130  }
131 
132  // the variable name needs to be the same as the dimension name
133  if( isequal &&
134  map->dimension_name( map->dim_begin() ) != map->name() )
135  {
136  isequal = false ;
137  }
138 
139  // compare the dimension name
140  if( isequal &&
141  tomap->dimension_name( tomap->dim_begin() ) !=
142  map->dimension_name( map->dim_begin() ) )
143  {
144  isequal = false ;
145  }
146 
147  // compare the dimension size. Is this the same as the length of the array
148  if( isequal &&
149  tomap->dimension_size( tomap->dim_begin(), true ) !=
150  map->dimension_size( map->dim_begin(), true ) )
151  {
152  isequal = false ;
153  }
154 
155  if( isequal )
156  {
157  // compare the values of the array
158  switch( tomap->var()->type() )
159  {
160  case dods_byte_c:
161  {
162  dods_byte my_values[map->length()] ;
163  map->value( my_values ) ;
164  dods_byte to_values[map->length()] ;
165  tomap->value( to_values ) ;
166  for( int i = 0; i < map->length(); i++ )
167  {
168  if( my_values[i] != to_values[i] )
169  {
170  isequal = false ;
171  break ;
172  }
173  }
174  }
175  break ;
176  case dods_int16_c:
177  {
178  dods_int16 my_values[map->length()] ;
179  map->value( my_values ) ;
180  dods_int16 to_values[map->length()] ;
181  tomap->value( to_values ) ;
182  for( int i = 0; i < map->length(); i++ )
183  {
184  if( my_values[i] != to_values[i] )
185  {
186  isequal = false ;
187  break ;
188  }
189  }
190  }
191  break ;
192  case dods_uint16_c:
193  {
194  dods_uint16 my_values[map->length()] ;
195  map->value( my_values ) ;
196  dods_uint16 to_values[map->length()] ;
197  tomap->value( to_values ) ;
198  for( int i = 0; i < map->length(); i++ )
199  {
200  if( my_values[i] != to_values[i] )
201  {
202  isequal = false ;
203  break ;
204  }
205  }
206  }
207  break ;
208  case dods_int32_c:
209  {
210  dods_int32 my_values[map->length()] ;
211  map->value( my_values ) ;
212  dods_int32 to_values[map->length()] ;
213  tomap->value( to_values ) ;
214  for( int i = 0; i < map->length(); i++ )
215  {
216  if( my_values[i] != to_values[i] )
217  {
218  isequal = false ;
219  break ;
220  }
221  }
222  }
223  break ;
224  case dods_uint32_c:
225  {
226  dods_uint32 my_values[map->length()] ;
227  map->value( my_values ) ;
228  dods_uint32 to_values[map->length()] ;
229  tomap->value( to_values ) ;
230  for( int i = 0; i < map->length(); i++ )
231  {
232  if( my_values[i] != to_values[i] )
233  {
234  isequal = false ;
235  break ;
236  }
237  }
238  }
239  break ;
240  case dods_float32_c:
241  {
242  dods_float32 my_values[map->length()] ;
243  map->value( my_values ) ;
244  dods_float32 to_values[map->length()] ;
245  tomap->value( to_values ) ;
246  for( int i = 0; i < map->length(); i++ )
247  {
248  if( my_values[i] != to_values[i] )
249  {
250  isequal = false ;
251  break ;
252  }
253  }
254  }
255  break ;
256  case dods_float64_c:
257  {
258  dods_float64 my_values[map->length()] ;
259  map->value( my_values ) ;
260  dods_float64 to_values[map->length()] ;
261  tomap->value( to_values ) ;
262  for( int i = 0; i < map->length(); i++ )
263  {
264  if( my_values[i] != to_values[i] )
265  {
266  isequal = false ;
267  break ;
268  }
269  }
270  }
271  break ;
272  case dods_str_c:
273  case dods_url_c:
274  {
275  vector<string> my_values ;
276  map->value( my_values ) ;
277  vector<string> to_values ;
278  tomap->value( to_values ) ;
279  vector<string>::const_iterator mi = my_values.begin() ;
280  vector<string>::const_iterator me = my_values.end() ;
281  vector<string>::const_iterator ti = to_values.begin() ;
282  for( ; mi != me; mi++, ti++ )
283  {
284  if( (*mi) != (*ti) )
285  {
286  isequal = false ;
287  break ;
288  }
289  }
290  }
291  break ;
292  default: // Elide unknown types; this is the current behavior
293  // but I made it explicit. jhrg 12.27.2011
294  break;
295  }
296  }
297 
298  BESDEBUG( "fonc", "FONcMap::compare - done comparing " << tomap->name()
299  << " to " << map->name() << ": " << isequal << endl ) ;
300  return isequal ;
301 }
302 
305 void
306 FONcMap::add_grid( const string &name )
307 {
308  _shared_by.push_back( name ) ;
309 }
310 
314 void
316 {
317  _arr->clear_embedded() ;
318 }
319 
325 void
326 FONcMap::define( int ncid )
327 {
328  if( !_defined )
329  {
330  _arr->define( ncid ) ;
331  _defined = true ;
332  }
333 }
334 
340 void
341 FONcMap::write( int ncid )
342 {
343  _arr->write( ncid ) ;
344 }
345 
353 void
354 FONcMap::dump( ostream &strm ) const
355 {
356  strm << BESIndent::LMarg << "FONcMap::dump - ("
357  << (void *)this << ")" << endl ;
359  strm << BESIndent::LMarg << "array:" ;
360  if( _arr )
361  {
362  strm << endl ;
364  _arr->dump( strm ) ;
366  }
367  else
368  {
369  strm << " not set" << endl ;
370  }
371  strm << BESIndent::LMarg << "shared by: " ;
372  vector<string>::const_iterator i = _shared_by.begin() ;
373  vector<string>::const_iterator e = _shared_by.end() ;
374  bool first = true ;
375  for( ; i != e; i++ )
376  {
377  if( !first ) strm << ", " ;
378  strm << (*i) ;
379  first = false ;
380  }
381  strm << endl ;
383 }
384 
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:341
virtual void add_grid(const string &name)
Add the name of the grid as a grid that uses this map.
Definition: FONcMap.cc:306
virtual ~FONcMap()
Destructor that cleans up the map.
Definition: FONcMap.cc:62
A DAP Array with file out netcdf information included.
Definition: FONcArray.h:50
virtual void clear_embedded()
Clears the list of embedded variable names.
Definition: FONcBaseType.cc:95
virtual bool compare(Array *arr)
a method to compare two grid maps, or possible grid maps.
Definition: FONcMap.cc:99
virtual void write(int ncid)
Write the array out to the netcdf file.
Definition: FONcArray.cc:357
virtual Array * array()
Definition: FONcArray.h:93
virtual void decref()
decrements the reference count for this map
Definition: FONcMap.cc:79
static void Indent()
Definition: BESIndent.cc:38
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual void define(int ncid)
define the DAP Array in the netcdf file
Definition: FONcArray.cc:289
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcMap.cc:354
virtual void define(int ncid)
define the map in the netcdf file by calling define on the FONcArray
Definition: FONcMap.cc:326
virtual void clear_embedded()
clear the embedded names for the FONcArray kept by this instance
Definition: FONcMap.cc:315
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
static void UnIndent()
Definition: BESIndent.cc:44
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcArray.cc:542