bes  Updated for version 3.20.6
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 "InternalErr.h"
40 
41 #include "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] = 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  case H5INT16:
112  {
113 
114  vector<short>val;
115  val.resize(nelms);
116 
117  for (int i = 0; i < count[0]; i++)
118  val[i] = offset[0] + step[0] * i;
119 
120  set_value ((dods_int16 *) &val[0], nelms);
121  }// H5CHAR and H5INT16
122  break;
123 
124 
125  case H5UINT16:
126  {
127  vector<unsigned short> val;
128  val.resize(nelms);
129 
130  for (int i = 0; i < count[0]; i++)
131  val[i] = offset[0] + step[0] * i;
132 
133  set_value ((dods_uint16 *) &val[0], nelms);
134  } // H5UINT16
135  break;
136 
137 
138  case H5INT32:
139  {
140  vector<int>val;
141  val.resize(nelms);
142 
143  for (int i = 0; i < count[0]; i++)
144  val[i] = offset[0] + step[0] * i;
145 
146  set_value ((dods_int32 *) &val[0], nelms);
147  } // case H5INT32
148  break;
149 
150  case H5UINT32:
151  {
152  vector<unsigned int>val;
153  val.resize(nelms);
154 
155  for (int i = 0; i < count[0]; i++)
156  val[i] = offset[0] + step[0] * i;
157 
158  set_value ((dods_uint32 *) &val[0], nelms);
159  }
160  break;
161 
162  case H5FLOAT32:
163  {
164 
165  vector<float>val;
166  val.resize(nelms);
167 
168  for (int i = 0; i < count[0]; i++)
169  val[i] = offset[0] + step[0] * i;
170 
171  set_value ((dods_float32 *) &val[0], nelms);
172  }
173  break;
174 
175 
176  case H5FLOAT64:
177  {
178 
179  vector<double>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_float64 *) &val[0], nelms);
186  } // case H5FLOAT64
187  break;
188 
189 
190  case H5FSTRING:
191  case H5VSTRING:
192  default:
193  {
194  ostringstream eherr;
195  eherr << "Currently the dimension scale datatype cannot be string"<<endl;
196  throw InternalErr (__FILE__, __LINE__, eherr.str ());
197  }
198 
199  }
200 
201 
202  return;
203 }
HDF5GMCFFillIndexArray
Definition: HDF5GMCFFillIndexArray.h:44
HDF5GMCFFillIndexArray.h
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
libdap
Definition: BESDapFunctionResponseCache.h:35