bes  Updated for version 3.20.6
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 <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  FONcAttributes::add_variable_attributes( ncid, _varid, _f ) ;
88  _varname, _orig_varname ) ;
89 
90  _defined = true ;
91  }
92 }
93 
103 void
104 FONcFloat::write( int ncid )
105 {
106  BESDEBUG( "fonc", "FONcFloat::write for var " << _varname << endl ) ;
107  size_t var_index[] = {0} ;
108  float *data = new float ;
109  _f->buf2val( (void**)&data ) ;
110  int stax = nc_put_var1_float( ncid, _varid, var_index, data ) ;
111  ncopts = NC_VERBOSE ;
112  if( stax != NC_NOERR )
113  {
114  string err = (string)"fileout.netcdf - "
115  + "Failed to write float data for "
116  + _varname ;
117  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
118  }
119  delete data ;
120  BESDEBUG( "fonc", "FONcFloat::done write for var " << _varname << endl ) ;
121 }
122 
127 string
129 {
130  return _f->name() ;
131 }
132 
137 nc_type
139 {
140  return NC_FLOAT ;
141 }
142 
149 void
150 FONcFloat::dump( ostream &strm ) const
151 {
152  strm << BESIndent::LMarg << "FONcFloat::dump - ("
153  << (void *)this << ")" << endl ;
154  BESIndent::Indent() ;
155  strm << BESIndent::LMarg << "name = " << _f->name() << endl ;
156  BESIndent::UnIndent() ;
157 }
158 
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
FONcFloat::FONcFloat
FONcFloat(BaseType *b)
Constructor for FONcFloat that takes a DAP Float32.
Definition: FONcFloat.cc:48
FONcFloat::write
virtual void write(int ncid)
Write the float out to the netcdf file.
Definition: FONcFloat.cc:104
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
FONcFloat::~FONcFloat
virtual ~FONcFloat()
Destructor that cleans up this instance.
Definition: FONcFloat.cc:65
FONcFloat::define
virtual void define(int ncid)
define the DAP Float32 in the netcdf file
Definition: FONcFloat.cc:80
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
FONcFloat::type
virtual nc_type type()
returns the netcdf type of the DAP Float32
Definition: FONcFloat.cc:138
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
FONcFloat::name
virtual string name()
returns the name of the DAP Float32
Definition: FONcFloat.cc:128
FONcFloat::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcFloat.cc:150