bes  Updated for version 3.20.10
HDF5GMCFFillIndexArray.cc
Go to the documentation of this file.
1 // This file is part of the hdf5_handler implementing for the CF-compliant
2 // Copyright (c) 2011-2016 The HDF Group, Inc. and OPeNDAP, Inc.
3 //
4 // This is free software; you can redistribute it and/or modify it under the
5 // terms of the GNU Lesser General Public License as published by the Free
6 // Software Foundation; either version 2.1 of the License, or (at your
7 // option) any later version.
8 //
9 // This software is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 // License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
19 // You can contact The HDF Group, Inc. at 1800 South Oak Street,
20 // Suite 203, Champaign, IL 61820
21 
29 
33 
34 #include "config_hdf5.h"
35 #include <iostream>
36 #include <sstream>
37 #include <cassert>
38 #include <BESDebug.h>
39 #include <libdap/InternalErr.h>
40 
41 #include <libdap/Str.h>
42 #include "HDF5GMCFFillIndexArray.h"
43 
44 using namespace std;
45 using namespace libdap;
46 
47 BaseType *HDF5GMCFFillIndexArray::ptr_duplicate()
48 {
49  return new HDF5GMCFFillIndexArray(*this);
50 }
51 
52 // Read in an HDF5 Array
53 bool HDF5GMCFFillIndexArray::read()
54 {
55 
56  BESDEBUG("h5","Coming to HDF5GMCFFillIndexArray read "<<endl);
57 
58  read_data_NOT_from_mem_cache(false,NULL);
59 
60  return true;
61 }
62 
63 
64 void HDF5GMCFFillIndexArray::read_data_NOT_from_mem_cache(bool /*add_cache*/,void*/*buf*/) {
65 
66 
67  BESDEBUG("h5","Coming to HDF5GMCFFillIndexArray: read_data_NOT_from_mem_cache"<<endl);
68 
69 
70  int nelms = 0;
71 
72 #if 0
73 cerr<<"coming to read function"<<endl;
74 cerr<<"file name " <<filename <<endl;
75 "h5","var name "<<varname <<endl;
76 #endif
77 
78  if (rank != 1)
79  throw InternalErr (__FILE__, __LINE__,
80  "Currently the rank of the dimension scale must be 1.");
81 
82  vector<int> offset;
83  offset.resize(rank);
84  vector<int>count;
85  count.resize(rank);
86  vector<int>step;
87  step.resize(rank);
88 
89  // Obtain the number of the subsetted elements
90  nelms = format_constraint (&offset[0], &step[0], &count[0]);
91 
92 
93  switch (dtype) {
94 
95  case H5UCHAR:
96 
97  {
98  vector<unsigned char> val;
99  val.resize(nelms);
100 
101  for (int i = 0; i < count[0]; i++)
102  val[i] = (unsigned char)(offset[0] + step[0] * i);
103 
104  set_value ((dods_byte *) &val[0], nelms);
105  } // case H5UCHAR
106  break;
107 
108 
109  // signed char maps to 16-bit integer in DAP2(HDF5 to DAP2 mapping document.)
110  case H5CHAR:
111  {
112  if(is_dap4 == false) {
113 
114  vector<short>val;
115  val.resize(nelms);
116 
117  for (int i = 0; i < count[0]; i++)
118  val[i] = (short)(offset[0] + step[0] * i);
119 
120  set_value ((dods_int16 *) &val[0], nelms);
121  }
122  else {
123 
124  vector<char> val;
125  val.resize(nelms);
126 
127  for (int i = 0; i < count[0]; i++)
128  val[i] = (char)(offset[0] + step[0] * i);
129 
130  set_value ((dods_int8 *) &val[0], nelms);
131 
132  }
133  }// H5CHAR and H5INT16
134  break;
135 
136 
137 
138  case H5INT16:
139  {
140 
141  vector<short>val;
142  val.resize(nelms);
143 
144  for (int i = 0; i < count[0]; i++)
145  val[i] = (short)(offset[0] + step[0] * i);
146 
147  set_value ((dods_int16 *) &val[0], nelms);
148  }// H5CHAR and H5INT16
149  break;
150 
151 
152  case H5UINT16:
153  {
154  vector<unsigned short> val;
155  val.resize(nelms);
156 
157  for (int i = 0; i < count[0]; i++)
158  val[i] = (unsigned short)(offset[0] + step[0] * i);
159 
160  set_value ((dods_uint16 *) &val[0], nelms);
161  } // H5UINT16
162  break;
163 
164 
165  case H5INT32:
166  {
167  vector<int>val;
168  val.resize(nelms);
169 
170  for (int i = 0; i < count[0]; i++)
171  val[i] = offset[0] + step[0] * i;
172 
173  set_value ((dods_int32 *) &val[0], nelms);
174  } // case H5INT32
175  break;
176 
177  case H5UINT32:
178  {
179  vector<unsigned int>val;
180  val.resize(nelms);
181 
182  for (int i = 0; i < count[0]; i++)
183  val[i] = offset[0] + step[0] * i;
184 
185  set_value ((dods_uint32 *) &val[0], nelms);
186  }
187  break;
188 
189  case H5INT64:
190  {
191  vector<long long>val;
192  val.resize(nelms);
193 
194  for (int i = 0; i < count[0]; i++)
195  val[i] = offset[0] + step[0] * i;
196 
197  set_value ((dods_int64 *) &val[0], nelms);
198  } // case H5INT64
199  break;
200 
201  case H5UINT64:
202  {
203  vector<unsigned long long>val;
204  val.resize(nelms);
205 
206  for (int i = 0; i < count[0]; i++)
207  val[i] = offset[0] + step[0] * i;
208 
209  set_value ((dods_uint64 *) &val[0], nelms);
210  }
211  break;
212 
213  case H5FLOAT32:
214  {
215 
216  vector<float>val;
217  val.resize(nelms);
218 
219  for (int i = 0; i < count[0]; i++)
220  val[i] = (float)(offset[0] + step[0] * i);
221 
222  set_value ((dods_float32 *) &val[0], nelms);
223  }
224  break;
225 
226 
227  case H5FLOAT64:
228  {
229 
230  vector<double>val;
231  val.resize(nelms);
232 
233  for (int i = 0; i < count[0]; i++)
234  val[i] = offset[0] + step[0] * i;
235 
236  set_value ((dods_float64 *) &val[0], nelms);
237  } // case H5FLOAT64
238  break;
239 
240 
241  case H5FSTRING:
242  case H5VSTRING:
243  default:
244  {
245  ostringstream eherr;
246  eherr << "Currently the dimension scale datatype cannot be string"<<endl;
247  throw InternalErr (__FILE__, __LINE__, eherr.str ());
248  }
249 
250  }
251 
252 
253  return;
254 }
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...