41 static char rcsid[]
not_used ={
"$Id$"};
48 #include <D4Attributes.h>
50 #include <InternalErr.h>
80 dynamic_cast<Structure&
>(*this) = rhs;
88 class AddAttribute:
public unary_function<BaseType *, void> {
93 void operator()(BaseType *a) {
95 AttrTable::Attr_iter aiter;
96 a->get_attr_table().find(
"translation", &at, &aiter);
97 if (a->get_attr_table().attr_end() == aiter) {
98 a->get_attr_table().append_attr(
"translation",
"String",
127 Vars_iter var = var_begin();
128 while (var != var_end()) {
129 (*var)->transfer_attributes(at);
150 Structure *dest =
new NCStructure(name(), dataset());
152 Constructor::transform_to_dap4(root, dest);
153 dest->set_parent(container);
158 void NCStructure::do_structure_read(
int ncid,
int varid, nc_type datatype,
159 vector<char> &values,
bool has_values,
int values_offset)
161 #if NETCDF_VERSION >= 4
163 char type_name[NC_MAX_NAME+1];
168 int errstat = nc_inq_user_type(ncid, datatype, type_name, &size, &base_type, &nfields, &class_type);
169 if (errstat != NC_NOERR)
170 throw InternalErr(__FILE__, __LINE__,
"Could not get information about a user-defined type (" + long_to_string(errstat) +
").");
172 switch (class_type) {
176 int errstat = nc_get_var(ncid, varid, &values[0] );
177 if (errstat != NC_NOERR)
178 throw Error(errstat,
string(
"Could not get the value for variable '") + name() +
string(
"'"));
182 for (
size_t i = 0; i < nfields; ++i) {
183 char field_name[NC_MAX_NAME+1];
184 nc_type field_typeid;
187 nc_inq_compound_field(ncid, datatype, i, field_name, &field_offset, &field_typeid, &field_ndims, 0);
192 nc_inq_compound_name(ncid, field_typeid, field_name);
194 ncs.do_structure_read(ncid, varid, field_typeid, values, has_values, field_offset + values_offset);
196 else if (var(field_name)->is_vector_type()) {
201 vector<size_t> cor(field_ndims);
202 vector<size_t> edg(field_ndims);
203 vector<ptrdiff_t> step(field_ndims);
205 long nels = child_array.format_constraint(&cor[0], &step[0], &edg[0], &has_stride);
206 child_array.do_array_read(ncid, varid, field_typeid,
207 values, has_values, field_offset + values_offset,
208 nels, &cor[0], &edg[0], &step[0], has_stride);
210 else if (var(field_name)->is_simple_type()) {
211 var(field_name)->val2buf(&values[0] + field_offset + values_offset);
214 throw InternalErr(__FILE__, __LINE__,
"Expecting a netcdf user defined type or an array or a scalar.");
217 var(field_name)->set_read_p(
true);
223 cerr <<
"in build_user_defined; found a vlen." << endl;
226 cerr <<
"in build_user_defined; found a opaque." << endl;
229 cerr <<
"in build_user_defined; found a enum." << endl;
232 throw InternalErr(__FILE__, __LINE__,
"Expected one of NC_COMPOUND, NC_VLEN, NC_OPAQUE or NC_ENUM");
236 throw InternalErr(__FILE__, __LINE__,
"Found a DAP Structure bound to a non-user-defined type in the netcdf file " + dataset());
238 throw InternalErr(__FILE__, __LINE__,
"Found a DAP Structure bound to a non-user-defined type in the netcdf file " + dataset());
248 int errstat = nc_open(dataset().c_str(), NC_NOWRITE, &ncid);
249 if (errstat != NC_NOERR)
250 throw Error(errstat,
"Could not open the dataset's file (" + dataset() +
")");
253 errstat = nc_inq_varid(ncid, name().c_str(), &varid);
254 if (errstat != NC_NOERR)
255 throw InternalErr(__FILE__, __LINE__,
"Could not get variable ID for: " + name() +
". (error: " + long_to_string(errstat) +
").");
258 errstat = nc_inq_vartype(ncid, varid, &datatype);
259 if (errstat != NC_NOERR)
260 throw Error(errstat,
"Could not read data type information about : " + name() +
". (error: " + long_to_string(errstat) +
").");
267 do_structure_read(ncid, varid, datatype, values,
false , 0 );
271 if (nc_close(ncid) != NC_NOERR)
272 throw InternalErr(__FILE__, __LINE__,
"Could not close the dataset!");
virtual BaseType * transform_to_dap4(D4Group *root, Constructor *container)
Custom version of the transform_to_dap4() method.
virtual void transfer_attributes(AttrTable *at)
Transfer attributes from a separately built DAS to the DDS.
NCStructure & operator=(const NCStructure &rhs)
NCStructure(const string &n, const string &d)
bool is_user_defined_type(int ncid, int type)
virtual BaseType * ptr_duplicate()