bes Updated for version 3.20.13
FONcByte.cc
1// FONcByte.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 <BESInternalError.h>
33#include <BESDebug.h>
34
35#include "FONcByte.h"
36#include "FONcUtils.h"
37#include "FONcAttributes.h"
38
48 : FONcBaseType(), _b(nullptr) {
49 _b = dynamic_cast<Byte *>(b);
50 if (!_b) {
51 string s = (string) "File out netcdf, FONcByte was passed a "
52 + "variable that is not a DAP Byte";
53 throw BESInternalError(s, __FILE__, __LINE__);
54 }
55}
56
67void
70
71 if (!_defined) {
72 if (is_dap4) {
73 D4Attributes *d4_attrs = _b->attributes();
74 updateD4AttrType(d4_attrs, NC_UBYTE);
75 }
76 else {
77 AttrTable &attrs = _b->get_attr_table();
78 updateAttrType(attrs, NC_UBYTE);
79 }
80
81 FONcAttributes::add_variable_attributes(ncid, _varid, _b, isNetCDF4_ENHANCED(), is_dap4);
82 FONcAttributes::add_original_name(ncid, _varid, _varname, _orig_varname);
83
84 _defined = true;
85 }
86}
87
97void
98FONcByte::write(int ncid) {
99 BESDEBUG("fonc", "FOncByte::write for var " << _varname << endl);
100
101 if (is_dap4)
102 _b->intern_data();
103 else
104 _b->intern_data(*get_eval(), *get_dds());
105
106 // For scalar types, assign the value to a local variable. Eliminate the
107 // allocation of dynamic memory as well as the delete call. The amount of
108 // memory used in this case is too small to warrant any more optimization.
109 unsigned char data = _b->value();
110 size_t var_index[] = {0};
111 int stax = nc_put_var1_uchar(ncid, _varid, var_index, &data);
112 if (stax != NC_NOERR) {
113 string err = string("fileout.netcdf - Failed to write byte data for ") + _varname;
114 FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
115 }
116}
117
124void
125FONcByte::dump(ostream &strm) const {
126 strm << BESIndent::LMarg << "FONcByte::dump - ("
127 << (void *) this << ")" << endl;
128 BESIndent::Indent();
129 strm << BESIndent::LMarg << "name = " << _b->name() << endl;
130 BESIndent::UnIndent();
131}
132
exception thrown if internal error encountered
static void add_original_name(int ncid, int varid, const string &var_name, const string &orig)
Adds an attribute for the variable if the variable name had to be modified in any way.
static void add_variable_attributes(int ncid, int varid, BaseType *b, bool is_netCDF_enhanced, bool is_dap4)
Add the attributes for an OPeNDAP variable to the netcdf file.
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:60
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:60
virtual void write(int ncid) override
Write the byte out to the netcdf file.
Definition: FONcByte.cc:98
virtual void dump(ostream &strm) const override
dumps information about this object for debugging purposes
Definition: FONcByte.cc:125
virtual void define(int ncid) override
define the DAP Byte in the netcdf file
Definition: FONcByte.cc:68
FONcByte(libdap::BaseType *b)
Constructor for FONcByte that takes a DAP Byte.
Definition: FONcByte.cc:47
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:424