OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HDF5GMCFSpecialCVArray.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-2013 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 
31 
32 #include "config_hdf5.h"
33 #include <iostream>
34 #include <sstream>
35 #include <cassert>
36 #include <debug.h>
37 #include "InternalErr.h"
38 #include <BESDebug.h>
39 
40 #include "HDF5GMCFSpecialCVArray.h"
41 
42 
44 {
45  return new HDF5GMCFSpecialCVArray(*this);
46 }
47 
49 {
50 
51  // Here we still use vector just in case we need to tackle "rank>1" in the future.
52  // Also we would like to keep it consistent with other similar handlings.
53 
54  vector<int>offset;
55  vector<int>count;
56  vector<int>step;
57 
58  int rank = 1;
59  offset.resize(rank);
60  count.resize(rank);
61  step.resize(rank);
62 
63  int nelms = format_constraint (&offset[0], &step[0], &count[0]);
64 
65  if (GPMS_L3 == product_type || GPMM_L3 == product_type) {
66  if(varname=="nlayer" && 28 == tnumelm)
67  obtain_gpm_l3_layer(nelms,offset,step,count);
68  else if(varname=="hgt" && 5 == tnumelm)
69  obtain_gpm_l3_hgt(nelms,offset,step,count);
70  else if(varname=="nalt" && 5 == tnumelm)
71  obtain_gpm_l3_nalt(nelms,offset,step,count);
72  }
73 
74 
75  return true;
76 }
77 
78 void HDF5GMCFSpecialCVArray::obtain_gpm_l3_layer(int nelms,vector<int>&offset,vector<int>&step,vector<int>&count) {
79 
80 
81  vector<float>total_val;
82  total_val.resize(tnumelm);
83  for (int i = 0; i<20;i++)
84  total_val[i] = 0.5*(i+1);
85 
86  for (int i = 20; i<28;i++)
87  total_val[i] = total_val[19]+(i-19);
88 
89  // Since we always assign the the missing Z dimension as 32-bit
90  // integer, so no need to check the type. The missing Z-dim is always
91  // 1-D with natural number 1,2,3,....
92  if (nelms == tnumelm) {
93  set_value ((dods_float32 *) &total_val[0], nelms);
94  }
95  else {
96 
97  vector<float>val;
98  val.resize(nelms);
99 
100  for (int i = 0; i < nelms; i++)
101  val[i] = total_val[offset[0] + step[0] * i];
102  set_value ((dods_float32 *) &val[0], nelms);
103  }
104 }
105 
106 void HDF5GMCFSpecialCVArray::obtain_gpm_l3_hgt(int nelms,vector<int>&offset,vector<int>&step,vector<int>&count) {
107 
108 
109  vector<float>total_val;
110  total_val.resize(5);
111  total_val[0] = 2;
112  total_val[1] = 4;
113  total_val[2] = 6;
114  total_val[3] = 10;
115  total_val[4] = 15;
116 
117  // Since we always assign the the missing Z dimension as 32-bit
118  // integer, so no need to check the type. The missing Z-dim is always
119  // 1-D with natural number 1,2,3,....
120  if (nelms == tnumelm) {
121  set_value ((dods_float32 *) &total_val[0], nelms);
122  }
123  else {
124 
125  vector<float>val;
126  val.resize(nelms);
127 
128  for (int i = 0; i < nelms; i++)
129  val[i] = total_val[offset[0] + step[0] * i];
130  set_value ((dods_float32 *) &val[0], nelms);
131  }
132 }
133 
134 void HDF5GMCFSpecialCVArray::obtain_gpm_l3_nalt(int nelms,vector<int>&offset,vector<int>&step,vector<int>&count) {
135 
136 
137  vector<float>total_val;
138  total_val.resize(5);
139 
140  total_val[0] = 2;
141  total_val[1] = 4;
142  total_val[2] = 6;
143  total_val[3] = 10;
144  total_val[4] = 15;
145 
146 
147  // Since we always assign the the missing Z dimension as 32-bit
148  // integer, so no need to check the type. The missing Z-dim is always
149  // 1-D with natural number 1,2,3,....
150  if (nelms == tnumelm) {
151  set_value ((dods_float32 *) &total_val[0], nelms);
152  }
153  else {
154 
155  vector<float>val;
156  val.resize(nelms);
157 
158  for (int i = 0; i < nelms; i++)
159  val[i] = total_val[offset[0] + step[0] * i];
160  set_value ((dods_float32 *) &val[0], nelms);
161  }
162 }
163 
164 
165 // parse constraint expr. and make hdf5 coordinate point location.
166 // return number of elements to read.
167 int
168 HDF5GMCFSpecialCVArray::format_constraint (int *offset, int *step, int *count)
169 {
170  long nels = 1;
171  int id = 0;
172 
173  Dim_iter p = dim_begin ();
174 
175  while (p != dim_end ()) {
176 
177  int start = dimension_start (p, true);
178  int stride = dimension_stride (p, true);
179  int stop = dimension_stop (p, true);
180 
181 
182  // Check for illegical constraint
183  if (stride < 0 || start < 0 || stop < 0 || start > stop) {
184  ostringstream oss;
185 
186  oss << "Array/Grid hyperslab indices are bad: [" << start <<
187  ":" << stride << ":" << stop << "]";
188  throw Error (malformed_expr, oss.str ());
189  }
190 
191  // Check for an empty constraint and use the whole dimension if so.
192  if (start == 0 && stop == 0 && stride == 0) {
193  start = dimension_start (p, false);
194  stride = dimension_stride (p, false);
195  stop = dimension_stop (p, false);
196  }
197 
198  offset[id] = start;
199  step[id] = stride;
200  count[id] = ((stop - start) / stride) + 1; // count of elements
201  nels *= count[id]; // total number of values for variable
202 
203  BESDEBUG ("h5",
204  "=format_constraint():"
205  << "id=" << id << " offset=" << offset[id]
206  << " step=" << step[id]
207  << " count=" << count[id]
208  << endl);
209 
210  id++;
211  p++;
212  }
213 
214  return nels;
215 }
216 
HDF5GMCFSpecialCVArray(H5DataType dtype, int tnumelm, const string &varfullpath, H5GCFProduct product_type, const string &n="", BaseType *v=0)
int format_constraint(int *cor, int *step, int *edg)
This class specifies the retrieval of the missing lat/lon values for general HDF5 products...
virtual BaseType * ptr_duplicate()
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64