bes  Updated for version 3.20.6
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 
47 FONcByte::FONcByte( BaseType *b )
48  : FONcBaseType(), _b( 0 )
49 {
50  _b = dynamic_cast<Byte *>(b) ;
51  if( !_b )
52  {
53  string s = (string)"File out netcdf, FONcByte was passed a "
54  + "variable that is not a DAP Byte" ;
55  throw BESInternalError( s, __FILE__, __LINE__ ) ;
56  }
57 }
58 
65 {
66 }
67 
78 void
79 FONcByte::define( int ncid )
80 {
81  FONcBaseType::define( ncid ) ;
82 
83  if( !_defined )
84  {
85  FONcAttributes::add_variable_attributes( ncid, _varid, _b ) ;
87  _varname, _orig_varname ) ;
88 
89  _defined = true ;
90  }
91 }
92 
102 void
103 FONcByte::write( int ncid )
104 {
105  BESDEBUG( "fonc", "FOncByte::write for var " << _varname << endl ) ;
106  size_t var_index[] = {0} ;
107  unsigned char *data = new unsigned char ;
108  _b->buf2val( (void**)&data ) ;
109  int stax = nc_put_var1_uchar( ncid, _varid, var_index, data ) ;
110  if( stax != NC_NOERR )
111  {
112  string err = (string)"fileout.netcdf - "
113  + "Failed to write byte data for "
114  + _varname ;
115  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
116  }
117  delete data ;
118 }
119 
124 string
126 {
127  return _b->name() ;
128 }
129 
134 nc_type
136 {
137  return NC_BYTE ;
138 }
139 
146 void
147 FONcByte::dump( ostream &strm ) const
148 {
149  strm << BESIndent::LMarg << "FONcByte::dump - ("
150  << (void *)this << ")" << endl ;
151  BESIndent::Indent() ;
152  strm << BESIndent::LMarg << "name = " << _b->name() << endl ;
153  BESIndent::UnIndent() ;
154 }
155 
FONcBaseType::define
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:53
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
FONcByte::name
virtual string name()
returns the name of the DAP Byte
Definition: FONcByte.cc:125
FONcByte::type
virtual nc_type type()
returns the netcdf type of the DAP Byte
Definition: FONcByte.cc:135
FONcAttributes::add_variable_attributes
static void add_variable_attributes(int ncid, int varid, BaseType *b)
Add the attributes for an OPeNDAP variable to the netcdf file.
Definition: FONcAttributes.cc:77
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
FONcByte::~FONcByte
virtual ~FONcByte()
Destructor that cleans up the byte.
Definition: FONcByte.cc:64
FONcAttributes::add_original_name
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.
Definition: FONcAttributes.cc:415
FONcBaseType
A DAP BaseType with file out netcdf information included.
Definition: FONcBaseType.h:58
FONcByte::define
virtual void define(int ncid)
define the DAP Byte in the netcdf file
Definition: FONcByte.cc:79
FONcByte::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcByte.cc:147
FONcByte::FONcByte
FONcByte(BaseType *b)
Constructor for FONcByte that takes a DAP Byte.
Definition: FONcByte.cc:47
FONcByte::write
virtual void write(int ncid)
Write the byte out to the netcdf file.
Definition: FONcByte.cc:103