OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDFSPArrayAddCVField.cc
Go to the documentation of this file.
1 // 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: MuQun Yang <myang6@hdfgroup.org>
12 // Copyright (c) 2010-2012 The HDF Group
14 
15 #include "HDFSPArrayAddCVField.h"
16 #include <iostream>
17 #include <sstream>
18 #include <cassert>
19 #include <debug.h>
20 #include "mfhdf.h"
21 #include "hdf.h"
22 #include "InternalErr.h"
23 #include <BESDebug.h>
24 
25 
26 bool
28 {
29 
30  BESDEBUG("h4","Coming to HDFSPArrayAddCVField read "<<endl);
31  // Declaration of offset,count and step
32  vector<int>offset;
33  offset.resize(1);
34  vector<int>count;
35  count.resize(1);
36  vector<int>step;
37  step.resize(1);
38 
39  // Obtain offset,step and count from the client expression constraint
40  int nelms = format_constraint(&offset[0],&step[0],&count[0]);
41 
42  if(sptype == TRMML3C_V6) {
43 
44  if(dtype != DFNT_FLOAT32) {
45  throw InternalErr (__FILE__, __LINE__,
46  "The Height datatype of TRMM CSH product should be float.");
47  }
48 
49  if(tnumelm != 19) {
50  throw InternalErr (__FILE__, __LINE__,
51  "The number of elements should be 19.");
52  }
53 
54  vector<float>total_val;
55  total_val.resize(tnumelm);
56  total_val[0] = 0.5;
57  for (int i = 1; i<tnumelm;i++)
58  total_val[i] = (float)i;
59 
60 
61  if (nelms == tnumelm) {
62  set_value ((dods_float32 *) &total_val[0], nelms);
63  }
64  else {
65 
66  vector<float>val;
67  val.resize(nelms);
68 
69  for (int i = 0; i < nelms; i++)
70  val[i] = total_val[offset[0] + step[0] * i];
71  set_value ((dods_float32 *) &val[0], nelms);
72  }
73  }
74 
75  if(sptype == TRMML3S_V7) {
76 
77 
78  if(dtype != DFNT_FLOAT32) {
79  throw InternalErr (__FILE__, __LINE__,
80  "The Height datatype of TRMM CSH product should be float.");
81  }
82 
83  if(tnumelm == 28)
84  Obtain_trmm_v7_layer(nelms,offset,step,count);
85  else if(tnumelm == 6)
86  Obtain_trmml3s_v7_nthrash(nelms,offset,step,count);
87  else {
88  throw InternalErr (__FILE__, __LINE__,
89  "This special coordinate variable is not supported.");
90  }
91 
92  }
93 
94  if(sptype == TRMML2_V7) {
95 
96 
97  if(dtype != DFNT_FLOAT32) {
98  throw InternalErr (__FILE__, __LINE__,
99  "The Height datatype of TRMM CSH product should be float.");
100  }
101 
102  if(tnumelm == 28 && name =="nlayer")
103  Obtain_trmm_v7_layer(nelms,offset,step,count);
104  else {
105  throw InternalErr (__FILE__, __LINE__,
106  "This special coordinate variable is not supported.");
107  }
108 
109  }
110 
111  return true;
112 }
113 
114 
115 
116 #if 0
117  if(tnumelm != 28) {
118  throw InternalErr (__FILE__, __LINE__,
119  "The number of elements should be 19.");
120  }
121 
122  vector<float>total_val;
123  total_val.resize(tnumelm);
124  for (int i = 0; i<20;i++)
125  total_val[i] = 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 
132  // Since we always assign the the missing Z dimension as 32-bit
133  // integer, so no need to check the type. The missing Z-dim is always
134  // 1-D with natural number 1,2,3,....
135  if (nelms == tnumelm) {
136  set_value ((dods_float32 *) &total_val[0], nelms);
137  }
138  else {
139 
140  vector<float>val;
141  val.resize(nelms);
142 
143  for (int i = 0; i < nelms; i++)
144  val[i] = total_val[offset[0] + step[0] * i];
145  set_value ((dods_float32 *) &val[0], nelms);
146  }
147  }
148 
149 #endif
150 
151 
152 void HDFSPArrayAddCVField:: Obtain_trmm_v7_layer(int nelms, vector<int>&offset,vector<int>&step,vector<int>&count) {
153 
154 
155  vector<float>total_val;
156  total_val.resize(tnumelm);
157  for (int i = 0; i<20;i++)
158  total_val[i] = 0.5*(i+1);
159 
160  for (int i = 20; i<28;i++)
161  total_val[i] = total_val[19]+(i-19);
162 
163 
164 
165  // Since we always assign the the missing Z dimension as 32-bit
166  // integer, so no need to check the type. The missing Z-dim is always
167  // 1-D with natural number 1,2,3,....
168  if (nelms == tnumelm) {
169  set_value ((dods_float32 *) &total_val[0], nelms);
170  }
171  else {
172 
173  vector<float>val;
174  val.resize(nelms);
175 
176  for (int i = 0; i < nelms; i++)
177  val[i] = total_val[offset[0] + step[0] * i];
178  set_value ((dods_float32 *) &val[0], nelms);
179  }
180 }
181 
182 
183 void HDFSPArrayAddCVField:: Obtain_trmml3s_v7_nthrash(int nelms, vector<int>&offset,vector<int>&step,vector<int>&count) {
184 
185  vector<float>total_val;
186  total_val.resize(tnumelm);
187 
188  if(name =="nthrshZO") {
189 
190  total_val[0] = 0.1;
191  total_val[1] = 0.2;
192  total_val[2] = 0.3;
193  total_val[3] = 0.5;
194  total_val[4] = 0.75;
195  total_val[5] = 50;
196  }
197 
198  else if (name == "nthrshHB") {
199 
200  total_val[0] = 0.1;
201  total_val[1] = 0.2;
202  total_val[2] = 0.3;
203  total_val[3] = 0.5;
204  total_val[4] = 0.75;
205  total_val[5] = 0.9999;
206  }
207 
208  else if(name =="nthrshSRT") {
209 
210  total_val[0] = 1.5;
211  total_val[1] = 1.0;
212  total_val[2] = 0.8;
213  total_val[3] = 0.6;
214  total_val[4] = 0.4;
215  total_val[5] = 0.1;
216 
217  }
218  else
219  throw InternalErr (__FILE__, __LINE__,
220  "Unsupported coordinate variable names.");
221 
222  // Since we always assign the the missing Z dimension as 32-bit
223  // integer, so no need to check the type. The missing Z-dim is always
224  // 1-D with natural number 1,2,3,....
225  if (nelms == tnumelm) {
226  set_value ((dods_float32 *) &total_val[0], nelms);
227  }
228  else {
229 
230  vector<float>val;
231  val.resize(nelms);
232 
233  for (int i = 0; i < nelms; i++)
234  val[i] = total_val[offset[0] + step[0] * i];
235  set_value ((dods_float32 *) &val[0], nelms);
236  }
237 }
238 
239 
240 
241 // Standard way of DAP handlers to pass the coordinates of the subsetted region to the handlers
242 // Return the number of elements to read.
243 int
244 HDFSPArrayAddCVField::format_constraint (int *offset, int *step, int *count)
245 {
246  long nels = 1;
247  int id = 0;
248 
249  Dim_iter p = dim_begin ();
250 
251  while (p != dim_end ()) {
252 
253  int start = dimension_start (p, true);
254  int stride = dimension_stride (p, true);
255  int stop = dimension_stop (p, true);
256 
257 
258  // Check for illegical constraint
259  if (stride < 0 || start < 0 || stop < 0 || start > stop) {
260  ostringstream oss;
261 
262  oss << "Array/Grid hyperslab indices are bad: [" << start <<
263  ":" << stride << ":" << stop << "]";
264  throw Error (malformed_expr, oss.str ());
265  }
266 
267  // Check for an empty constraint and use the whole dimension if so.
268  if (start == 0 && stop == 0 && stride == 0) {
269  start = dimension_start (p, false);
270  stride = dimension_stride (p, false);
271  stop = dimension_stop (p, false);
272  }
273 
274  offset[id] = start;
275  step[id] = stride;
276  count[id] = ((stop - start) / stride) + 1; // count of elements
277  nels *= count[id]; // total number of values for variable
278 
279  BESDEBUG ("h4",
280  "=format_constraint():"
281  << "id=" << id << " offset=" << offset[id]
282  << " step=" << step[id]
283  << " count=" << count[id]
284  << endl);
285 
286  id++;
287  p++;
288  }
289 
290  return nels;
291 }
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
int format_constraint(int *cor, int *step, int *edg)