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