40#include "config_hdf.h"
45#ifdef HAVE_SYS_PARAM_H
52#include <libdap/Error.h>
53#include <libdap/InternalErr.h>
54#include <libdap/debug.h>
55#include <libdap/escaping.h>
66HDFGrid::HDFGrid(
const string &n,
const string &d) :
72BaseType *HDFGrid::ptr_duplicate() {
80vector<array_ce> HDFGrid::get_map_constraints() {
81 vector<array_ce> a_ce_vec;
84 for (Grid::Map_iter p = map_begin(); p != map_end(); ++p) {
85 Array & a =
static_cast<Array &
> (**p);
86 Array::Dim_iter q = a.dim_begin();
87 int start = a.dimension_start(q,
true);
88 int stop = a.dimension_stop(q,
true);
89 int stride = a.dimension_stride(q,
true);
90 int edge = (
int) ((stop - start) / stride) + 1;
91 array_ce a_ce(a.name(), start, edge, stride);
92 a_ce_vec.push_back(a_ce);
101 int status = read_tagref(-1, -1, err);
103 throw Error(unknown_error,
"Could not read from dataset.");
107bool HDFGrid::read_tagref(int32, int32 ref,
int &err) {
113 string hdf_file = dataset();
114 string hdf_name = this->name();
126 throw InternalErr(__FILE__, __LINE__,
"Expected an HDFArray.");
128 bool isslab = primary_array->GetSlabConstraint(start, edge, stride);
132 sdsin.setslab(start, edge, stride,
false);
135 sdsin.set_map_ce(get_map_constraints());
140 sdsin.seek(hdf_name.c_str());
143 if (array_var()->send_p() || array_var()->is_in_selection()) {
147 string(
"Could not read ") + array_var()->name()
148 +
string(
" from dataset ") + dataset()
152 LoadGridFromSDS(
this, sds);
162 if (!(array_var()->send_p() || array_var()->is_in_selection())) {
165 sds.dims = vector<hdf_dim> ();
171 for (Grid::Map_iter p = map_begin(); p != map_end(); ++p) {
172 if ((*p)->send_p() || (*p)->is_in_selection()) {
173 for (
unsigned int i = 0; i < sds.dims.size(); i++) {
174 if ((*p)->name() == sds.dims[i].name) {
176 char *data =
static_cast<char *
> (ExportDataForDODS(
180 (*p)->set_read_p(
true);
196void HDFGrid::transfer_attributes(AttrTable *at) {
198 array_var()->transfer_attributes(at);
200 Map_iter map = map_begin();
201 while (map != map_end()) {
202 (*map)->transfer_attributes(at);
206 AttrTable *mine = at->get_attr_table(name());
209 mine->set_is_global_attribute(
false);
210 AttrTable::Attr_iter at_p = mine->attr_begin();
211 while (at_p != mine->attr_end()) {
212 if (mine->get_attr_type(at_p) == Attr_container)
213 get_attr_table().append_container(
214 new AttrTable(*mine->get_attr_table(at_p)),
215 mine->get_name(at_p));
217 get_attr_table().append_attr(mine->get_name(at_p),
218 mine->get_type(at_p), mine->get_attr_vector(at_p));
225 string dim_name_base = name() +
"_dim_";
227 AttrTable::Attr_iter a_p = at->attr_begin();
228 while (a_p != at->attr_end()) {
229 string::size_type i = at->get_name(a_p).find(dim_name_base);
233 if (i == 0 && at->get_attr_type(a_p) == Attr_container) {
234 AttrTable *dim = at->get_attr_table(a_p);
237 BESDEBUG(
"h4",
"dim->name(): " << dim->get_name() << endl);
238 BESDEBUG(
"h4",
"dim->get_name().substr(i + dim_name_base.length()): "
239 << dim->get_name().substr(i + dim_name_base.length()) << endl);
240 int n = atoi(dim->get_name().substr(i + dim_name_base.length()).c_str());
243 BESDEBUG(
"h4",
"Inside HDFGrid::transfer_attreibutes: n = " << n << endl);
244 static_cast<HDFArray&
> (*(*(map_begin() + n))).transfer_dimension_attribute(dim);