40#include "config_hdf.h"
47#ifdef HAVE_SYS_PARAM_H
54#include <libdap/Error.h>
55#include <libdap/escaping.h>
56#include <libdap/Sequence.h>
57#include <libdap/Array.h>
58#include <libdap/util.h>
59#include <libdap/debug.h>
62#include "HDFStructure.h"
67HDFStructure::HDFStructure(
const string &n,
const string &d) :
71HDFStructure::~HDFStructure() =
default;
73BaseType *HDFStructure::ptr_duplicate() {
74 return new HDFStructure(*
this);
77 const string & hdf_file);
79void HDFStructure::set_read_p(
bool state) {
81 BaseType::set_read_p(state);
84bool HDFStructure::read_from_value(vector<uint8_t> &values,
size_t &values_offset) {
87 Constructor::Vars_iter vi = this->var_begin();
88 Constructor::Vars_iter ve = this->var_end();
90 for (; vi != ve; vi++) {
93 for (
auto &bt:this->variables()) {
94 Type t_bt = bt->type();
95 if (libdap::is_simple_type(t_bt) && t_bt != dods_str_c && t_bt != dods_url_c && t_bt!= dods_enum_c && t_bt!=dods_opaque_c) {
98 if(t_bt == dods_int32_c) {
101 BESDEBUG(
"dmrpp",
"int value is: " << *((dods_int32*)(values.data()+values_offset)) <<
"'" << endl);
103 else if (t_bt == dods_float32_c) {
106 BESDEBUG(
"dmrpp",
"float value is: " << *((dods_float32*)(values.data()+values_offset)) <<
"'" << endl);
109 bt->val2buf(values.data() + values_offset);
112 bt->val2buf(values.data() + values_offset);
113 bt->set_read_p(
true);
114 values_offset += bt->width_ll();
117 else if (t_bt == dods_array_c) {
119 auto t_a =
dynamic_cast<Array *
>(bt);
120 Type t_array_var = t_a->var()->type();
121 if (libdap::is_simple_type(t_array_var) && t_array_var != dods_str_c && t_array_var != dods_url_c && t_array_var!= dods_enum_c && t_array_var!=dods_opaque_c) {
122 t_a->val2buf(values.data()+values_offset);
123 t_a->set_read_p(
true);
125 values_offset +=t_a->width_ll();
128 throw InternalErr(__FILE__, __LINE__,
"The base type of this structure is not integer or float. Currently it is not supported.");
131 throw InternalErr(__FILE__, __LINE__,
"The base type of this structure is not integer or float. Currently it is not supported.");
136bool HDFStructure::read() {
138 int status = read_tagref(-1, -1, err);
140 throw Error(unknown_error,
"Could not read from dataset.");
148bool HDFStructure::read_tagref(int32 , int32 ref,
int &err) {
153 string hdf_file = dataset();
154 string hdf_name = this->name();
156 BESDEBUG(
"h4",
" hdf_name = " << hdf_name << endl);
163 hdfistream_vgroup vgin(hdf_file.c_str());
167 vgin.seek(hdf_name.c_str());
173 LoadStructureFromVgroup(
this, vgroup, hdf_file);
205 BESDEBUG(
"h4",
"Entering HDFStructure::transfer_attributes for variable " << name() << endl);
208 Vars_iter var = var_begin();
209 while (var != var_end()) {
211 BESDEBUG(
"h4",
"Processing the attributes for: " << (*var)->name() <<
" a " << (*var)->type_name() << endl);
212 (*var)->transfer_attributes(at);
215 BESDEBUG(
"h4",
"Got this exception: " << e.get_error_message() << endl);
221 AttrTable *mine = at->get_attr_table(name());
224 mine->set_is_global_attribute(
false);
225 AttrTable::Attr_iter at_p = mine->attr_begin();
226 while (at_p != mine->attr_end()) {
227 if (mine->get_attr_type(at_p) == Attr_container)
228 get_attr_table().append_container(
new AttrTable(*mine->get_attr_table(at_p)), mine->get_name(at_p));
230 get_attr_table().append_attr(mine->get_name(at_p), mine->get_type(at_p), mine->get_attr_vector(at_p));
void transfer_attributes(libdap::AttrTable *at_container) override