bes  Updated for version 3.20.6
FONcDouble.cc
1 // FONcDouble.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 <Float64.h>
35 
36 #include "FONcDouble.h"
37 #include "FONcUtils.h"
38 #include "FONcAttributes.h"
39 
48 FONcDouble::FONcDouble( BaseType *b )
49  : FONcBaseType(), _f( 0 )
50 {
51  _f = dynamic_cast<Float64 *>(b) ;
52  if( !_f )
53  {
54  string s = (string)"File out netcdf, FONcDouble was passed a "
55  + "variable that is not a DAP Float64" ;
56  throw BESInternalError( s, __FILE__, __LINE__ ) ;
57  }
58 }
59 
65 {
66 }
67 
78 void
79 FONcDouble::define( int ncid )
80 {
81  FONcBaseType::define( ncid ) ;
82 
83  if( !_defined )
84  {
85  FONcAttributes::add_variable_attributes( ncid, _varid, _f ) ;
87  _varname, _orig_varname ) ;
88 
89  _defined = true ;
90  }
91 }
92 
100 void
101 FONcDouble::write( int ncid )
102 {
103  BESDEBUG( "fonc", "FONcDouble::write for var " << _varname << endl ) ;
104  size_t var_index[] = {0} ;
105  double *data = new double ;
106  _f->buf2val( (void**)&data ) ;
107  int stax = nc_put_var1_double( ncid, _varid, var_index, data ) ;
108  if( stax != NC_NOERR )
109  {
110  string err = (string)"fileout.netcdf - "
111  + "Failed to write double data for "
112  + _varname ;
113  FONcUtils::handle_error( stax, err, __FILE__, __LINE__ ) ;
114  }
115  delete data ;
116  BESDEBUG( "fonc", "FONcDouble::done write for var " << _varname << endl ) ;
117 }
118 
123 string
125 {
126  return _f->name() ;
127 }
128 
133 nc_type
135 {
136  return NC_DOUBLE ;
137 }
138 
145 void
146 FONcDouble::dump( ostream &strm ) const
147 {
148  strm << BESIndent::LMarg << "FONcDouble::dump - ("
149  << (void *)this << ")" << endl ;
150  BESIndent::Indent() ;
151  strm << BESIndent::LMarg << "name = " << _f->name() << endl ;
152  BESIndent::UnIndent() ;
153 }
154 
FONcDouble::~FONcDouble
virtual ~FONcDouble()
Destructor that cleans up the instance.
Definition: FONcDouble.cc:64
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
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
FONcDouble::type
virtual nc_type type()
returns the netcdf type of the DAP Float64
Definition: FONcDouble.cc:134
FONcDouble::write
virtual void write(int ncid)
Write the float64 out to the netcdf file.
Definition: FONcDouble.cc:101
FONcDouble::dump
virtual void dump(ostream &strm) const
dumps information about this object for debugging purposes
Definition: FONcDouble.cc:146
FONcDouble::define
virtual void define(int ncid)
define the DAP Float64 in the netcdf file
Definition: FONcDouble.cc:79
FONcDouble::FONcDouble
FONcDouble(BaseType *b)
Constructor for FOncDouble that takes a DAP Float64.
Definition: FONcDouble.cc:48
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
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
FONcDouble::name
virtual string name()
returns the name of the DAP Float64
Definition: FONcDouble.cc:124