OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDF5BaseArray.cc
Go to the documentation of this file.
1 // This file is part of hdf5_handler an HDF5 file handler for the OPeNDAP
2 // data server.
3 
4 // Author: Muqun Yang <myang6@hdfgroup.org>
5 
6 // Copyright (c) 2011-2013 The HDF Group, Inc. and OPeNDAP, Inc.
7 //
8 // This is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License as published by the Free
10 // Software Foundation; either version 2.1 of the License, or (at your
11 // option) any later version.
12 //
13 // This software is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 // License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
24 // Suite 203, Champaign, IL 61820
41 
42 #include <iostream>
43 #include <sstream>
44 #include <cassert>
45 #include <debug.h>
46 #include "InternalErr.h"
47 #include <BESDebug.h>
48 
49 #include "HDF5BaseArray.h"
50 
51 
52 
54 {
55  return new HDF5BaseArray(*this);
56 }
57 
58 // Always return true.
59 // Data will be read from the missing coordinate variable class(HDF5GMCFMissNonLLCVArray etc.)
61 {
62  BESDEBUG("h5","Coming to HDF5BaseArray read "<<endl);
63  return true;
64 }
65 
66 
67 // parse constraint expr. and make hdf5 coordinate point location.
68 // return number of elements to read.
69 int
70 HDF5BaseArray::format_constraint (int *offset, int *step, int *count)
71 {
72  long nels = 1;
73  int id = 0;
74 
75  Dim_iter p = dim_begin ();
76 
77  while (p != dim_end ()) {
78 
79  int start = dimension_start (p, true);
80  int stride = dimension_stride (p, true);
81  int stop = dimension_stop (p, true);
82 
83 
84  // Check for illegical constraint
85  if (stride < 0 || start < 0 || stop < 0 || start > stop) {
86  ostringstream oss;
87  oss << "Array/Grid hyperslab indices are bad: [" << start <<
88  ":" << stride << ":" << stop << "]";
89  throw Error (malformed_expr, oss.str ());
90  }
91 
92  // Check for an empty constraint and use the whole dimension if so.
93  if (start == 0 && stop == 0 && stride == 0) {
94  start = dimension_start (p, false);
95  stride = dimension_stride (p, false);
96  stop = dimension_stop (p, false);
97  }
98 
99  offset[id] = start;
100  step[id] = stride;
101  count[id] = ((stop - start) / stride) + 1; // count of elements
102  nels *= count[id]; // total number of values for variable
103 
104  BESDEBUG ("h5",
105  "=format_constraint():"
106  << "id=" << id << " offset=" << offset[id]
107  << " step=" << step[id]
108  << " count=" << count[id]
109  << endl);
110 
111  id++;
112  p++;
113  }// while (p != dim_end ())
114 
115  return nels;
116 }
117 
118 void HDF5BaseArray::write_nature_number_buffer(int rank, int tnumelm) {
119 
120  if (rank != 1)
121  throw InternalErr(__FILE__, __LINE__, "Currently the rank of the missing field should be 1");
122 
123  vector<int>offset;
124  vector<int>count;
125  vector<int>step;
126  offset.resize(rank);
127  count.resize(rank);
128  step.resize(rank);
129 
130 
131  int nelms = format_constraint(&offset[0], &step[0], &count[0]);
132 
133  // Since we always assign the the missing Z dimension as 32-bit
134  // integer, so no need to check the type. The missing Z-dim is always
135  // 1-D with natural number 1,2,3,....
136  vector<int>val;
137  val.resize(nelms);
138 
139  if (nelms == tnumelm) {
140  for (int i = 0; i < nelms; i++)
141  val[i] = i;
142  set_value((dods_int32 *) &val[0], nelms);
143  }
144  else {
145  for (int i = 0; i < count[0]; i++)
146  val[i] = offset[0] + step[0] * i;
147  set_value((dods_int32 *) &val[0], nelms);
148  }
149 }
150 
151 
virtual BaseType * ptr_duplicate()
HDF5BaseArray(const string &n="", BaseType *v=0)
Definition: HDF5BaseArray.h:57
int format_constraint(int *cor, int *step, int *edg)
virtual bool read()
void write_nature_number_buffer(int rank, int tnumelm)
A helper class that aims to reduce code redundence for different special CF derived array class For e...
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64