-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHDFSPArrayAddCVField.cc
More file actions
289 lines (216 loc) · 7.87 KB
/
HDFSPArrayAddCVField.cc
File metadata and controls
289 lines (216 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/////////////////////////////////////////////////////////////////////////////
// This file is part of the hdf4 data handler for the OPeNDAP data server.
// It retrieves the missing fields for some special NASA HDF4 data products.
// The products include TRMML2_V6,TRMML3B_V6,CER_AVG,CER_ES4,CER_CDAY,CER_CGEO,CER_SRB,CER_SYN,CER_ZAVG,OBPGL2,OBPGL3
// To know more information about these products,check HDFSP.h.
// Some third-dimension coordinate variable values are not provided.
// What we do here is to provide natural number series(1,2,3, ...) for
// these missing values. It doesn't make sense to visualize or analyze
// with vertical cross-section. One can check the data level by level.
// Authors: MuQun Yang <myang6@hdfgroup.org>
// Copyright (c) 2010-2012 The HDF Group
/////////////////////////////////////////////////////////////////////////////
#include "HDFSPArrayAddCVField.h"
#include <iostream>
#include <sstream>
#include <cassert>
#include <libdap/debug.h>
#include "mfhdf.h"
#include "hdf.h"
#include <libdap/InternalErr.h>
#include <BESDebug.h>
using namespace libdap;
using namespace std;
bool
HDFSPArrayAddCVField::read ()
{
BESDEBUG("h4","Coming to HDFSPArrayAddCVField read "<<endl);
if(length() == 0)
return true;
// Declaration of offset,count and step
vector<int>offset;
offset.resize(1);
vector<int>count;
count.resize(1);
vector<int>step;
step.resize(1);
// Obtain offset,step and count from the client expression constraint
int nelms = format_constraint(&offset[0],&step[0],&count[0]);
if(sptype == TRMML3C_V6) {
if(dtype != DFNT_FLOAT32) {
throw InternalErr (__FILE__, __LINE__,
"The Height datatype of TRMM CSH product should be float.");
}
if(tnumelm != 19) {
throw InternalErr (__FILE__, __LINE__,
"The number of elements should be 19.");
}
vector<float>total_val;
total_val.resize(tnumelm);
total_val[0] = 0.5;
for (int i = 1; i<tnumelm;i++)
total_val[i] = (float)i;
if (nelms == tnumelm) {
set_value ((dods_float32 *) &total_val[0], nelms);
}
else {
vector<float>val;
val.resize(nelms);
for (int i = 0; i < nelms; i++)
val[i] = total_val[offset[0] + step[0] * i];
set_value ((dods_float32 *) &val[0], nelms);
}
}
if(sptype == TRMML3S_V7) {
if(dtype != DFNT_FLOAT32) {
throw InternalErr (__FILE__, __LINE__,
"The Height datatype of TRMM CSH product should be float.");
}
if(tnumelm == 28)
Obtain_trmm_v7_layer(nelms,offset,step);
else if(tnumelm == 6)
Obtain_trmml3s_v7_nthrash(nelms,offset,step);
else {
throw InternalErr (__FILE__, __LINE__,
"This special coordinate variable is not supported.");
}
}
if(sptype == TRMML2_V7) {
if(dtype != DFNT_FLOAT32) {
throw InternalErr (__FILE__, __LINE__,
"The Height datatype of TRMM CSH product should be float.");
}
if(tnumelm == 28 && name =="nlayer")
Obtain_trmm_v7_layer(nelms,offset,step);
else {
throw InternalErr (__FILE__, __LINE__,
"This special coordinate variable is not supported.");
}
}
return true;
}
#if 0
if(tnumelm != 28) {
throw InternalErr (__FILE__, __LINE__,
"The number of elements should be 19.");
}
vector<float>total_val;
total_val.resize(tnumelm);
for (int i = 0; i<20;i++)
total_val[i] = 0.5*(i+1);
for (int i = 20; i<28;i++)
total_val[i] = total_val[19]+(i-19);
// Since we always assign the the missing Z dimension as 32-bit
// integer, so no need to check the type. The missing Z-dim is always
// 1-D with natural number 1,2,3,....
if (nelms == tnumelm) {
set_value ((dods_float32 *) &total_val[0], nelms);
}
else {
vector<float>val;
val.resize(nelms);
for (int i = 0; i < nelms; i++)
val[i] = total_val[offset[0] + step[0] * i];
set_value ((dods_float32 *) &val[0], nelms);
}
}
#endif
void HDFSPArrayAddCVField:: Obtain_trmm_v7_layer(int nelms, vector<int>&offset,vector<int>&step) {
vector<float>total_val;
total_val.resize(tnumelm);
for (int i = 0; i<20;i++)
total_val[i] = 0.5*(i+1);
for (int i = 20; i<28;i++)
total_val[i] = total_val[19]+(i-19);
// Since we always assign the the missing Z dimension as 32-bit
// integer, so no need to check the type. The missing Z-dim is always
// 1-D with natural number 1,2,3,....
if (nelms == tnumelm) {
set_value ((dods_float32 *) &total_val[0], nelms);
}
else {
vector<float>val;
val.resize(nelms);
for (int i = 0; i < nelms; i++)
val[i] = total_val[offset[0] + step[0] * i];
set_value ((dods_float32 *) &val[0], nelms);
}
}
void HDFSPArrayAddCVField:: Obtain_trmml3s_v7_nthrash(int nelms, vector<int>&offset,vector<int>&step) {
vector<float>total_val;
total_val.resize(tnumelm);
if(name =="nthrshZO") {
total_val[0] = 0.1;
total_val[1] = 0.2;
total_val[2] = 0.3;
total_val[3] = 0.5;
total_val[4] = 0.75;
total_val[5] = 50;
}
else if (name == "nthrshHB") {
total_val[0] = 0.1;
total_val[1] = 0.2;
total_val[2] = 0.3;
total_val[3] = 0.5;
total_val[4] = 0.75;
total_val[5] = 0.9999;
}
else if(name =="nthrshSRT") {
total_val[0] = 1.5;
total_val[1] = 1.0;
total_val[2] = 0.8;
total_val[3] = 0.6;
total_val[4] = 0.4;
total_val[5] = 0.1;
}
else
throw InternalErr (__FILE__, __LINE__,
"Unsupported coordinate variable names.");
// Since we always assign the the missing Z dimension as 32-bit
// integer, so no need to check the type. The missing Z-dim is always
// 1-D with natural number 1,2,3,....
if (nelms == tnumelm) {
set_value ((dods_float32 *) &total_val[0], nelms);
}
else {
vector<float>val;
val.resize(nelms);
for (int i = 0; i < nelms; i++)
val[i] = total_val[offset[0] + step[0] * i];
set_value ((dods_float32 *) &val[0], nelms);
}
}
// Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
// Return the number of elements to read.
int
HDFSPArrayAddCVField::format_constraint (int *offset, int *step, int *count)
{
long nels = 1;
int id = 0;
Dim_iter p = dim_begin ();
while (p != dim_end ()) {
int start = dimension_start (p, true);
int stride = dimension_stride (p, true);
int stop = dimension_stop (p, true);
// Check for illegal constraint
if (start > stop) {
ostringstream oss;
oss << "Array/Grid hyperslab start point "<< start <<
" is greater than stop point " << stop <<".";
throw Error(malformed_expr, oss.str());
}
offset[id] = start;
step[id] = stride;
count[id] = ((stop - start) / stride) + 1; // count of elements
nels *= count[id]; // total number of values for variable
BESDEBUG ("h4",
"=format_constraint():"
<< "id=" << id << " offset=" << offset[id]
<< " step=" << step[id]
<< " count=" << count[id]
<< endl);
id++;
p++;
}// while (p != dim_end ())
return nels;
}