bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
FONcUByte.cc
1// FONcUByte.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//
23// Authors:
24// kyang Kent Yang <myang6@hdfgroup.org>
25// Note: The code follows FONcUByte.cc.
26
27
28
29#include <BESInternalError.h>
30#include <BESDebug.h>
31
32#include "FONcUByte.h"
33#include "FONcUtils.h"
34#include "FONcAttributes.h"
35
45 : FONcBaseType(), _b( 0 )
46{
47 _b = dynamic_cast<Byte *>(b) ;
48 if( !_b )
49 {
50 string s = (string)"File out netcdf, FONcUByte was passed a "
51 + "variable that is not a DAP Byte" ;
52 throw BESInternalError( s, __FILE__, __LINE__ ) ;
53 }
54}
55
64
75void
77{
78 FONcBaseType::define( ncid ) ;
79
80 if( !d_defined )
81 {
82 if(d_is_dap4) {
83 D4Attributes *d4_attrs = _b->attributes();
84 updateD4AttrType(d4_attrs,NC_UBYTE);
85 }
86 else {
87 AttrTable &attrs = _b->get_attr_table();
88 updateAttrType(attrs,NC_UBYTE);
89 }
90
91 FONcAttributes::add_variable_attributes(ncid, d_varid, _b, isNetCDF4_ENHANCED(), d_is_dap4 ) ;
93 d_varname, d_orig_varname ) ;
94
95 d_defined = true ;
96 }
97}
98
108void
110{
111 BESDEBUG( "fonc", "FOncUByte::write for var " << d_varname << endl ) ;
112 size_t var_index[] = {0} ;
113 unsigned char *data = new unsigned char ;
114
115 if (d_is_dap4)
116 _b->intern_data();
117 else
118 _b->intern_data(*get_eval(), *get_dds());
119
120 _b->buf2val( (void**)&data ) ;
121 int stax = nc_put_var1_uchar(ncid, d_varid, var_index, data ) ;
122 if( stax != NC_NOERR )
123 {
124 string err = (string)"fileout.netcdf - "
125 + "Failed to write byte data for "
126 + d_varname ;
127 FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
128 }
129 delete data ;
130}
131
136string
138{
139 return _b->name() ;
140}
141
146nc_type
148{
149 return NC_UBYTE ;
150}
151
158void
160{
161 strm << BESIndent::LMarg << "FONcUByte::dump - ("
162 << (void *)this << ")" << endl ;
163 BESIndent::Indent() ;
164 strm << BESIndent::LMarg << "name = " << _b->name() << endl ;
165 BESIndent::UnIndent() ;
166}
167
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.
virtual void define(int ncid)
Define the variable in the netcdf file.
FONcUByte(libdap::BaseType *b)
Constructor for FONcUByte that takes a DAP Byte.
Definition FONcUByte.cc:44
virtual void define(int ncid)
define the DAP Byte in the netcdf file
Definition FONcUByte.cc:76
virtual ~FONcUByte()
Destructor that cleans up the byte.
Definition FONcUByte.cc:61
virtual nc_type type()
returns the netcdf type of the DAP Byte
Definition FONcUByte.cc:147
virtual string name()
returns the name of the DAP Byte
Definition FONcUByte.cc:137
virtual void write(int ncid)
Write the byte out to the netcdf file.
Definition FONcUByte.cc:109
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition FONcUByte.cc:159
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition FONcUtils.cc:429
STL class.
STL class.