32#include <libdap/D4Attributes.h>
34#include <BESInternalError.h>
37#include "FONcBaseType.h"
42void FONcBaseType::convert(
const vector<string> embed,
bool _dap4,
bool dap4_group)
46 d_is_dap4_group = dap4_group;
64 BESDEBUG(
"fonc",
"FONcBaseType::define - defining '" << d_varname <<
"'" << endl);
65 int stax = nc_def_var(ncid, d_varname.c_str(),
type(), 0,
nullptr, &d_varid);
66 if (stax != NC_NOERR) {
67 string err = (
string)
"fileout.netcdf - " +
"Failed to define variable " + d_varname;
70 stax = nc_def_var_fill(ncid, d_varid, NC_NOFILL, NULL );
71 if (stax != NC_NOERR) {
72 string err = (
string)
"fileout.netcdf - " +
"Failed to clear fill value for " + d_varname;
76 BESDEBUG(
"fonc",
"FONcBaseType::define - done defining " << d_varname << endl);
102 d_ncVersion = version;
104 BESDEBUG(
"fonc",
"FONcBaseType::setVersion() - version: '" << d_ncVersion <<
"'" << endl);
111 d_nc4_datamodel = nc4_datamodel;
113 BESDEBUG(
"fonc",
"FONcBaseType::setNC4DataModel() - data model: '" << d_nc4_datamodel <<
"'" << endl);
120 return FONcBaseType::d_ncVersion == FONC_RETURN_AS_NETCDF4;
123bool FONcBaseType::isNetCDF4_ENHANCED()
125 return FONcBaseType::d_nc4_datamodel == FONC_NC4_ENHANCED;
128void FONcBaseType::updateD4AttrType(libdap::D4Attributes *d4_attrs, nc_type t)
130 for (
auto ii = d4_attrs->attribute_begin(), ee = d4_attrs->attribute_end(); ii != ee; ++ii) {
131 if ((*ii)->name() == _FillValue) {
132 BESDEBUG(
"fonc",
"FONcBaseType - attrtype " << getD4AttrType(t) << endl);
133 BESDEBUG(
"fonc",
"FONcBaseType - attr_type " << (*ii)->type() << endl);
134 D4AttributeType correct_d4_attr_type = getD4AttrType(t);
135 if (correct_d4_attr_type != (*ii)->type())
136 (*ii)->set_type(correct_d4_attr_type);
144void FONcBaseType::updateAttrType(libdap::AttrTable &attrs, nc_type t)
146 if (attrs.get_size()) {
147 for (
auto iter = attrs.attr_begin(); iter != attrs.attr_end(); iter++) {
148 if (attrs.get_name(iter) == _FillValue) {
149 BESDEBUG(
"fonc",
"FONcBaseType - attrtype " << getAttrType(t) << endl);
150 BESDEBUG(
"fonc",
"FONcBaseType - attr_type " << attrs.get_attr_type(iter) << endl);
151 if (getAttrType(t) != attrs.get_attr_type(iter)) {
152 (*iter)->type = getAttrType(t);
163libdap::AttrType FONcBaseType::getAttrType(nc_type nct)
165 BESDEBUG(
"fonc",
"FONcArray getAttrType " << endl);
166 libdap::AttrType atype = Attr_unknown;
180 atype = Attr_float32;
183 atype = Attr_float64;
189 if (isNetCDF4_ENHANCED())
195 if (isNetCDF4_ENHANCED())
211D4AttributeType FONcBaseType::getD4AttrType(nc_type nct)
213 D4AttributeType atype = attr_null_c;
220 atype = attr_int16_c;
223 atype = attr_int32_c;
226 atype = attr_float32_c;
229 atype = attr_float64_c;
235 if (isNetCDF4_ENHANCED())
236 atype = attr_uint16_c;
238 atype = attr_int32_c;
241 if (isNetCDF4_ENHANCED())
242 atype = attr_uint32_c;
245 if (isNetCDF4_ENHANCED())
246 atype = attr_int64_c;
249 if (isNetCDF4_ENHANCED())
250 atype = attr_uint64_c;
259 if(atype == attr_null_c)
260 throw BESInternalError(
"Cannot convert unknown netCDF attribute type", __FILE__, __LINE__);
virtual void define(int ncid)
Define the variable in the netcdf file.
virtual bool isNetCDF4()
Returns true if NetCDF4 features will be required.
virtual nc_type type()
Returns the type of data of this variable.
virtual void clear_embedded()
Clears the list of embedded variable names.
virtual void setNC4DataModel(const string &nc4_datamodel)
Identifies the netCDF4 data model (CLASSIC or ENHANCED)
virtual void setVersion(const std::string &version)
Identifies variable with use of NetCDF4 features.
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
static string gen_name(const vector< string > &embed, const string &name, string &original)
generate a new name for the embedded variable