bes  Updated for version 3.20.6
FONcDim.cc
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 
62 {
63  _ref--;
64  if (!_ref) delete this;
65 }
66 
79 void FONcDim::define(int ncid)
80 {
81  if (!_defined) {
82  if (_name.empty()) {
83  ostringstream dimname_strm;
84  dimname_strm << "dim" << FONcDim::DimNameNum + 1;
85  FONcDim::DimNameNum++;
86  _name = dimname_strm.str();
87  }
88  else {
89  _name = FONcUtils::id2netcdf(_name);
90  }
91  int stax = nc_def_dim(ncid, _name.c_str(), _size, &_dimid);
92  if (stax != NC_NOERR) {
93  string err = (string) "fileout.netcdf - " + "Failed to add dimension " + _name;
94  FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
95  }
96  _defined = true;
97  }
98 }
99 
106 void FONcDim::dump(ostream &strm) const
107 {
108  strm << BESIndent::LMarg << "FONcDim::dump - (" << (void *) this << ")" << endl;
109  BESIndent::Indent();
110  strm << BESIndent::LMarg << "name = " << _name << endl;
111  strm << BESIndent::LMarg << "size = " << _size << endl;
112  strm << BESIndent::LMarg << "dimid = " << _dimid << endl;
113  strm << BESIndent::LMarg << "already defined? ";
114  if (_defined)
115  strm << "true";
116  else
117  strm << "false";
118  strm << endl;
119  BESIndent::UnIndent();
120 }
121 
FONcUtils::id2netcdf
static string id2netcdf(string in)
convert the provided string to a netcdf allowed identifier.
Definition: FONcUtils.cc:75
FONcDim::dump
virtual void dump(std::ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcDim.cc:106
FONcUtils::handle_error
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:245
FONcDim::FONcDim
FONcDim(const std::string &name, int size)
Constructor for FOncDim that defines the dimension of an array.
Definition: FONcDim.cc:49
FONcDim::define
virtual void define(int ncid)
define the DAP dimension in the netcdf file
Definition: FONcDim.cc:79
FONcDim::decref
virtual void decref()
Decrement the reference count for this dimension.
Definition: FONcDim.cc:61