37 #include "InternalErr.h"
52 BESDEBUG(
"h5",
"Coming to HDF5GMCFMissLLArray read "<<endl);
67 obtain_gpm_l3_ll(&offset[0],&step[0],nelms);
69 obtain_aqu_obpg_l3_ll(&offset[0],&step[0],nelms);
74 void HDF5GMCFMissLLArray::obtain_aqu_obpg_l3_ll(
int* offset,
int* step,
int nelms) {
81 throw InternalErr (__FILE__, __LINE__,
82 "The number of dimension for Aquarius Level 3 map data must be 1");
84 string check_pass_fileid_key_str=
"H5.EnablePassFileID";
85 bool check_pass_fileid_key =
false;
87 if(
false == check_pass_fileid_key) {
88 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
90 eherr <<
"HDF5 File " << filename
91 <<
" cannot be opened. "<<endl;
92 throw InternalErr (__FILE__, __LINE__, eherr.str ());
97 if ((rootid = H5Gopen(fileid,
"/",H5P_DEFAULT)) < 0) {
101 eherr <<
"HDF5 dataset " << varname
102 <<
" cannot be opened. "<<endl;
103 throw InternalErr (__FILE__, __LINE__, eherr.str ());
106 float LL_first_point = 0.0;
108 int LL_total_num = 0;
111 string Lat_SWP_name =(
Aqu_L3 == product_type)?
"SW Point Latitude":
"sw_point_latitude";
112 string Lat_step_name =(
Aqu_L3== product_type)?
"Latitude Step":
"latitude_step";
113 string Num_lines_name =(
Aqu_L3== product_type)?
"Number of Lines":
"number_of_lines";
115 float Lat_step = 0.0;
117 vector<char> dummy_str;
119 obtain_ll_attr_value(fileid,rootid,Lat_SWP_name,Lat_SWP,dummy_str);
120 obtain_ll_attr_value(fileid,rootid,Lat_step_name,Lat_step,dummy_str);
121 obtain_ll_attr_value(fileid,rootid,Num_lines_name,Num_lines,dummy_str);
123 if (Num_lines <= 0) {
127 throw InternalErr(__FILE__,__LINE__,
"The number of line must be >0");
131 LL_first_point = Lat_SWP + (Num_lines -1)*Lat_step;
132 LL_step = Lat_step *(-1.0);
133 LL_total_num = Num_lines;
137 string Lon_SWP_name =(
Aqu_L3==product_type)?
"SW Point Longitude":
"sw_point_longitude";
138 string Lon_step_name =(
Aqu_L3==product_type)?
"Longitude Step":
"longitude_step";
139 string Num_columns_name =(
Aqu_L3==product_type)?
"Number of Columns":
"number_of_columns";
141 float Lon_step = 0.0;
144 vector<char>dummy_str_value;
146 obtain_ll_attr_value(fileid,rootid,Lon_SWP_name,Lon_SWP,dummy_str_value);
147 obtain_ll_attr_value(fileid,rootid,Lon_step_name,Lon_step,dummy_str_value);
148 obtain_ll_attr_value(fileid,rootid,Num_columns_name,Num_cols,dummy_str_value);
153 throw InternalErr(__FILE__,__LINE__,
"The number of line must be >0");
157 LL_first_point = Lon_SWP;
159 LL_total_num = Num_cols;
165 if (nelms > LL_total_num) {
169 throw InternalErr (__FILE__, __LINE__,
170 "The number of elements exceeds the total number of Latitude or Longitude");
173 for (
int i = 0; i < nelms; ++i)
174 val[i] = LL_first_point + (offset[0] + i*step[0])*LL_step;
176 set_value ((dods_float32 *) &val[0], nelms);
183 void HDF5GMCFMissLLArray::obtain_gpm_l3_ll(
int* offset,
int* step,
int nelms) {
186 throw InternalErr (__FILE__, __LINE__,
187 "The number of dimension for Aquarius Level 3 map data must be 1");
189 string check_pass_fileid_key_str=
"H5.EnablePassFileID";
190 bool check_pass_fileid_key =
false;
193 if(
false == check_pass_fileid_key) {
194 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
196 eherr <<
"HDF5 File " << filename
197 <<
" cannot be opened. "<<endl;
198 throw InternalErr (__FILE__, __LINE__, eherr.str ());
202 hid_t grid_grp_id = -1;
204 string grid_grp_name;
208 if((name() ==
"nlat") || (name() ==
"nlon")) {
209 string temp_grid_grp_name(GPM_GRID_GROUP_NAME1,strlen(GPM_GRID_GROUP_NAME1));
210 temp_grid_grp_name =
"/" + temp_grid_grp_name;
211 if(H5Lexists(fileid,temp_grid_grp_name.c_str(),H5P_DEFAULT) >0)
212 grid_grp_name = temp_grid_grp_name;
214 string temp_grid_grp_name2(GPM_GRID_GROUP_NAME2,strlen(GPM_GRID_GROUP_NAME2));
215 temp_grid_grp_name2 =
"/"+temp_grid_grp_name2;
216 if(H5Lexists(fileid,temp_grid_grp_name2.c_str(),H5P_DEFAULT) >0)
217 grid_grp_name = temp_grid_grp_name2;
219 throw InternalErr (__FILE__, __LINE__,
"Unknown GPM grid group name ");
225 string temp_grids_group_name(GPM_GRID_MULTI_GROUP_NAME,strlen(GPM_GRID_MULTI_GROUP_NAME));
226 if(name() ==
"lnH" || name() ==
"ltH")
227 grid_grp_name = temp_grids_group_name +
"/G2" ;
228 else if(name() ==
"lnL" || name() ==
"ltL")
229 grid_grp_name = temp_grids_group_name +
"/G1" ;
236 if(name() ==
"lnH" || name() ==
"ltH" ||
237 name() ==
"lnL" || name() ==
"ltL") {
238 string temp_grids_group_name(GPM_GRID_MULTI_GROUP_NAME,strlen(GPM_GRID_MULTI_GROUP_NAME));
240 cerr<<
"varname is "<<varname <<endl;
241 size_t grids_group_pos = varname.find(temp_grids_group_name);
242 if(string::npos == grids_group_pos) {
243 throw InternalErr (__FILE__, __LINE__,
244 "Cannot find group Grids.");
247 string grids_cgroup_path = varname.substr(grids_group_pos+1);
248 size_t grids_cgroup_pos = varname.find_first_of(
"/");
249 if(string::npos == grids_cgroup_pos) {
250 throw InternalErr (__FILE__, __LINE__,
251 "Cannot find child group of group Grids.");
254 string temp_sub_grp_name = grids_cgroup_path.substr(0,grids_cgroup_pos);
255 if(name() ==
"lnH" || name() ==
"ltH")
256 sub_grp1_name = temp_sub_grp_name;
257 else if(name() ==
"lnL" || name() ==
"ltL")
258 sub_grp2_name = temp_sub_grp_name;
260 grid_grp_name = temp_grids_group_name +
"/" + temp_sub_grp_name;
265 if ((grid_grp_id = H5Gopen(fileid,grid_grp_name.c_str(),H5P_DEFAULT)) < 0) {
268 eherr <<
"HDF5 dataset " << varname
269 <<
" cannot be opened. "<<endl;
270 throw InternalErr (__FILE__, __LINE__, eherr.str ());
274 string grid_info_name(GPM_ATTR2_NAME,strlen(GPM_ATTR2_NAME));
275 if(name() ==
"lnL" || name() ==
"ltL")
276 grid_info_name =
"G1_" + grid_info_name;
277 else if(name() ==
"lnH" || name() ==
"ltH")
278 grid_info_name =
"G2_" + grid_info_name;
280 vector<char> grid_info_value;
281 float dummy_value = 0.0;
283 obtain_ll_attr_value(fileid,grid_grp_id,grid_info_name,dummy_value,grid_info_value);
291 float lat_start = 0;;
292 float lon_start = 0.;
301 lat_start,lon_start,lat_res,lon_res,
false);
303 if(0 == latsize || 0 == lonsize) {
305 throw InternalErr (__FILE__, __LINE__,
"Either latitude or longitude size is 0. ");
313 if(nelms > latsize) {
314 H5Gclose(grid_grp_id);
317 throw InternalErr (__FILE__, __LINE__,
318 "The number of elements exceeds the total number of Latitude ");
321 for (
int i = 0; i < nelms; ++i)
322 val[i] = lat_start+offset[0]*lat_res+lat_res/2 + i*lat_res*step[0];
326 if(nelms > lonsize) {
327 H5Gclose(grid_grp_id);
330 throw InternalErr (__FILE__, __LINE__,
331 "The number of elements exceeds the total number of Longitude");
335 for (
int i = 0; i < nelms; ++i)
336 val[i] = lon_start+offset[0]*lon_res+lon_res/2 + i*lon_res*step[0];
339 set_value ((dods_float32 *) &val[0], nelms);
341 H5Gclose(grid_grp_id);
350 if (nelms > LL_total_num) {
353 throw InternalErr (__FILE__, __LINE__,
354 "The number of elements exceeds the total number of Latitude or Longitude");
357 for (
int i = 0; i < nelms; ++i)
358 val[i] = LL_first_point + (offset[0] + i*step[0])*LL_step;
360 set_value ((dods_float32 *) &val[0], nelms);
368 void HDF5GMCFMissLLArray::obtain_ll_attr_value(hid_t file_id, hid_t s_root_id,
369 const string & s_attr_name, T& attr_value,
370 vector<char> & str_attr_value) {
372 hid_t s_attr_id = -1;
373 if ((s_attr_id = H5Aopen_by_name(s_root_id,
".",s_attr_name.c_str(),
374 H5P_DEFAULT, H5P_DEFAULT)) <0) {
375 string msg =
"Cannot open the HDF5 attribute ";
379 throw InternalErr(__FILE__, __LINE__, msg);
382 hid_t attr_type = -1;
383 if ((attr_type = H5Aget_type(s_attr_id)) < 0) {
384 string msg =
"cannot get the attribute datatype for the attribute ";
389 throw InternalErr(__FILE__, __LINE__, msg);
392 hid_t attr_space = -1;
393 if ((attr_space = H5Aget_space(s_attr_id)) < 0) {
394 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
400 throw InternalErr(__FILE__, __LINE__, msg);
403 int num_elm = H5Sget_simple_extent_npoints(attr_space);
406 string msg =
"cannot get the number for the attribute ";
410 H5Sclose(attr_space);
413 throw InternalErr(__FILE__, __LINE__, msg);
417 string msg =
"The number of attribute must be 1 for Aquarius level 3 data ";
421 H5Sclose(attr_space);
424 throw InternalErr(__FILE__, __LINE__, msg);
428 size_t atype_size = H5Tget_size(attr_type);
429 if (atype_size <= 0) {
430 string msg =
"cannot obtain the datatype size of the attribute ";
434 H5Sclose(attr_space);
437 throw InternalErr(__FILE__, __LINE__, msg);
440 if(H5T_STRING == H5Tget_class(attr_type)) {
441 if(H5Tis_variable_str(attr_type)) {
444 H5Sclose(attr_space);
446 throw InternalErr(__FILE__,__LINE__,
447 "Currently we assume the attributes we use to retrieve lat and lon are NOT variable length string.");
450 str_attr_value.resize(atype_size);
451 if (H5Aread(s_attr_id,attr_type, &str_attr_value[0])<0){
452 string msg =
"cannot retrieve the value of the attribute ";
456 H5Sclose(attr_space);
459 throw InternalErr(__FILE__, __LINE__, msg);
465 else if (H5Aread(s_attr_id,attr_type, &attr_value)<0){
466 string msg =
"cannot retrieve the value of the attribute ";
470 H5Sclose(attr_space);
473 throw InternalErr(__FILE__, __LINE__, msg);
478 H5Sclose(attr_space);
492 Dim_iter p = dim_begin ();
494 while (p != dim_end ()) {
496 int start = dimension_start (p,
true);
497 int stride = dimension_stride (p,
true);
498 int stop = dimension_stop (p,
true);
502 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
505 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
506 ":" << stride <<
":" << stop <<
"]";
507 throw Error (malformed_expr, oss.str ());
511 if (start == 0 && stop == 0 && stride == 0) {
512 start = dimension_start (p,
false);
513 stride = dimension_stride (p,
false);
514 stop = dimension_stop (p,
false);
519 count[id] = ((stop - start) / stride) + 1;
523 "=format_constraint():"
524 <<
"id=" <<
id <<
" offset=" << offset[
id]
525 <<
" step=" << step[
id]
526 <<
" count=" << count[
id]
This class specifies the retrieval of the missing lat/lon values for general HDF5 products...
static void close_fileid(hid_t, bool)
static void parser_gpm_l3_gridheader(const std::vector< char > &value, int &latsize, int &lonsize, float &lat_start, float &lon_start, float &lat_res, float &lon_res, bool check_reg_orig)
static bool check_beskeys(const string key)
virtual BaseType * ptr_duplicate()
HDF5GMCFMissLLArray(int rank, const string &filename, const hid_t fileid, H5DataType dtype, const string &varfullpath, H5GCFProduct product_type, CVType cvartype, const string &n="", BaseType *v=0)
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
int format_constraint(int *cor, int *step, int *edg)