bes  Updated for version 3.20.10
FONcFloat.cc
1 // FONcFloat.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 #include <libdap/Float32.h>
35 
36 #include "FONcFloat.h"
37 #include "FONcUtils.h"
38 #include "FONcAttributes.h"
39 
48 FONcFloat::FONcFloat( BaseType *b )
49  : FONcBaseType(), _f( 0 )
50 {
51  _f = dynamic_cast<Float32 *>(b) ;
52  if( !_f )
53  {
54  string s = (string)"File out netcdf, FONcFloat was passed a "
55  + "variable that is not a DAP Float32" ;
56  throw BESInternalError( s, __FILE__, __LINE__ ) ;
57  }
58 }
59 
66 {
67 }
68 
79 void
80 FONcFloat::define( int ncid )
81 {
82  FONcBaseType::define( ncid ) ;
83 
84  if( !_defined )
85  {
86  if(is_dap4) {
87  D4Attributes *d4_attrs = _f->attributes();
88  updateD4AttrType(d4_attrs,NC_FLOAT);
89  }
90  else {
91  AttrTable &attrs = _f->get_attr_table();
92  updateAttrType(attrs,NC_FLOAT);
93  }
94 
95 
96  FONcAttributes::add_variable_attributes( ncid, _varid, _f,isNetCDF4_ENHANCED() ,is_dap4) ;
98  _varname, _orig_varname ) ;
99 
100  _defined = true ;
101  }
102 }
103 
113 void
114 FONcFloat::write( int ncid )
115 {
116  BESDEBUG( "fonc", "FONcFloat::write for var " << _varname << endl ) ;
117  size_t var_index[] = {0} ;
118  float *data = new float ;
119 
120  if (is_dap4)
121  _f->intern_data();
122  else
123  _f->intern_data(*get_eval(), *get_dds());
124 
125  _f->buf2val( (void**)&data ) ;
126  int stax = nc_put_var1_float( ncid, _varid, var_index, data ) ;
127  ncopts = NC_VERBOSE ;
128  if( stax != NC_NOERR )
129  {
130  string err = (string)"fileout.netcdf - "
131  + "Failed to write float data for "
132  + _varname ;
133  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
134  }
135  delete data ;
136  BESDEBUG( "fonc", "FONcFloat::done write for var " << _varname << endl ) ;
137 }
138 
143 string
145 {
146  return _f->name() ;
147 }
148 
153 nc_type
155 {
156  return NC_FLOAT ;
157 }
158 
165 void
166 FONcFloat::dump( ostream &strm ) const
167 {
168  strm << BESIndent::LMarg << "FONcFloat::dump - ("
169  << (void *)this << ")" << endl ;
170  BESIndent::Indent() ;
171  strm << BESIndent::LMarg << "name = " << _f->name() << endl ;
172  BESIndent::UnIndent() ;
173 }
174 
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:64
virtual void define(int ncid)
Define the variable in the netcdf file.
Definition: FONcBaseType.cc:60
virtual nc_type type()
returns the netcdf type of the DAP Float32
Definition: FONcFloat.cc:154
virtual void write(int ncid)
Write the float out to the netcdf file.
Definition: FONcFloat.cc:114
virtual string name()
returns the name of the DAP Float32
Definition: FONcFloat.cc:144
FONcFloat(libdap::BaseType *b)
Constructor for FONcFloat that takes a DAP Float32.
Definition: FONcFloat.cc:48
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcFloat.cc:166
virtual void define(int ncid)
define the DAP Float32 in the netcdf file
Definition: FONcFloat.cc:80
virtual ~FONcFloat()
Destructor that cleans up this instance.
Definition: FONcFloat.cc:65
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
Definition: FONcUtils.cc:424