bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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-2023 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 410 E University Ave,
20// Suite 200, Champaign, IL 61820
21
31
32#include <iostream>
33#include <memory>
34#include <cassert>
35#include <BESDebug.h>
36
38
39using namespace std;
40using namespace libdap;
41
42BaseType *HDF5GMCFSpecialCVArray::ptr_duplicate()
43{
44 auto HDF5GMCFSpecialCVArray_unique = make_unique<HDF5GMCFSpecialCVArray>(*this);
45 return HDF5GMCFSpecialCVArray_unique.release();
46}
47
48bool HDF5GMCFSpecialCVArray::read()
49{
50
51 BESDEBUG("h5", "Coming to HDF5GMCFSpecialCVArray read "<<endl);
52
53 read_data_NOT_from_mem_cache(false, nullptr);
54
55 return true;
56}
57
58// This is according to https://storm.pps.eosdis.nasa.gov/storm/filespec.GPM.V1.pdf(section 5.32), the definition of nlayer
59// The top of each layer is 0.5,1.0,....., 10.0,11.0.....18.0 km.
60void HDF5GMCFSpecialCVArray::obtain_gpm_l3_layer(int64_t nelms, const vector<int64_t>&offset, const vector<int64_t>&step, const vector<int64_t>&/*count*/)
61{
62
63 vector<float> total_val;
64 total_val.resize(tnumelm);
65 for (int i = 0; i < 20; i++)
66 total_val[i] = 0.5 * (i + 1);
67
68 for (int i = 20; i < 28; i++)
69 total_val[i] = total_val[19] + (i - 19);
70
71 // Since we always assign the the missing Z dimension as 32-bit
72 // integer, so no need to check the type. The missing Z-dim is always
73 // 1-D with natural number 1,2,3,....
74 // No need to change the set_value and int, they will never exceed the 2GB.
75 if (nelms == tnumelm) {
76 set_value(total_val.data(), (int)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(val.data(), (int)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(int64_t nelms, const vector<int64_t>&offset, const vector<int64_t>&step, const vector<int64_t>&/*count*/)
95{
96
97 // No need to add the large array support. It will never happen to this product.
98 vector<float> total_val;
99 total_val.resize(tnumelm);
100 for (int i = 0; i < 2; i++)
101 total_val[i] = 0.5 * (i + 1);
102
103 for (int i = 2; i < 19; i++)
104 total_val[i] = total_val[1] + (i - 1);
105
106 // Since we always assign the the missing Z dimension as 32-bit
107 // integer, so no need to check the type. The missing Z-dim is always
108 // 1-D with natural number 1,2,3,....
109 if (nelms == tnumelm) {
110 set_value(total_val.data(), (int)nelms);
111 }
112 else {
113
114 vector<float> val;
115 val.resize(nelms);
116
117 for (int i = 0; i < nelms; i++)
118 val[i] = total_val[offset[0] + step[0] * i];
119 set_value(val.data(), (int)nelms);
120 }
121}
122
123void HDF5GMCFSpecialCVArray::obtain_gpm_l3_nalt_hgt(int64_t nelms, const vector<int64_t>&offset, const vector<int64_t>&step, const vector<int64_t>&/*count*/)
124{
125
126 // No need to add the large array support. It will never happen to this product.
127 vector<float> total_val;
128 total_val.resize(5);
129 total_val[0] = 2;
130 total_val[1] = 4;
131 total_val[2] = 6;
132 total_val[3] = 10;
133 total_val[4] = 15;
134
135 // Since we always assign the the missing Z dimension as 32-bit
136 // integer, so no need to check the type. The missing Z-dim is always
137 // 1-D with natural number 1,2,3,....
138 if (nelms == tnumelm) {
139 set_value(total_val.data(), (int)nelms);
140 }
141 else {
142
143 vector<float> val;
144 val.resize(nelms);
145
146 for (int i = 0; i < nelms; i++)
147 val[i] = total_val[offset[0] + step[0] * i];
148 set_value(val.data(), (int)nelms);
149 }
150}
151
152#if 0
153void HDF5GMCFSpecialCVArray::obtain_gpm_l3_nalt(int64_t nelms, const vector<int64_t>&offset, const vector<int64_t>&step, const vector<int64_t>&/*count*/)
154{
155 // No need to add the large array support. It will never happen to this product.
156 vector<float> total_val;
157 total_val.resize(5);
158
159 total_val[0] = 2;
160 total_val[1] = 4;
161 total_val[2] = 6;
162 total_val[3] = 10;
163 total_val[4] = 15;
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(total_val.data(), (int)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(val.data(), (int)nelms);
179 }
180}
181#endif
182
183void HDF5GMCFSpecialCVArray::read_data_NOT_from_mem_cache(bool /*add_cache*/, void*/*buf*/)
184{
185
186 BESDEBUG("h5", "Coming to HDF5GMCFSpecialCVArray: read_data_NOT_from_mem_cache "<<endl);
187 // Here we still use vector just in case we need to tackle "rank>1" in the future.
188 // Also we would like to keep it consistent with other similar handlings.
189
190 vector<int64_t> offset;
191 vector<int64_t> count;
192 vector<int64_t> step;
193
194 int rank = 1;
195 offset.resize(rank);
196 count.resize(rank);
197 step.resize(rank);
198
199 int64_t nelms = format_constraint(offset.data(), step.data(), count.data());
200
201 if (GPMS_L3 == product_type || GPMM_L3 == product_type || GPM_L3_New == product_type) {
202 if (varname == "nlayer" && 28 == tnumelm)
203 obtain_gpm_l3_layer(nelms, offset, step, count);
204 else if (varname == "nlayer" && 19 == tnumelm)
205 obtain_gpm_l3_layer2(nelms, offset, step, count);
206 else if (varname == "hgt" && 5 == tnumelm) {
207 obtain_gpm_l3_nalt_hgt(nelms, offset, step, count);
208 }
209 else if (varname == "nalt" && 5 == tnumelm) obtain_gpm_l3_nalt_hgt(nelms, offset, step, count);
210 }
211
212 return;
213}
214
This class specifies the retrieval of the missing lat/lon values for general HDF5 products.