44#include "FONcUShort.h"
48#include "FONcUInt64.h"
50#include "FONcDouble.h"
51#include "FONcStructure.h"
52#include "FONcArrayStructure.h"
53#include "FONcArrayStructureField.h"
56#include "FONcSequence.h"
58#include <BESInternalError.h>
60#include <libdap/D4Dimensions.h>
72 FONcArray::Dimensions.clear();
74 FONcDim::DimNameNum = 0;
75 FONcDim::StructDimNameNum = 0;
90 string allowed =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+_.@";
93 string first =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
95 string::size_type i = 0;
97 while ((i = in.find_first_not_of(allowed, i)) != string::npos) {
98 in.replace(i, 1,
"_");
102 if (first.find(in[0]) == string::npos) {
117 nc_type x_type = NC_NAT;
119 string var_type = element->type_name();
120 BESDEBUG(
"fonc",
"FONcUtils() - var_type "<< var_type <<endl);
121 BESDEBUG(
"fonc",
"FONcUtils() - var_name "<< element->name() <<endl);
122 if (var_type ==
"Byte" || var_type ==
"UInt8") {
128 else if(var_type ==
"Int8")
130 else if (var_type ==
"String")
132 else if (var_type ==
"Int16")
134 else if (var_type ==
"UInt16"){
140 else if (var_type ==
"Int32")
142 else if (var_type ==
"UInt32"){
147 else if (var_type ==
"Int64") {
152 else if (var_type ==
"UInt64"){
157 else if (var_type ==
"Float32")
159 else if (var_type ==
"Float64")
162 BESDEBUG(
"fonc",
"FONcUtils() - var_type returned"<< x_type <<endl);
188 for (; i != e; i++) {
192 new_name += FONC_EMBEDDED_SEPARATOR + (*i);
198 new_name += FONC_EMBEDDED_SEPARATOR + name;
218FONcUtils::convert(BaseType *v,
const string &ncdf_version,
const bool is_classic_model) {
221 return convert(v, ncdf_version, is_classic_model,fdimname_to_id,rds_nums);
257FONcUtils::convert(BaseType *v,
258 const string &ncdf_version,
259 const bool is_classic_model,
263 FONcBaseType *b =
nullptr;
266 bool is_netcdf4_enhanced =
false;
267 if(ncdf_version == FONC_RETURN_AS_NETCDF4 && is_classic_model ==
false)
268 is_netcdf4_enhanced =
true;
270 bool unsigned_promote =
true;
272 if (v->type()==dods_array_c && v->var()->type()==dods_structure_c)
273 b =
new FONcArrayStructure(v);
282 if (
true == is_netcdf4_enhanced)
283 b =
new FONcUByte(v);
285 b =
new FONcShort(v, unsigned_promote);
293 case dods_uint16_c: {
294 if (
true == is_netcdf4_enhanced)
295 b =
new FONcUShort(v);
297 b =
new FONcInt(v, unsigned_promote);
301 b =
new FONcShort(v);
303 case dods_uint32_c: {
304 if (
true == is_netcdf4_enhanced)
307 string err = (string)
"file out netcdf, " +
"classic model-doesn't support unsigned int.";
308 err +=
" Please use netCDF-4 enhanced model instead.";
309 throw BESInternalError(err, __FILE__, __LINE__);
316 case dods_uint64_c: {
317 if (
true == is_netcdf4_enhanced)
318 b =
new FONcUInt64(v);
320 string err = (string)
"file out netcdf, " +
"classic model-doesn't support unsigned 64-bit int.";
321 err +=
" Please use netCDF-4 enhanced model instead.";
322 throw BESInternalError(err, __FILE__, __LINE__);
327 if (
true == is_netcdf4_enhanced)
328 b =
new FONcInt64(v);
330 string err = (string)
"file out netcdf, " +
"classic model-doesn't support unsigned 64-bit int.";
331 err +=
" Please use netCDF-4 enhanced model instead.";
332 throw BESInternalError(err, __FILE__, __LINE__);
337 b =
new FONcFloat(v);
340 b =
new FONcDouble(v);
349 if (fdimname_to_id.size() > 0) {
351 vector<bool> use_d4_dim_ids;
352 Array *t_a =
dynamic_cast<Array *
>(v);
353 Array::Dim_iter di = t_a->dim_begin();
354 Array::Dim_iter de = t_a->dim_end();
362 for (; di != de; di++) {
364 D4Dimension *d4_dim = t_a->dimension_D4dim(di);
367 "FONcArray() - constructor is dap4: dimension name is " << d4_dim->name() << endl);
368 if (fdimname_to_id.find(d4_dim->fully_qualified_name()) != fdimname_to_id.end()) {
369 int dim_id = fdimname_to_id[d4_dim->fully_qualified_name()];
370 dim_ids.push_back(dim_id);
371 use_d4_dim_ids.push_back(
true);
373 dim_ids.push_back(0);
374 use_d4_dim_ids.push_back(
false);
377 dim_ids.push_back(0);
378 use_d4_dim_ids.push_back(
false);
382 b =
new FONcArray(v, dim_ids, use_d4_dim_ids, rds_nums);
385 b =
new FONcArray(v);
388 case dods_structure_c:
389 b =
new FONcStructure(v);
391 case dods_sequence_c:
392 b =
new FONcSequence(v);
395 string err = (string)
"file out netcdf, unable to " +
"write unknown variable type";
396 throw BESInternalError(err, __FILE__, __LINE__);
402 if(ncdf_version == FONC_RETURN_AS_NETCDF4) {
431 assert(stax != NC_NOERR);
exception thrown if internal error encountered
A DAP BaseType with file out netcdf information included.
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 vector< FONcMap * > Maps
global list of maps that could be shared amongst the different grids
static void handle_error(int stax, const string &err, const string &file, int line)
handle any netcdf errors
static string name_prefix
If a variable name, dimension name, or attribute name begins with a character that is not supported b...
static void reset()
Resets the FONc transformation for a new input and out file.
static nc_type get_nc_type(libdap::BaseType *element, bool isNC4_ENHANCED)
translate the OPeNDAP data type to a netcdf data type
static string id2netcdf(string in)
convert the provided string to a netcdf allowed identifier.
static string gen_name(const vector< string > &embed, const string &name, string &original)
generate a new name for the embedded variable