11#include <libdap/InternalErr.h>
13#include "HDF5MissLLArray.h"
22BaseType *HDF5MissLLArray::ptr_duplicate()
24 auto HDF5MissLLArray_unique = make_unique<HDF5MissLLArray>(*
this);
25 return HDF5MissLLArray_unique.release();
28bool HDF5MissLLArray::read()
31 BESDEBUG(
"h5",
"Coming to HDF5MissLLArray read "<<endl);
33 if (g_info.projection == HE5_GCTP_GEO)
42bool HDF5MissLLArray::read_data_non_geo() {
45 vector<int64_t>offset;
50 throw InternalErr (__FILE__, __LINE__,
51 "The number of dimension of this variable should be greater than 0");
56 nelms = format_constraint (offset.data(), step.data(), count.data());
60 throw InternalErr (__FILE__, __LINE__,
61 "The number of elments is negative.");
63 int64_t total_elms = g_info.xdim_size * g_info.ydim_size;
64 if (total_elms > DODS_INT_MAX)
65 throw InternalErr (__FILE__, __LINE__,
66 "Currently we cannot calculate lat/lon that is greater than 2G for HDF-EOS5.");
68 if(g_info.ydim_size <=0 || g_info.xdim_size <=0)
69 throw InternalErr (__FILE__, __LINE__,
70 "The number of elments at each dimension should be greater than 0.");
72 vector<size_t>pos(rank,0);
73 for (
int i = 0; i< rank; i++)
76 vector<size_t>dimsizes;
77 dimsizes.push_back(g_info.ydim_size);
78 dimsizes.push_back(g_info.xdim_size);
86 rows.resize(g_info.xdim_size * g_info.ydim_size);
87 cols.resize(g_info.xdim_size * g_info.ydim_size);
88 lon.resize(g_info.xdim_size * g_info.ydim_size);
89 lat.resize(g_info.xdim_size * g_info.ydim_size);
91 upleft[0] = g_info.point_left;
92 upleft[1] = g_info.point_upper;
93 lowright[0] = g_info.point_right;
94 lowright[1] = g_info.point_lower;
99 for (
int j = 0; j < g_info.ydim_size; ++j) {
100 for (
int i = 0; i < g_info.xdim_size; ++i) {
107 BESDEBUG(
"h5",
" Before calling GDij2ll, check all projection parameters. " << endl);
108 BESDEBUG(
"h5",
" eos5_projcode is " << g_info.projection <<endl);
109 BESDEBUG(
"h5",
" eos5_zone is " << g_info.zone <<endl);
110 BESDEBUG(
"h5",
" eos5_params[0] is " << g_info.param[0] <<endl);
111 BESDEBUG(
"h5",
" eos5_params[1] is " << g_info.param[1] <<endl);
112 BESDEBUG(
"h5",
" eos5_sphere is " << g_info.sphere <<endl);
113 BESDEBUG(
"h5",
" xdimsize is " << g_info.xdim_size <<endl);
114 BESDEBUG(
"h5",
" ydimsize is " << g_info.ydim_size <<endl);
115 BESDEBUG(
"h5",
" eos5_pixelreg is " << g_info.pixelregistration <<endl);
116 BESDEBUG(
"h5",
" eos5_origin is " << g_info.gridorigin <<endl);
117 BESDEBUG(
"h5",
" upleft[0] is " << upleft[0] <<endl);
118 BESDEBUG(
"h5",
" upleft[1] is " << upleft[1] <<endl);
119 BESDEBUG(
"h5",
" lowright[0] is " << lowright[0] <<endl);
120 BESDEBUG(
"h5",
" lowright[1] is " << lowright[1] <<endl);
124 r = GDij2ll (g_info.projection, g_info.zone, g_info.param,g_info.sphere, g_info.xdim_size, g_info.ydim_size, upleft, lowright,
125 g_info.xdim_size * g_info.ydim_size, rows.data(), cols.data(), lon.data(), lat.data(), g_info.pixelregistration, g_info.gridorigin);
128 eherr <<
"cannot calculate grid latitude and longitude";
129 throw InternalErr (__FILE__, __LINE__, eherr.str ());
133 BESDEBUG(
"h5",
" The first value of lon is " << lon[0] <<endl);
134 BESDEBUG(
"h5",
" The first value of lat is " << lat[0] <<endl);
138 if(total_elms == nelms)
139 set_value_ll(lat.data(),total_elms);
152 set_value_ll(val.data(),nelms);
157 if(total_elms == nelms)
158 set_value_ll(lon.data(),total_elms);
171 set_value_ll(val.data(),nelms);
178bool HDF5MissLLArray::read_data_geo(){
180 BESDEBUG(
"h5",
"HDF5MissLLArray: Coming to read_data_geo "<<endl);
182 vector<int64_t>offset;
183 vector<int64_t>count;
188 throw InternalErr (__FILE__, __LINE__,
189 "The number of dimension of this variable should be greater than 0");
194 nelms = format_constraint (offset.data(), step.data(), count.data());
197 if (nelms <= 0 || nelms >DODS_INT_MAX)
198 throw InternalErr (__FILE__, __LINE__,
199 "The number of elements for geographic lat/lon is negative or greater than 2G.");
207 if (HE5_HDFE_GD_UL == g_info.gridorigin || HE5_HDFE_GD_UR == g_info.gridorigin) {
209 start = (float)(g_info.point_upper);
210 end = (float)(g_info.point_lower);
215 start = (float)(g_info.point_lower);
216 end = (float)(g_info.point_upper);
219 if(g_info.ydim_size <=0)
220 throw InternalErr (__FILE__, __LINE__,
221 "The number of elments should be greater than 0.");
223 float lat_step = (end - start) /(
float)(g_info.ydim_size);
225 if ( HE5_HDFE_CENTER == g_info.pixelregistration ) {
226 for (
int i = 0; i < nelms; i++)
227 val[i] = (((
float)(offset[0]+i*step[0]) + 0.5F) * lat_step + start) / 1000000.0F;
230 for (
int i = 0; i < nelms; i++)
231 val[i] = ((
float)(offset[0]+i * step[0])*lat_step + start) / 1000000.0F;
236 if (HE5_HDFE_GD_UL == g_info.gridorigin || HE5_HDFE_GD_LL == g_info.gridorigin) {
238 start = (float)(g_info.point_left);
239 end = (float)(g_info.point_right);
244 start = (float)(g_info.point_right);
245 end = (float)(g_info.point_left);
248 if(g_info.xdim_size <=0)
249 throw InternalErr (__FILE__, __LINE__,
250 "The number of elments should be greater than 0.");
251 float lon_step = (end - start) /(
float)(g_info.xdim_size);
253 if (HE5_HDFE_CENTER == g_info.pixelregistration) {
255 for (
int i = 0; i < nelms; i++)
256 val[i] = (((
float)(offset[0] + i *step[0]) + 0.5F) * lon_step + start ) / 1000000.0F;
260 for (
int i = 0; i < nelms; i++)
261 val[i] = ((
float)(offset[0]+i*step[0]) * lon_step + start) / 1000000.0F;
266for (
int i =0; i <nelms; i++)
267"h5",
"final data val "<< i <<
" is " << val[i] <<endl;
271 read_data_geo_lat(nelms, offset, step, val) ;
273 read_data_geo_lon(nelms, offset, step, val) ;
274 set_value_ll(val.data(), nelms);
280void HDF5MissLLArray::read_data_geo_lat(int64_t nelms,
const vector<int64_t> &offset,
281 const vector<int64_t> &step, vector<float> &val)
const
287 if (HE5_HDFE_GD_UL == g_info.gridorigin || HE5_HDFE_GD_UR == g_info.gridorigin) {
289 start = (float)(g_info.point_upper);
290 end = (float)(g_info.point_lower);
295 start = (float)(g_info.point_lower);
296 end = (float)(g_info.point_upper);
299 if(g_info.ydim_size <=0)
300 throw InternalErr (__FILE__, __LINE__,
301 "The number of elements should be greater than 0.");
303 float lat_step = (end - start) /(
float)(g_info.ydim_size);
305 if ( HE5_HDFE_CENTER == g_info.pixelregistration ) {
306 for (
int i = 0; i < nelms; i++)
307 val[i] = (((
float)(offset[0]+i*step[0]) + 0.5F) * lat_step + start) / 1000000.0F;
310 for (
int i = 0; i < nelms; i++)
311 val[i] = ((
float)(offset[0]+i * step[0])*lat_step + start) / 1000000.0F;
316void HDF5MissLLArray::read_data_geo_lon(int64_t nelms,
const vector<int64_t> &offset,
const vector<int64_t> &step,
317 vector<float> &val)
const {
322 if (HE5_HDFE_GD_UL == g_info.gridorigin || HE5_HDFE_GD_LL == g_info.gridorigin) {
324 start = (float)(g_info.point_left);
325 end = (float)(g_info.point_right);
330 start = (float)(g_info.point_right);
331 end = (float)(g_info.point_left);
334 if (g_info.xdim_size <=0)
335 throw InternalErr (__FILE__, __LINE__,
336 "The number of elements should be greater than 0.");
338 float lon_step = (end - start) /(
float)(g_info.xdim_size);
340 if (HE5_HDFE_CENTER == g_info.pixelregistration) {
342 for (
int i = 0; i < nelms; i++)
343 val[i] = (((
float)(offset[0] + i *step[0]) + 0.5F) * lon_step + start ) / 1000000.0F;
347 for (
int i = 0; i < nelms; i++)
348 val[i] = ((
float)(offset[0]+i*step[0]) * lon_step + start) / 1000000.0F;
356HDF5MissLLArray::format_constraint (int64_t *offset, int64_t *step, int64_t *count)
361 Dim_iter p = dim_begin ();
363 while (p != dim_end ()) {
365 int64_t start = dimension_start (p,
true);
366 int64_t stride = dimension_stride (p,
true);
367 int64_t stop = dimension_stop (p,
true);
372 oss <<
"Array/Grid hyperslab start point "<< start <<
373 " is greater than stop point " << stop <<
".";
374 throw Error(malformed_expr, oss.str());
379 count[id] = ((stop - start) / stride) + 1;
383 "=format_constraint():"
384 <<
"id=" <<
id <<
" offset=" << offset[
id]
385 <<
" step=" << step[
id]
386 <<
" count=" << count[
id]
408int HDF5MissLLArray::subset(
411 const vector<size_t> & dim,
419 for(
int k=0; k<edge[index]; k++)
421 pos[index] = start[index] + k*stride[index];
423 subset(input, s_rank, dim, start, stride, edge, poutput,pos,index+1);
426 size_t cur_pos = INDEX_nD_TO_1D( dim, pos);
427 auto tempbuf = (
void*)((
char*)input+cur_pos*
sizeof(T));
428 poutput->push_back(*(
static_cast<T*
>(tempbuf)));
434size_t HDF5MissLLArray::INDEX_nD_TO_1D (
const std::vector < size_t > &dims,
435 const std::vector < size_t > &pos)
const {
440 if(dims.size () != pos.size ())
441 throw InternalErr(__FILE__,__LINE__,
"dimension error in INDEX_nD_TO_1D routine.");
445 for (
const auto &p:pos) {
448 for (
size_t j = start; j < dims.size (); j++)
This file includes several helper functions for translating HDF5 to CF-compliant.
include the entry functions to execute the handlers