44#include "FONcUShort.h"
48#include "FONcUInt64.h"
50#include "FONcDouble.h"
51#include "FONcStructure.h"
54#include "FONcSequence.h"
56#include <BESInternalError.h>
58#include <libdap/D4Dimensions.h>
70 FONcArray::Dimensions.clear();
72 FONcDim::DimNameNum = 0;
87 string allowed =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+_.@";
90 string first =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
92 string::size_type i = 0;
94 while ((i = in.find_first_not_of(allowed, i)) != string::npos) {
95 in.replace(i, 1,
"_");
99 if (first.find(in[0]) == string::npos) {
114 nc_type x_type = NC_NAT;
116 string var_type = element->type_name();
117 BESDEBUG(
"fonc",
"FONcUtils() - var_type "<< var_type <<endl);
118 BESDEBUG(
"fonc",
"FONcUtils() - var_name "<< element->name() <<endl);
119 if (var_type ==
"Byte" || var_type ==
"UInt8") {
125 else if(var_type ==
"Int8")
127 else if (var_type ==
"String")
129 else if (var_type ==
"Int16")
131 else if (var_type ==
"UInt16"){
137 else if (var_type ==
"Int32")
139 else if (var_type ==
"UInt32"){
144 else if (var_type ==
"Int64") {
149 else if (var_type ==
"UInt64"){
154 else if (var_type ==
"Float32")
156 else if (var_type ==
"Float64")
159 BESDEBUG(
"fonc",
"FONcUtils() - var_type returned"<< x_type <<endl);
182 vector<string>::const_iterator i = embed.begin();
183 vector<string>::const_iterator e = embed.end();
185 for (; i != e; i++) {
189 new_name += FONC_EMBEDDED_SEPARATOR + (*i);
195 new_name += FONC_EMBEDDED_SEPARATOR + name;
215FONcUtils::convert(BaseType *v,
const string &ncdf_version,
const bool is_classic_model) {
216 map<string,int>fdimname_to_id;
218 return convert(v, ncdf_version, is_classic_model,fdimname_to_id,rds_nums);
254FONcUtils::convert(BaseType *v,
255 const string &ncdf_version,
256 const bool is_classic_model,
257 map<string,int>&fdimname_to_id,
258 vector<int>&rds_nums)
263 bool is_netcdf4_enhanced =
false;
264 if(ncdf_version == FONC_RETURN_AS_NETCDF4 && is_classic_model ==
false)
265 is_netcdf4_enhanced =
true;
267 bool unsigned_promote =
true;
276 if(
true == is_netcdf4_enhanced)
287 case dods_uint16_c: {
288 if(
true == is_netcdf4_enhanced)
291 b =
new FONcInt(v,unsigned_promote);
297 case dods_uint32_c: {
298 if(
true == is_netcdf4_enhanced)
301 string err = (string)
"file out netcdf, " +
"classic model-doesn't support unsigned int.";
302 err +=
" Please use netCDF-4 enhanced model instead.";
310 case dods_uint64_c: {
311 if(
true == is_netcdf4_enhanced)
314 string err = (string)
"file out netcdf, " +
"classic model-doesn't support unsigned 64-bit int.";
315 err +=
" Please use netCDF-4 enhanced model instead.";
321 if(
true == is_netcdf4_enhanced)
324 string err = (string)
"file out netcdf, " +
"classic model-doesn't support unsigned 64-bit int.";
325 err +=
" Please use netCDF-4 enhanced model instead.";
343 if(fdimname_to_id.size()>0) {
345 vector<bool> use_d4_dim_ids;
346 Array *t_a =
dynamic_cast<Array *
>(v);
347 Array::Dim_iter di = t_a->dim_begin();
348 Array::Dim_iter de = t_a->dim_end();
356 for (; di != de; di++) {
358 D4Dimension * d4_dim = t_a->dimension_D4dim(di);
360 BESDEBUG(
"fonc",
"FONcArray() - constructor is dap4: dimension name is "<< d4_dim->name() <<endl);
361 if(fdimname_to_id.find(d4_dim->fully_qualified_name())!= fdimname_to_id.end()) {
362 int dim_id = fdimname_to_id[d4_dim->fully_qualified_name()];
363 dim_ids.push_back(dim_id);
364 use_d4_dim_ids.push_back(
true);
367 dim_ids.push_back(0);
368 use_d4_dim_ids.push_back(
false);
372 dim_ids.push_back(0);
373 use_d4_dim_ids.push_back(
false);
377 b =
new FONcArray(v,dim_ids,use_d4_dim_ids,rds_nums);
384 case dods_structure_c:
387 case dods_sequence_c:
391 string err = (string)
"file out netcdf, unable to " +
"write unknown variable type";
397 if(ncdf_version == FONC_RETURN_AS_NETCDF4) {
426 assert(stax != NC_NOERR);
exception thrown if internal error encountered
A DAP Array with file out netcdf information included.
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.
A DAP Float64 with file out netcdf information included.
A DAP Float32 with file out netcdf information included.
A DAP Grid with file out netcdf information included.
static vector< FONcMap * > Maps
global list of maps that could be shared amongst the different grids
A DAP Int64 with file out netcdf information included.
A class representing the DAP4 int8 class for file out netcdf.
A DAP Int32 and UInt32 with file out netcdf information included.
A DAP Sequence with file out netcdf information included.
A DAP Int16 and UInt16 with file out netcdf information included.
A class representing the DAP Str class for file out netcdf.
A DAP Structure with file out netcdf information included.
A class representing the DAP Byte class for file out netcdf.
A DAP UInt32 with file out netcdf information included.
A DAP UInt32 with file out netcdf information included.
A DAP UInt16 with file out netcdf information included.
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