bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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
34using std::ostringstream;
35
36#include <netcdf.h>
37#include <BESDebug.h>
38
39#include "FONcDim.h"
40#include "FONcUtils.h"
41
42int FONcDim::DimNameNum = 0;
43int FONcDim::StructDimNameNum = 0;
50FONcDim::FONcDim(const string &name, int64_t size) :
51 _name(name), _size(size)
52{
53}
54
63{
64 _ref--;
65 if (!_ref) delete this;
66}
67
68void FONcDim::struct_decref()
69{
70 _struct_ref--;
71 if (!_struct_ref) delete this;
72}
85void FONcDim::define(int ncid)
86{
87 if (!_defined) {
88 if (_name.empty()) {
89 ostringstream dimname_strm;
90 dimname_strm << "dim" << FONcDim::DimNameNum + 1;
91 FONcDim::DimNameNum++;
92 _name = dimname_strm.str();
93 }
94 else {
95 _name = FONcUtils::id2netcdf(_name);
96 }
97
98 BESDEBUG("fonc", "FONcDim:: dimension size is "<<_size <<endl);
99 BESDEBUG("fonc", "FONcDim:: dimension name is "<<_name <<endl);
100 int stax = nc_def_dim(ncid, _name.c_str(), _size, &_dimid);
101 if (stax != NC_NOERR) {
102 string err = (string) "fileout.netcdf - " + "Failed to add dimension " + _name;
103 FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
104 }
105 _defined = true;
106 }
107}
108
109void FONcDim::define_struct(int ncid)
110{
111 if (!_defined) {
112 if (_name.empty()) {
113 FONcDim::StructDimNameNum++;
114 _name ="sdim" + to_string(FONcDim::StructDimNameNum);
115 }
116 else {
117 _name = FONcUtils::id2netcdf(_name);
118 }
119
120 BESDEBUG("fonc", "FONcDim:: dimension size is "<<_size <<endl);
121 BESDEBUG("fonc", "FONcDim:: dimension name is "<<_name <<endl);
122 int stax = nc_def_dim(ncid, _name.c_str(), _size, &_dimid);
123 if (stax != NC_NOERR) {
124 string err = (string) "fileout.netcdf - " + "Failed to add dimension " + _name;
125 FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
126 }
127 _defined = true;
128 }
129}
130
137void FONcDim::dump(ostream &strm) const
138{
139 strm << BESIndent::LMarg << "FONcDim::dump - (" << (void *) this << ")" << endl;
140 BESIndent::Indent();
141 strm << BESIndent::LMarg << "name = " << _name << endl;
142 strm << BESIndent::LMarg << "size = " << _size << endl;
143 strm << BESIndent::LMarg << "dimid = " << _dimid << endl;
144 strm << BESIndent::LMarg << "already defined? ";
145 if (_defined)
146 strm << "true";
147 else
148 strm << "false";
149 strm << endl;
150 BESIndent::UnIndent();
151}
152
virtual void dump(std::ostream &strm) const
dumps information about this object for debugging purposes
Definition FONcDim.cc:137
FONcDim(const std::string &name, int64_t size)
Constructor for FOncDim that defines the dimension of an array.
Definition FONcDim.cc:50
virtual void define(int ncid)
define the DAP dimension in the netcdf file
Definition FONcDim.cc:85
virtual void decref()
Decrement the reference count for this dimension.
Definition FONcDim.cc:62
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition FONcUtils.cc:429
static string id2netcdf(string in)
convert the provided string to a netcdf allowed identifier.
Definition FONcUtils.cc:87
STL class.