bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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-2023 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 410 E University Ave,
20// Suite 200, Champaign, IL 61820
21
29
33
34#include <memory>
35#include <iostream>
36#include <cassert>
37#include <BESDebug.h>
38#include <libdap/InternalErr.h>
39
40#include <libdap/Str.h>
42
43using namespace std;
44using namespace libdap;
45
46BaseType *HDF5GMCFFillIndexArray::ptr_duplicate()
47{
48 auto HDF5GMCFFillIndexArray_unique = make_unique<HDF5GMCFFillIndexArray>(*this);
49 return HDF5GMCFFillIndexArray_unique.release();
50}
51
52// Read in an HDF5 Array
53bool HDF5GMCFFillIndexArray::read()
54{
55
56 BESDEBUG("h5","Coming to HDF5GMCFFillIndexArray read "<<endl);
57
58 read_data_NOT_from_mem_cache(false,nullptr);
59
60 return true;
61}
62
63
64void 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 int64_t nelms = 0;
71
72#if 0
73cerr<<"coming to read function"<<endl;
74cerr<<"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<int64_t> offset;
83 offset.resize(rank);
84 vector<int64_t>count;
85 count.resize(rank);
86 vector<int64_t>step;
87 step.resize(rank);
88
89 // Obtain the number of the subsetted elements
90 nelms = format_constraint (offset.data(), step.data(), count.data());
91
92
93 switch (dtype) {
94
95 case H5UCHAR:
96
97 {
98 vector<unsigned char> val;
99 val.resize(nelms);
100
101 for (int64_t i = 0; i < count[0]; i++)
102 val[i] = (unsigned char)(offset[0] + step[0] * i);
103
104 set_value_ll ((dods_byte *) val.data(), 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 (int64_t i = 0; i < count[0]; i++)
118 val[i] = (short)(offset[0] + step[0] * i);
119
120 set_value_ll (val.data(), nelms);
121 }
122 else {
123
124 vector<char> val;
125 val.resize(nelms);
126
127 for (int64_t i = 0; i < count[0]; i++)
128 val[i] = (char)(offset[0] + step[0] * i);
129
130 set_value_ll ((dods_int8*)val.data(), nelms);
131
132 }
133 }// H5CHAR and H5INT16
134 break;
135
136 case H5INT16:
137 {
138
139 vector<short>val;
140 val.resize(nelms);
141
142 for (int64_t i = 0; i < count[0]; i++)
143 val[i] = (short)(offset[0] + step[0] * i);
144
145 set_value_ll (val.data(), nelms);
146 }// H5CHAR and H5INT16
147 break;
148
149
150 case H5UINT16:
151 {
152 vector<unsigned short> val;
153 val.resize(nelms);
154
155 for (int64_t i = 0; i < count[0]; i++)
156 val[i] = (unsigned short)(offset[0] + step[0] * i);
157
158 set_value_ll (val.data(), nelms);
159 } // H5UINT16
160 break;
161
162
163 case H5INT32:
164 {
165 vector<int>val;
166 val.resize(nelms);
167
168 for (int64_t i = 0; i < count[0]; i++)
169 val[i] = (int)(offset[0] + step[0] * i);
170
171 set_value_ll (val.data(), nelms);
172 } // case H5INT32
173 break;
174
175 case H5UINT32:
176 {
177 vector<unsigned int>val;
178 val.resize(nelms);
179
180 for (int64_t i = 0; i < count[0]; i++)
181 val[i] = (unsigned int)(offset[0] + step[0] * i);
182
183 set_value_ll (val.data(), nelms);
184 }
185 break;
186
187 case H5INT64:
188 {
189 vector<long long>val;
190 val.resize(nelms);
191
192 for (int64_t i = 0; i < count[0]; i++)
193 val[i] = offset[0] + step[0] * i;
194
195 set_value_ll ((dods_int64 *) val.data(), nelms);
196 } // case H5INT64
197 break;
198
199 case H5UINT64:
200 {
201 vector<unsigned long long>val;
202 val.resize(nelms);
203
204 for (int64_t i = 0; i < count[0]; i++)
205 val[i] = offset[0] + step[0] * i;
206
207 set_value_ll ((dods_uint64 *) val.data(), nelms);
208 }
209 break;
210
211 case H5FLOAT32:
212 {
213
214 vector<float>val;
215 val.resize(nelms);
216
217 for (int64_t i = 0; i < count[0]; i++)
218 val[i] = (float)(offset[0] + step[0] * i);
219
220 set_value_ll (val.data(), nelms);
221 }
222 break;
223
224
225 case H5FLOAT64:
226 {
227
228 vector<double>val;
229 val.resize(nelms);
230
231 for (int64_t i = 0; i < count[0]; i++)
232 val[i] = (double)(offset[0] + step[0] * i);
233
234 set_value_ll (val.data(), nelms);
235 } // case H5FLOAT64
236 break;
237
238
239 case H5FSTRING:
240 case H5VSTRING:
241 default:
242 {
243 ostringstream eherr;
244 eherr << "Currently the dimension scale datatype cannot be string"<<endl;
245 throw InternalErr (__FILE__, __LINE__, eherr.str ());
246 }
247
248 }
249
250
251 return;
252}
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...