11#include "HDFDMRArray_SDS.h"
16#include <libdap/debug.h>
17#include <libdap/InternalErr.h>
25HDFDMRArray_SDS::read ()
28 BESDEBUG(
"h4",
"Coming to HDFDMRArray_SDS read "<<endl);
34 offset.resize(sds_rank);
36 count.resize(sds_rank);
38 step.resize(sds_rank);
41 int nelms = format_constraint(offset.data(),step.data(),count.data());
42 BESDEBUG(
"h4",
"Coming to HDFDMRArray_SDS read "<<endl);
44 int32 sdid = SDstart (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
47 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
48 throw InternalErr (__FILE__, __LINE__, eherr.str ());
51 BESDEBUG(
"h4",
"Coming to HDFDMRArray_SDS read "<<endl);
52 BESDEBUG(
"h4",
"After SDstart "<<endl);
54 int32 sdsindex = SDreftoindex (sdid, sds_ref);
58 eherr <<
"SDS index " << sdsindex <<
" is not right.";
59 throw InternalErr (__FILE__, __LINE__, eherr.str ());
63 int32 sdsid = SDselect (sdid, sdsindex);
67 eherr <<
"SDselect failed.";
68 throw InternalErr (__FILE__, __LINE__, eherr.str ());
72 buf.resize(nelms*sds_typesize);
74 int32 r = SDreaddata (sdsid, offset.data(), step.data(), count.data(), buf.data());
79 eherr <<
"SDreaddata failed";
80 throw InternalErr (__FILE__, __LINE__, eherr.str ());
93HDFDMRArray_SDS::format_constraint (
int *offset,
int *step,
int *count)
98 Dim_iter p = dim_begin ();
99 while (p != dim_end ()) {
101 int start = dimension_start (p,
true);
102 int stride = dimension_stride (p,
true);
103 int stop = dimension_stop (p,
true);
108 oss <<
"Array/Grid hyperslab start point "<< start <<
109 " is greater than stop point " << stop <<
".";
110 throw Error(malformed_expr, oss.str());
115 count[id] = ((stop - start) / stride) + 1;
119 "=format_constraint():"
120 <<
"id=" <<
id <<
" offset=" << offset[
id]
121 <<
" step=" << step[
id]
122 <<
" count=" << count[
id]