40#include "config_hdf.h"
47#ifdef HAVE_SYS_PARAM_H
55#include <libdap/escaping.h>
56#include <libdap/Error.h>
57#include <libdap/debug.h>
66HDFArray::HDFArray(
const string &n,
const string &d, BaseType * v) :
70HDFArray::~HDFArray() {
73BaseType *HDFArray::ptr_duplicate() {
80bool HDFArray::read() {
82 int status = read_tagref(-1, -1, err);
85 throw Error(unknown_error,
"Could not read from dataset.");
92bool HDFArray::read_tagref(int32 tag, int32 ref,
int &err) {
97 string hdf_file = dataset();
98 string hdf_name = this->name();
101 vector<int> start, edge, stride;
102 bool isslab = GetSlabConstraint(start, edge, stride);
104 bool foundsds =
false;
106 if (tag == -1 || tag == DFTAG_NDG) {
107 if (SDSExists(hdf_file.c_str(), hdf_name.c_str())) {
110 BESDEBUG(
"h4",
"sds seek with ref = " << ref << endl);
113 BESDEBUG(
"h4",
"sds seek with name = '" << hdf_name <<
"'" << endl);
114 sdsin.seek(hdf_name.c_str());
117 sdsin.setslab(start, edge, stride,
false);
124 bool foundgr =
false;
126 if (!foundsds && (tag == -1 || tag == DFTAG_VG)) {
127 if (GRExists(hdf_file.c_str(), hdf_name.c_str())) {
132 grin.seek(hdf_name.c_str());
134 grin.setslab(start, edge, stride,
false);
143 LoadArrayFromSDS(
this, sds);
145 LoadArrayFromGR(
this, gr);
147 if (foundgr || foundsds) {
159bool HDFArray::GetSlabConstraint(vector<int>&start_array,
160 vector<int>&edge_array, vector<int>&stride_array) {
161 int start = 0, stop = 0, stride = 0;
164 start_array = vector<int> (0);
165 edge_array = vector<int> (0);
166 stride_array = vector<int> (0);
168 for (Array::Dim_iter p = dim_begin(); p != dim_end(); ++p) {
169 start = dimension_start(p,
true);
170 stride = dimension_stride(p,
true);
171 stop = dimension_stop(p,
true);
172 if (start == 0 && stop == 0 && stride == 0)
176 edge = (
int) ((stop - start) / stride) + 1;
177 if (start + edge > dimension_size(p))
180 start_array.push_back(start);
181 edge_array.push_back(edge);
182 stride_array.push_back(stride);
209 BESDEBUG(
"h4",
"Transferring attributes for " << name() << endl);
211 BaseType::transfer_attributes(at);
213 BESDEBUG(
"h4",
"...Now looking for the " << name() <<
" _dim_n containers." << endl);
216 string dim_name_base = name() +
"_dim_";
218 AttrTable::Attr_iter a_p = at->attr_begin();
219 while (a_p != at->attr_end()) {
220 string::size_type i = at->get_name(a_p).find(dim_name_base);
224 if (i == 0 && at->get_attr_type(a_p) == Attr_container) {
225 AttrTable *dim = at->get_attr_table(a_p);
227 BESDEBUG(
"h4",
"Found a dimension container for " << name() << endl);
228 transfer_dimension_attribute(dim);
231 BESDEBUG(
"h4",
"Caught an error transferring dimension attribute " << dim->get_name() <<
" for variable " << name() << endl);
240void HDFArray::transfer_dimension_attribute(AttrTable *dim) {
242 dim->set_is_global_attribute(
false);
244 AttrTable *at =
new AttrTable(*dim);
246 string name = at->get_name().substr(at->get_name().find(
"dim"));
247 get_attr_table().append_container(at, name);
virtual void transfer_attributes(libdap::AttrTable *at_container)