bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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 <libdap/Float64.h>
35
36#include "FONcDouble.h"
37#include "FONcUtils.h"
38#include "FONcAttributes.h"
39
49 : FONcBaseType(), _f(0) {
50 _f = dynamic_cast<Float64 *>(b);
51 if (!_f) {
52 string s = (string) "File out netcdf, FONcDouble was passed a "
53 + "variable that is not a DAP Float64";
54 throw BESInternalError(s, __FILE__, __LINE__);
55 }
56}
57
68void
71
72 if (!d_defined) {
73
74 if (d_is_dap4) {
75 D4Attributes *d4_attrs = _f->attributes();
76 updateD4AttrType(d4_attrs, NC_DOUBLE);
77 }
78 else {
79 AttrTable &attrs = _f->get_attr_table();
80 updateAttrType(attrs, NC_DOUBLE);
81 }
82
83 FONcAttributes::add_variable_attributes(ncid, d_varid, _f, isNetCDF4_ENHANCED(), d_is_dap4);
84 FONcAttributes::add_original_name(ncid, d_varid, d_varname, d_orig_varname);
85
86 d_defined = true;
87 }
88}
89
97void
99 BESDEBUG("fonc", "FONcDouble::write for var " << d_varname << endl);
100
101 if (d_is_dap4)
102 _f->intern_data();
103 else
104 _f->intern_data(*get_eval(), *get_dds());
105
106 double data = _f->value();
107 size_t var_index[] = {0};
108 int stax = nc_put_var1_double(ncid, d_varid, var_index, &data);
109 if (stax != NC_NOERR) {
110 string err = (string) "fileout.netcdf - "
111 + "Failed to write double data for "
112 + d_varname;
113 FONcUtils::handle_error(stax, err, __FILE__, __LINE__);
114 }
115
116 BESDEBUG("fonc", "FONcDouble::done write for var " << d_varname << endl);
117}
118
125void
127 strm << BESIndent::LMarg << "FONcDouble::dump - ("
128 << (void *) this << ")" << endl;
129 BESIndent::Indent();
130 strm << BESIndent::LMarg << "name = " << _f->name() << endl;
131 BESIndent::UnIndent();
132}
133
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.
virtual void dump(ostream &strm) const override
dumps information about this object for debugging purposes
virtual void write(int ncid) override
Write the float64 out to the netcdf file.
Definition FONcDouble.cc:98
virtual void define(int ncid) override
define the DAP Float64 in the netcdf file
Definition FONcDouble.cc:69
FONcDouble(libdap::BaseType *b)
Constructor for FOncDouble that takes a DAP Float64.
Definition FONcDouble.cc:48
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.