bes Updated for version 3.20.13
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-2016 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 <BESDebug.h>
37#include <libdap/InternalErr.h>
38
40
41using namespace std;
42using namespace libdap;
43
44BaseType *HDF5GMCFSpecialCVArray::ptr_duplicate()
45{
46 return new HDF5GMCFSpecialCVArray(*this);
47}
48
49bool HDF5GMCFSpecialCVArray::read()
50{
51
52 BESDEBUG("h5", "Coming to HDF5GMCFSpecialCVArray read "<<endl);
53
54 read_data_NOT_from_mem_cache(false, nullptr);
55
56 return true;
57}
58
59// This is according to https://storm.pps.eosdis.nasa.gov/storm/filespec.GPM.V1.pdf(section 5.32), the definition of nlayer
60// The top of each layer is 0.5,1.0,....., 10.0,11.0.....18.0 km.
61void HDF5GMCFSpecialCVArray::obtain_gpm_l3_layer(int nelms, vector<int>&offset, vector<int>&step, vector<int>&/*count*/)
62{
63
64 vector<float> total_val;
65 total_val.resize(tnumelm);
66 for (int i = 0; i < 20; i++)
67 total_val[i] = 0.5 * (i + 1);
68
69 for (int i = 20; i < 28; i++)
70 total_val[i] = total_val[19] + (i - 19);
71
72 // Since we always assign the the missing Z dimension as 32-bit
73 // integer, so no need to check the type. The missing Z-dim is always
74 // 1-D with natural number 1,2,3,....
75 if (nelms == tnumelm) {
76 set_value((dods_float32 *) total_val.data(), nelms);
77 }
78 else {
79
80 vector<float> val;
81 val.resize(nelms);
82
83 for (int i = 0; i < nelms; i++)
84 val[i] = total_val[offset[0] + step[0] * i];
85 set_value((dods_float32 *) val.data(), nelms);
86 }
87}
88
89// This is according to
90// http://www.eorc.jaxa.jp/GPM/doc/product/format/en/03.%20GPM_DPR_L2_L3%20Product%20Format%20Documentation_E.pdf
91// section 8.1. Number of layers at the fixed heights of 0.0-0.5km,0.5-1.0 km,.....
92// Like obtain_gpm_l3_layer1, we use the top height value 0.5 km, 1.0 km,2km,.....,18 km.
93// See also section 4.1.1 and 3.1.1 of http://www.eorc.jaxa.jp/GPM/doc/product/format/en/06.%20GPM_Combined%20Product%20Format_E.pdf
94void HDF5GMCFSpecialCVArray::obtain_gpm_l3_layer2(int nelms, vector<int>&offset, vector<int>&step, const vector<int>&/*count*/)
95{
96
97 vector<float> total_val;
98 total_val.resize(tnumelm);
99 for (int i = 0; i < 2; i++)
100 total_val[i] = 0.5 * (i + 1);
101
102 for (int i = 2; i < 19; i++)
103 total_val[i] = total_val[1] + (i - 1);
104
105 // Since we always assign the the missing Z dimension as 32-bit
106 // integer, so no need to check the type. The missing Z-dim is always
107 // 1-D with natural number 1,2,3,....
108 if (nelms == tnumelm) {
109 set_value((dods_float32 *) total_val.data(), nelms);
110 }
111 else {
112
113 vector<float> val;
114 val.resize(nelms);
115
116 for (int i = 0; i < nelms; i++)
117 val[i] = total_val[offset[0] + step[0] * i];
118 set_value((dods_float32 *) val.data(), nelms);
119 }
120}
121
122void HDF5GMCFSpecialCVArray::obtain_gpm_l3_hgt(int nelms, vector<int>&offset, vector<int>&step, const vector<int>&/*count*/)
123{
124
125 vector<float> total_val;
126 total_val.resize(5);
127 total_val[0] = 2;
128 total_val[1] = 4;
129 total_val[2] = 6;
130 total_val[3] = 10;
131 total_val[4] = 15;
132
133 // Since we always assign the the missing Z dimension as 32-bit
134 // integer, so no need to check the type. The missing Z-dim is always
135 // 1-D with natural number 1,2,3,....
136 if (nelms == tnumelm) {
137 set_value((dods_float32 *) total_val.data(), nelms);
138 }
139 else {
140
141 vector<float> val;
142 val.resize(nelms);
143
144 for (int i = 0; i < nelms; i++)
145 val[i] = total_val[offset[0] + step[0] * i];
146 set_value((dods_float32 *) val.data(), nelms);
147 }
148}
149
150void HDF5GMCFSpecialCVArray::obtain_gpm_l3_nalt(int nelms, vector<int>&offset, vector<int>&step, const vector<int>&/*count*/)
151{
152 vector<float> total_val;
153 total_val.resize(5);
154
155 total_val[0] = 2;
156 total_val[1] = 4;
157 total_val[2] = 6;
158 total_val[3] = 10;
159 total_val[4] = 15;
160
161 // Since we always assign the the missing Z dimension as 32-bit
162 // integer, so no need to check the type. The missing Z-dim is always
163 // 1-D with natural number 1,2,3,....
164 if (nelms == tnumelm) {
165 set_value((dods_float32 *) total_val.data(), nelms);
166 }
167 else {
168
169 vector<float> val;
170 val.resize(nelms);
171
172 for (int i = 0; i < nelms; i++)
173 val[i] = total_val[offset[0] + step[0] * i];
174 set_value((dods_float32 *) val.data(), nelms);
175 }
176}
177
178void HDF5GMCFSpecialCVArray::read_data_NOT_from_mem_cache(bool /*add_cache*/, void*/*buf*/)
179{
180
181 BESDEBUG("h5", "Coming to HDF5GMCFSpecialCVArray: read_data_NOT_from_mem_cache "<<endl);
182 // Here we still use vector just in case we need to tackle "rank>1" in the future.
183 // Also we would like to keep it consistent with other similar handlings.
184
185 vector<int> offset;
186 vector<int> count;
187 vector<int> step;
188
189 int rank = 1;
190 offset.resize(rank);
191 count.resize(rank);
192 step.resize(rank);
193
194 int nelms = format_constraint(offset.data(), step.data(), count.data());
195
196 if (GPMS_L3 == product_type || GPMM_L3 == product_type || GPM_L3_New == product_type) {
197 if (varname == "nlayer" && 28 == tnumelm)
198 obtain_gpm_l3_layer(nelms, offset, step, count);
199 else if (varname == "nlayer" && 19 == tnumelm)
200 obtain_gpm_l3_layer2(nelms, offset, step, count);
201 else if (varname == "hgt" && 5 == tnumelm) {
202 obtain_gpm_l3_hgt(nelms, offset, step, count);
203 }
204 else if (varname == "nalt" && 5 == tnumelm) obtain_gpm_l3_nalt(nelms, offset, step, count);
205 }
206
207 return;
208}
209
This class specifies the retrieval of the missing lat/lon values for general HDF5 products.