32 #include "config_hdf5.h"
37 #include "InternalErr.h"
45 BaseType *HDF5GMCFMissLLArray::ptr_duplicate()
50 bool HDF5GMCFMissLLArray::read()
53 BESDEBUG(
"h5",
"Coming to HDF5GMCFMissLLArray read "<<endl);
55 if (NULL == HDF5RequestHandler::get_lrdata_mem_cache())
56 read_data_NOT_from_mem_cache(
false, NULL);
60 vector<string> cur_lrd_non_cache_dir_list;
61 HDF5RequestHandler::get_lrd_non_cache_dir_list(cur_lrd_non_cache_dir_list);
66 if ((cur_lrd_non_cache_dir_list.size() == 0)
67 || (
"" == check_str_sect_in_list(cur_lrd_non_cache_dir_list, filename,
'/'))) {
69 vector<string> cur_cache_dlist;
70 HDF5RequestHandler::get_lrd_cache_dir_list(cur_cache_dlist);
71 string cache_dir = check_str_sect_in_list(cur_cache_dlist, filename,
'/');
72 if (cache_dir !=
"") {
74 cache_key = cache_dir + varname;
77 cache_key = filename + varname;
81 vector<size_t> dim_sizes;
82 Dim_iter i_dim = dim_begin();
83 Dim_iter i_enddim = dim_end();
84 while (i_dim != i_enddim) {
85 dim_sizes.push_back(dimension_size(i_dim));
89 size_t total_elems = 1;
90 for (
unsigned int i = 0; i < dim_sizes.size(); i++)
91 total_elems = total_elems * dim_sizes[i];
93 handle_data_with_mem_cache(dtype, total_elems, cache_flag, cache_key);
96 read_data_NOT_from_mem_cache(
false, NULL);
102 void HDF5GMCFMissLLArray::obtain_aqu_obpg_l3_ll(
int* offset,
int* step,
int nelms,
bool add_cache,
void* buf)
105 BESDEBUG(
"h5",
"Coming to obtain_aqu_obpg_l3_ll read "<<endl);
111 throw InternalErr(__FILE__, __LINE__,
"The number of dimension for Aquarius Level 3 map data must be 1");
113 bool check_pass_fileid_key = HDF5RequestHandler::get_pass_fileid();
114 if (
false == check_pass_fileid_key) {
115 if ((fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
117 eherr <<
"HDF5 File " << filename <<
" cannot be opened. " << endl;
118 throw InternalErr(__FILE__, __LINE__, eherr.str());
123 if ((rootid = H5Gopen(fileid,
"/", H5P_DEFAULT)) < 0) {
124 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
126 eherr <<
"HDF5 dataset " << varname <<
" cannot be opened. " << endl;
127 throw InternalErr(__FILE__, __LINE__, eherr.str());
130 float LL_first_point = 0.0;
132 int LL_total_num = 0;
134 if (CV_LAT_MISS == cvartype) {
135 string Lat_SWP_name = (Aqu_L3 == product_type) ?
"SW Point Latitude" :
"sw_point_latitude";
136 string Lat_step_name = (Aqu_L3 == product_type) ?
"Latitude Step" :
"latitude_step";
137 string Num_lines_name = (Aqu_L3 == product_type) ?
"Number of Lines" :
"number_of_lines";
139 float Lat_step = 0.0;
141 vector<char> dummy_str;
143 obtain_ll_attr_value(fileid, rootid, Lat_SWP_name, Lat_SWP, dummy_str);
144 obtain_ll_attr_value(fileid, rootid, Lat_step_name, Lat_step, dummy_str);
145 obtain_ll_attr_value(fileid, rootid, Num_lines_name, Num_lines, dummy_str);
146 if (Num_lines <= 0) {
148 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
149 throw InternalErr(__FILE__, __LINE__,
"The number of line must be >0");
153 LL_first_point = Lat_SWP + (Num_lines - 1) * Lat_step;
154 LL_step = Lat_step * (-1.0);
155 LL_total_num = Num_lines;
158 if (CV_LON_MISS == cvartype) {
160 string Lon_SWP_name = (Aqu_L3 == product_type) ?
"SW Point Longitude" :
"sw_point_longitude";
161 string Lon_step_name = (Aqu_L3 == product_type) ?
"Longitude Step" :
"longitude_step";
162 string Num_columns_name = (Aqu_L3 == product_type) ?
"Number of Columns" :
"number_of_columns";
164 float Lon_step = 0.0;
167 vector<char> dummy_str_value;
169 obtain_ll_attr_value(fileid, rootid, Lon_SWP_name, Lon_SWP, dummy_str_value);
170 obtain_ll_attr_value(fileid, rootid, Lon_step_name, Lon_step, dummy_str_value);
171 obtain_ll_attr_value(fileid, rootid, Num_columns_name, Num_cols, dummy_str_value);
174 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
175 throw InternalErr(__FILE__, __LINE__,
"The number of line must be >0");
179 LL_first_point = Lon_SWP;
181 LL_total_num = Num_cols;
187 if (nelms > LL_total_num) {
189 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
190 throw InternalErr(__FILE__, __LINE__,
191 "The number of elements exceeds the total number of Latitude or Longitude");
194 for (
int i = 0; i < nelms; ++i)
195 val[i] = LL_first_point + (offset[0] + i * step[0]) * LL_step;
197 if (
true == add_cache) {
198 vector<float> total_val;
199 total_val.resize(LL_total_num);
200 for (
int total_i = 0; total_i < LL_total_num; total_i++)
201 total_val[total_i] = LL_first_point + total_i * LL_step;
202 memcpy(buf, &total_val[0], 4 * LL_total_num);
205 set_value((dods_float32 *) &val[0], nelms);
207 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
211 void HDF5GMCFMissLLArray::obtain_gpm_l3_ll(
int* offset,
int* step,
int nelms,
bool add_cache,
void*buf)
215 throw InternalErr(__FILE__, __LINE__,
"The number of dimension for Aquarius Level 3 map data must be 1");
217 bool check_pass_fileid_key = HDF5RequestHandler::get_pass_fileid();
219 if (
false == check_pass_fileid_key) {
220 if ((fileid = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
222 eherr <<
"HDF5 File " << filename <<
" cannot be opened. " << endl;
223 throw InternalErr(__FILE__, __LINE__, eherr.str());
227 hid_t grid_grp_id = -1;
229 string grid_grp_name;
231 if ((name() ==
"nlat") || (name() ==
"nlon")) {
233 string temp_grid_grp_name(GPM_GRID_GROUP_NAME1, strlen(GPM_GRID_GROUP_NAME1));
234 temp_grid_grp_name =
"/" + temp_grid_grp_name;
235 if (H5Lexists(fileid, temp_grid_grp_name.c_str(), H5P_DEFAULT) > 0)
236 grid_grp_name = temp_grid_grp_name;
238 string temp_grid_grp_name2(GPM_GRID_GROUP_NAME2, strlen(GPM_GRID_GROUP_NAME2));
239 temp_grid_grp_name2 =
"/" + temp_grid_grp_name2;
240 if (H5Lexists(fileid, temp_grid_grp_name2.c_str(), H5P_DEFAULT) > 0)
241 grid_grp_name = temp_grid_grp_name2;
243 throw InternalErr(__FILE__, __LINE__,
"Unknown GPM grid group name ");
249 string temp_grids_group_name(GPM_GRID_MULTI_GROUP_NAME, strlen(GPM_GRID_MULTI_GROUP_NAME));
250 if (name() ==
"lnH" || name() ==
"ltH")
251 grid_grp_name = temp_grids_group_name +
"/G2";
252 else if (name() ==
"lnL" || name() ==
"ltL") grid_grp_name = temp_grids_group_name +
"/G1";
259 if(name() ==
"lnH" || name() ==
"ltH" ||
260 name() ==
"lnL" || name() ==
"ltL") {
261 string temp_grids_group_name(GPM_GRID_MULTI_GROUP_NAME,strlen(GPM_GRID_MULTI_GROUP_NAME));
264 size_t grids_group_pos = varname.find(temp_grids_group_name);
265 if(string::npos == grids_group_pos) {
266 throw InternalErr (__FILE__, __LINE__,
267 "Cannot find group Grids.");
270 string grids_cgroup_path = varname.substr(grids_group_pos+1);
271 size_t grids_cgroup_pos = varname.find_first_of(
"/");
272 if(string::npos == grids_cgroup_pos) {
273 throw InternalErr (__FILE__, __LINE__,
274 "Cannot find child group of group Grids.");
277 string temp_sub_grp_name = grids_cgroup_path.substr(0,grids_cgroup_pos);
278 if(name() ==
"lnH" || name() ==
"ltH")
279 sub_grp1_name = temp_sub_grp_name;
280 else if(name() ==
"lnL" || name() ==
"ltL")
281 sub_grp2_name = temp_sub_grp_name;
283 grid_grp_name = temp_grids_group_name +
"/" + temp_sub_grp_name;
288 if ((grid_grp_id = H5Gopen(fileid, grid_grp_name.c_str(), H5P_DEFAULT)) < 0) {
289 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
291 eherr <<
"HDF5 dataset " << varname <<
" cannot be opened. " << endl;
292 throw InternalErr(__FILE__, __LINE__, eherr.str());
296 string grid_info_name(GPM_ATTR2_NAME, strlen(GPM_ATTR2_NAME));
297 if (name() ==
"lnL" || name() ==
"ltL")
298 grid_info_name =
"G1_" + grid_info_name;
299 else if (name() ==
"lnH" || name() ==
"ltH") grid_info_name =
"G2_" + grid_info_name;
301 vector<char> grid_info_value;
302 float dummy_value = 0.0;
304 obtain_ll_attr_value(fileid, grid_grp_id, grid_info_name, dummy_value, grid_info_value);
307 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
313 float lon_start = 0.;
320 HDF5CFUtil::parser_gpm_l3_gridheader(grid_info_value, latsize, lonsize, lat_start, lon_start, lat_res, lon_res,
323 if (0 == latsize || 0 == lonsize) {
324 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
325 throw InternalErr(__FILE__, __LINE__,
"Either latitude or longitude size is 0. ");
331 if (CV_LAT_MISS == cvartype) {
333 if (nelms > latsize) {
334 H5Gclose(grid_grp_id);
335 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
336 throw InternalErr(__FILE__, __LINE__,
"The number of elements exceeds the total number of Latitude ");
339 for (
int i = 0; i < nelms; ++i)
340 val[i] = lat_start + offset[0] * lat_res + lat_res / 2 + i * lat_res * step[0];
342 if (add_cache ==
true) {
343 vector<float> total_val;
344 total_val.resize(latsize);
345 for (
int total_i = 0; total_i < latsize; total_i++)
346 total_val[total_i] = lat_start + lat_res / 2 + total_i * lat_res;
347 memcpy(buf, &total_val[0], 4 * latsize);
350 else if (CV_LON_MISS == cvartype) {
352 if (nelms > lonsize) {
353 H5Gclose(grid_grp_id);
354 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
355 throw InternalErr(__FILE__, __LINE__,
"The number of elements exceeds the total number of Longitude");
359 for (
int i = 0; i < nelms; ++i)
360 val[i] = lon_start + offset[0] * lon_res + lon_res / 2 + i * lon_res * step[0];
362 if (add_cache ==
true) {
363 vector<float> total_val;
364 total_val.resize(lonsize);
365 for (
int total_i = 0; total_i < lonsize; total_i++)
366 total_val[total_i] = lon_start + lon_res / 2 + total_i * lon_res;
367 memcpy(buf, &total_val[0], 4 * lonsize);
372 set_value((dods_float32 *) &val[0], nelms);
374 H5Gclose(grid_grp_id);
375 HDF5CFUtil::close_fileid(fileid, check_pass_fileid_key);
382 if (nelms > LL_total_num) {
385 throw InternalErr (__FILE__, __LINE__,
386 "The number of elements exceeds the total number of Latitude or Longitude");
389 for (
int i = 0; i < nelms; ++i)
390 val[i] = LL_first_point + (offset[0] + i*step[0])*LL_step;
392 set_value ((dods_float32 *) &val[0], nelms);
401 void HDF5GMCFMissLLArray::obtain_ll_attr_value(hid_t , hid_t s_root_id,
const string & s_attr_name,
402 T& attr_value, vector<char> & str_attr_value)
405 BESDEBUG(
"h5",
"Coming to obtain_ll_attr_value"<<endl);
406 hid_t s_attr_id = -1;
407 if ((s_attr_id = H5Aopen_by_name(s_root_id,
".", s_attr_name.c_str(),
408 H5P_DEFAULT, H5P_DEFAULT)) < 0) {
409 string msg =
"Cannot open the HDF5 attribute ";
412 throw InternalErr(__FILE__, __LINE__, msg);
415 hid_t attr_type = -1;
416 if ((attr_type = H5Aget_type(s_attr_id)) < 0) {
417 string msg =
"cannot get the attribute datatype for the attribute ";
421 throw InternalErr(__FILE__, __LINE__, msg);
424 hid_t attr_space = -1;
425 if ((attr_space = H5Aget_space(s_attr_id)) < 0) {
426 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
431 throw InternalErr(__FILE__, __LINE__, msg);
434 int num_elm = H5Sget_simple_extent_npoints(attr_space);
437 string msg =
"cannot get the number for the attribute ";
441 H5Sclose(attr_space);
443 throw InternalErr(__FILE__, __LINE__, msg);
447 string msg =
"The number of attribute must be 1 for Aquarius level 3 data ";
451 H5Sclose(attr_space);
453 throw InternalErr(__FILE__, __LINE__, msg);
456 size_t atype_size = H5Tget_size(attr_type);
457 if (atype_size <= 0) {
458 string msg =
"cannot obtain the datatype size of the attribute ";
462 H5Sclose(attr_space);
464 throw InternalErr(__FILE__, __LINE__, msg);
467 if (H5T_STRING == H5Tget_class(attr_type)) {
468 if (H5Tis_variable_str(attr_type)) {
471 H5Sclose(attr_space);
473 throw InternalErr(__FILE__, __LINE__,
474 "Currently we assume the attributes we use to retrieve lat and lon are NOT variable length string.");
477 str_attr_value.resize(atype_size);
478 if (H5Aread(s_attr_id, attr_type, &str_attr_value[0]) < 0) {
479 string msg =
"cannot retrieve the value of the attribute ";
483 H5Sclose(attr_space);
485 throw InternalErr(__FILE__, __LINE__, msg);
491 else if (H5Aread(s_attr_id, attr_type, &attr_value) < 0) {
492 string msg =
"cannot retrieve the value of the attribute ";
496 H5Sclose(attr_space);
498 throw InternalErr(__FILE__, __LINE__, msg);
503 H5Sclose(attr_space);
507 void HDF5GMCFMissLLArray::read_data_NOT_from_mem_cache(
bool add_cache,
void*buf)
510 BESDEBUG(
"h5",
"Coming to HDF5GMCFMissLLArray: read_data_NOT_from_mem_cache "<<endl);
522 int nelms = format_constraint(&offset[0], &step[0], &count[0]);
524 if (GPMM_L3 == product_type || GPMS_L3 == product_type)
525 obtain_gpm_l3_ll(&offset[0], &step[0], nelms, add_cache, buf);
526 else if (Aqu_L3 == product_type || OBPG_L3 == product_type)
527 obtain_aqu_obpg_l3_ll(&offset[0], &step[0], nelms, add_cache, buf);