OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
FONcDim.cc
Go to the documentation of this file.
1 // FONcDim.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 <sstream>
33 
34 using std::ostringstream ;
35 
36 #include <netcdf.h>
37 
38 #include "FONcDim.h"
39 #include "FONcUtils.h"
40 
41 int FONcDim::DimNameNum = 0 ;
42 
49 FONcDim::FONcDim( const string &name, int size )
50  : _name( name ), _size( size ), _dimid( 0 ), _defined( false ), _ref( 1 )
51 {
52 }
53 
61 void
63 {
64  _ref-- ;
65  if( !_ref ) delete this ;
66 }
67 
80 void
81 FONcDim::define( int ncid )
82 {
83  if( !_defined )
84  {
85  if( _name.empty() )
86  {
87  ostringstream dimname_strm ;
88  dimname_strm << "dim" << FONcDim::DimNameNum+1 ;
89  FONcDim::DimNameNum++ ;
90  _name = dimname_strm.str() ;
91  }
92  else
93  {
94  _name = FONcUtils::id2netcdf( _name ) ;
95  }
96  int stax = nc_def_dim( ncid, _name.c_str(), _size, &_dimid ) ;
97  if( stax != NC_NOERR )
98  {
99  string err = (string)"fileout.netcdf - "
100  + "Failed to add dimension " + _name ;
101  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
102  }
103  _defined = true ;
104  }
105 }
106 
113 void
114 FONcDim::dump( ostream &strm ) const
115 {
116  strm << BESIndent::LMarg << "FONcDim::dump - ("
117  << (void *)this << ")" << endl ;
119  strm << BESIndent::LMarg << "name = " << _name << endl ;
120  strm << BESIndent::LMarg << "size = " << _size << endl ;
121  strm << BESIndent::LMarg << "dimid = " << _dimid << endl ;
122  strm << BESIndent::LMarg << "already defined? " ;
123  if( _defined )
124  strm << "true" ;
125  else
126  strm << "false" ;
127  strm << endl ;
129 }
130 
static int DimNameNum
Definition: FONcDim.h:68
static void Indent()
Definition: BESIndent.cc:38
virtual void decref()
Decrement the reference count for this dimension.
Definition: FONcDim.cc:62
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
FONcDim(const string &name, int size)
Constructor for FOncDim that defines the dimension of an array.
Definition: FONcDim.cc:49
static void handle_error(int stax, string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:238
virtual void define(int ncid)
define the DAP dimension in the netcdf file
Definition: FONcDim.cc:81
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcDim.cc:114
static void UnIndent()
Definition: BESIndent.cc:44
static string id2netcdf(string in)
convert the provided string to a netcdf allowed identifier.
Definition: FONcUtils.cc:73