44#include "h5apicompatible.h"
47using namespace HDF5CF;
52 newname = var->newname;
54 fullpath = var->fullpath;
56 total_elems = var->total_elems;
57 zero_storage_size = var->zero_storage_size;
59 comp_ratio = var->comp_ratio;
60 unsupported_attr_dtype = var->unsupported_attr_dtype;
61 unsupported_attr_dspace = var->unsupported_attr_dspace;
62 unsupported_dspace = var->unsupported_dspace;
63 unsupported_attr_dspace = var->unsupported_attr_dspace;
64 dimnameflag = var->dimnameflag;
65 coord_attr_add_path = var->coord_attr_add_path;
67 for (
auto ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
69 attr->name = (*ira)->name;
70 attr->newname = (*ira)->newname;
71 attr->dtype = (*ira)->dtype;
72 attr->count = (*ira)->count;
73 attr->strsize = (*ira)->strsize;
74 attr->fstrsize = (*ira)->fstrsize;
75 attr->value = (*ira)->value;
76 attrs.push_back(attr);
79 for (
auto ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
81 dim->name = (*ird)->name;
82 dim->newname = (*ird)->newname;
83 dim->unlimited_dim = (*ird)->unlimited_dim;
89bool CVar::isLatLon()
const
92 bool ret_value =
false;
93 if (CV_EXIST == this->cvartype || CV_MODIFY == this->cvartype || CV_SPECIAL == this->cvartype) {
94 string attr_name =
"units";
95 string lat_unit_value =
"degrees_north";
96 string lon_unit_value =
"degrees_east";
98 for (
auto ira = this->attrs.begin(); ira != this->attrs.end(); ira++) {
100 if ((H5FSTRING == (*ira)->getType()) || (H5VSTRING == (*ira)->getType())) {
101 if (attr_name == (*ira)->newname) {
102 string attr_value1((*ira)->getValue().begin(), (*ira)->getValue().end());
104 if ((*ira)->getCount() == 1) {
105 string attr_value((*ira)->getValue().begin(), (*ira)->getValue().end());
106 if (attr_value.compare(0, lat_unit_value.size(), lat_unit_value) == 0) {
107 if (attr_value.size() == lat_unit_value.size()) {
111 else if (attr_value.size() == (lat_unit_value.size() + 1)) {
112 if (attr_value[attr_value.size() - 1] ==
'\0'
113 || attr_value[attr_value.size() - 1] ==
' ') {
119 else if (attr_value.compare(0, lon_unit_value.size(), lon_unit_value) == 0) {
120 if (attr_value.size() == lon_unit_value.size()) {
124 else if (attr_value.size() == (lon_unit_value.size() + 1)) {
125 if (attr_value[attr_value.size() - 1] ==
'\0'
126 || attr_value[attr_value.size() - 1] ==
' ') {
139 else if (this->cvartype == CV_LAT_MISS || this->cvartype == CV_LON_MISS) ret_value =
true;
146 if (this->fileid >= 0) {
147 if (this->rootid >= 0) {
158 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
163 for_each(this->dims.begin(), this->dims.end(),
delete_elem());
164 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
171 BESDEBUG(
"h5",
"coming to Retrieve_H5_Info" <<endl);
173 if (
true == include_attr) {
177 this->check_ignored = HDF5RequestHandler::get_check_ignore_obj();
178 if (
true == this->check_ignored) this->add_ignored_info_page_header();
183 if ((root_id = H5Gopen(file_id,
"/", H5P_DEFAULT)) < 0) {
184 throw1(
"Cannot open the HDF5 root group ");
186 this->rootid = root_id;
188 this->Retrieve_H5_Obj(root_id,
"/", include_attr);
195 if (
true == include_attr) {
203 if (H5OGET_INFO(root_id, &oinfo) < 0)
204 throw1(
"Error obtaining the info for the root group");
206 num_attrs = (
int)(oinfo.num_attrs);
207 bool temp_unsup_attr_atype =
false;
208 bool temp_unsup_attr_dspace =
false;
210 for (
int j = 0; j < num_attrs; j++) {
213 this->Retrieve_H5_Attr_Info(attr, root_id, j, temp_unsup_attr_atype, temp_unsup_attr_dspace);
223 this->unsupported_attr_dtype = temp_unsup_attr_atype;
224 this->unsupported_attr_dspace = temp_unsup_attr_dspace;
228void File::Retrieve_H5_Obj(hid_t grp_id,
const char*gname,
bool include_attr)
235 if (H5Gget_info(grp_id, &g_info) < 0)
236 throw2(
"Counting hdf5 group elements error for ", gname);
237 nelems = g_info.nlinks;
239 ssize_t oname_size = 0;
240 for (hsize_t i = 0; i < nelems; i++) {
244 Group *group =
nullptr;
250 size_t dummy_name_len = 1;
253 oname_size = H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i,
nullptr, dummy_name_len,
256 throw2(
"Error getting the size of the hdf5 object from the group: ", gname);
260 oname.resize((
size_t) oname_size + 1);
262 if (H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, oname.data(), (
size_t) (oname_size + 1),
264 throw2(
"Error getting the hdf5 object name from the group: ", gname);
268 if (H5Lget_info(grp_id, oname.data(), &linfo, H5P_DEFAULT) < 0)
269 throw2(
"HDF5 link name error from ", gname);
272 if (H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type) {
273 if (
true == include_attr &&
true == check_ignored) {
274 this->add_ignored_info_links_header();
275 string full_path_name;
276 string temp_oname(oname.begin(), oname.end());
278 (string(gname) !=
"/") ?
279 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
280 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
281 this->add_ignored_info_links(full_path_name);
290 if (H5OGET_INFO_BY_IDX(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT) < 0)
291 throw2(
"Error obtaining the info for the object ",
string(oname.begin(), oname.end()));
293 H5O_type_t obj_type = oinfo.type;
297 case H5O_TYPE_GROUP: {
300 string full_path_name;
301 string temp_oname(oname.begin(), oname.end());
304 (string(gname) !=
"/") ?
305 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
306 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
308 cgroup = H5Gopen(grp_id, full_path_name.c_str(), H5P_DEFAULT);
310 throw2(
"Error opening the group ", full_path_name);
313 group->path = full_path_name;
314 group->newname = full_path_name;
317 if (
true == include_attr) {
319 int num_attrs = (
int)(oinfo.num_attrs);
320 bool temp_unsup_attr_dtype =
false;
321 bool temp_unsup_attr_dspace =
false;
323 for (
int j = 0; j < num_attrs; j++) {
326 Retrieve_H5_Attr_Info(attr, cgroup, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
327 group->attrs.push_back(attr);
331 group->unsupported_attr_dtype = temp_unsup_attr_dtype;
332 group->unsupported_attr_dspace = temp_unsup_attr_dspace;
334 this->
groups.push_back(group);
335 Retrieve_H5_Obj(cgroup, full_path_name.c_str(), include_attr);
336 if (H5Gclose(cgroup) < 0)
337 throw2(
"Error closing the group ", full_path_name);
340 case H5O_TYPE_DATASET: {
343 string temp_oname(oname.begin(), oname.end());
344 string full_path_name = (
345 (string(gname) !=
"/") ?
346 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
347 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
350 var->name = temp_oname.substr(0, temp_oname.size() - 1);
351 var->fullpath = full_path_name;
354 var->newname = full_path_name;
356 cdset = H5Dopen(grp_id, full_path_name.c_str(), H5P_DEFAULT);
358 throw2(
"Error opening the HDF5 dataset ", full_path_name);
361 bool temp_unsup_var_dtype =
false;
362 Retrieve_H5_VarType(var, cdset, full_path_name, temp_unsup_var_dtype);
365 if (!this->unsupported_var_dtype && temp_unsup_var_dtype) this->unsupported_var_dtype =
true;
368 bool temp_unsup_var_dspace =
false;
369 Retrieve_H5_VarDim(var, cdset, full_path_name, temp_unsup_var_dspace);
372 if (!this->unsupported_var_dspace && temp_unsup_var_dspace) this->unsupported_var_dspace =
true;
374 hsize_t d_storage_size = H5Dget_storage_size(cdset);
375 var->zero_storage_size =(d_storage_size ==0);
376 var->comp_ratio = Retrieve_H5_VarCompRatio(var, cdset);
379 if (
true == include_attr) {
381 int num_attrs = (
int)(oinfo.num_attrs);
382 bool temp_unsup_attr_dtype =
false;
383 bool temp_unsup_attr_dspace =
false;
385 for (
int j = 0; j < num_attrs; j++) {
389 Retrieve_H5_Attr_Info(attr, cdset, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
390 var->attrs.push_back(attr);
394 var->unsupported_attr_dtype = temp_unsup_attr_dtype;
395 var->unsupported_attr_dspace = temp_unsup_attr_dspace;
397 if (!this->unsupported_var_attr_dspace && temp_unsup_attr_dspace)
398 this->unsupported_var_attr_dspace =
true;
401 this->
vars.push_back(var);
402 if (H5Dclose(cdset) < 0)
403 throw2(
"Error closing the HDF5 dataset ", full_path_name);
407 case H5O_TYPE_NAMED_DATATYPE: {
409 if (
true == include_attr &&
true == check_ignored) {
410 this->add_ignored_info_namedtypes(
string(gname),
string(oname.begin(), oname.end()));
420 if (attr !=
nullptr) {
425 if (var !=
nullptr) {
430 if (group !=
nullptr) {
435 if (cgroup != -1) H5Gclose(cgroup);
437 if (cdset != -1) H5Dclose(cdset);
446float File::Retrieve_H5_VarCompRatio(
const Var *var,
const hid_t dset_id)
const
449 float comp_ratio = 1.0;
451 hid_t dset_create_plist = H5Dget_create_plist(dset_id);
452 if (dset_create_plist < 0)
453 throw1(
"unable to obtain hdf5 dataset creation property list ");
454 H5D_layout_t dset_layout = H5Pget_layout(dset_create_plist);
455 if (dset_layout < 0) {
456 H5Pclose(dset_create_plist);
457 throw1(
"unable to obtain hdf5 dataset creation property list storage layout");
460 if (dset_layout == H5D_CHUNKED) {
462 hsize_t dstorage_size = H5Dget_storage_size(dset_id);
463 if (dstorage_size > 0 && var->total_elems > 0) {
467 if ((ty_id = H5Dget_type(dset_id)) < 0)
468 throw1(
"unable to obtain hdf5 datatype for the dataset ");
469 size_t type_size = H5Tget_size(ty_id);
470 comp_ratio = ((float)((var->total_elems) * type_size))/dstorage_size;
475 H5Pclose(dset_create_plist);
480void File::Retrieve_H5_VarType(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dtype)
486 if ((ty_id = H5Dget_type(dset_id)) < 0)
487 throw2(
"unable to obtain hdf5 datatype for the dataset ", varname);
506 if (
false == HDF5CFUtil::cf_strict_support_type(var->dtype,_is_dap4))
507 unsup_var_dtype =
true;
509 if (H5Tclose(ty_id) < 0)
510 throw1(
"Unable to close the HDF5 datatype ");;
514void File::Retrieve_H5_VarDim(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dspace)
517 vector<hsize_t> dsize;
518 vector<hsize_t> maxsize;
520 hid_t dspace_id = -1;
524 if ((dspace_id = H5Dget_space(dset_id)) < 0)
525 throw2(
"Cannot get hdf5 dataspace id for the variable ", varname);
527 H5S_class_t space_class = H5S_NO_CLASS;
528 if ((space_class = H5Sget_simple_extent_type(dspace_id)) < 0)
529 throw2(
"Cannot obtain the HDF5 dataspace class for the variable ", varname);
531 if (H5S_NULL == space_class)
532 unsup_var_dspace =
true;
534 if (
false == unsup_var_dspace) {
536 hssize_t h5_total_elms = H5Sget_simple_extent_npoints(dspace_id);
537 if (h5_total_elms < 0)
538 throw2(
"Cannot get the total number of elements of HDF5 dataset ", varname);
540 var->total_elems = (size_t) h5_total_elms;
541 int ndims = H5Sget_simple_extent_ndims(dspace_id);
543 throw2(
"Cannot get the hdf5 dataspace number of dimension for the variable ", varname);
548 maxsize.resize(ndims);
553 if (H5Sget_simple_extent_dims(dspace_id, dsize.data(), maxsize.data()) < 0)
554 throw2(
"Cannot obtain the dim. info for the variable ", varname);
556 for (
int i = 0; i < ndims; i++) {
558 if (maxsize[i] == H5S_UNLIMITED) {
559 dim->unlimited_dim =
true;
560 if (
false == have_udim)
563 var->dims.push_back(dim);
568 var->unsupported_dspace = unsup_var_dspace;
570 if (H5Sclose(dspace_id) < 0)
571 throw1(
"Cannot close the HDF5 dataspace .");
577 if (dspace_id != -1) H5Sclose(dspace_id);
579 if (ty_id != -1) H5Tclose(ty_id);
586void File::Retrieve_H5_Attr_Info(
Attribute * attr, hid_t obj_id,
const int j,
bool &unsup_attr_dtype,
587 bool &unsup_attr_dspace)
593 hid_t aspace_id = -1;
599 if ((attrid = H5Aopen_by_idx(obj_id,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) j, H5P_DEFAULT,
601 throw1(
"Unable to open attribute by index ");
604 ssize_t name_size = H5Aget_name(attrid, 0,
nullptr);
606 throw1(
"Unable to obtain the size of the hdf5 attribute name ");
609 attr_name.resize(name_size + 1);
612 if ((H5Aget_name(attrid, name_size + 1, &attr_name[0])) < 0)
613 throw1(
"unable to obtain the hdf5 attribute name ");
616 if ((ty_id = H5Aget_type(attrid)) < 0)
617 throw2(
"unable to obtain hdf5 datatype for the attribute ", attr_name);
635 if (
false == HDF5CFUtil::cf_strict_support_type(attr->dtype,_is_dap4))
636 unsup_attr_dtype =
true;
638 if(H5VSTRING == attr->dtype || H5FSTRING == attr->dtype) {
639 H5T_cset_t c_set_type = H5Tget_cset(ty_id);
641 throw2(
"Cannot get hdf5 character set type for the attribute ", attr_name);
644 attr->is_cset_ascii =
false;
647 if ((aspace_id = H5Aget_space(attrid)) < 0)
648 throw2(
"Cannot get hdf5 dataspace id for the attribute ", attr_name);
650 int ndims = H5Sget_simple_extent_ndims(aspace_id);
652 throw2(
"Cannot get the hdf5 dataspace number of dimension for attribute ", attr_name);
659 vector<hsize_t> asize;
660 vector<hsize_t> maxsize;
662 maxsize.resize(ndims);
665 if (H5Sget_simple_extent_dims(aspace_id, asize.data(), maxsize.data()) < 0)
666 throw2(
"Cannot obtain the dim. info for the attribute ", attr_name);
669 for (
int dim_count = 0;dim_count < ndims; dim_count ++) {
671 if (asize[dim_count] == 0) {
672 unsup_attr_dspace =
true;
677 if (
false == unsup_attr_dspace) {
679 for (
int dim_count = 0; dim_count< ndims; dim_count++)
680 nelmts *= asize[dim_count];
686 size_t ty_size = H5Tget_size(ty_id);
688 throw2(
"Cannot obtain the dtype size for the attribute ", attr_name);
690 memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
692 throw2(
"Cannot obtain the memory datatype for the attribute ", attr_name);
695 string temp_aname(attr_name.begin(), attr_name.end());
696 attr->name = temp_aname.substr(0, temp_aname.size() - 1);
697 attr->newname = attr->name;
698 attr->count = nelmts;
701 if (H5Tclose(ty_id) < 0)
702 throw1(
"Cannot successfully close the attribute datatype.");
703 if (H5Tclose(memtype) < 0)
704 throw1(
"Cannot successfully close the attribute memory datatype.");
705 if (H5Sclose(aspace_id) < 0)
706 throw1(
"Cannot successfully close the HDF5 dataspace.");
707 if (H5Aclose(attrid) < 0)
708 throw1(
"Cannot successfully close the HDF5 attribute.");
713 if (ty_id != -1) H5Tclose(ty_id);
715 if (memtype != -1) H5Tclose(memtype);
717 if (aspace_id != -1) H5Sclose(aspace_id);
719 if (attrid != -1) H5Aclose(attrid);
730 for (
auto ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira)
731 Retrieve_H5_Attr_Value(*ira,
"/");
733 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
734 for (
auto ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
735 Retrieve_H5_Attr_Value(*ira, (*irg)->path);
739 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
740 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
741 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
748 for (
auto ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
749 Retrieve_H5_Attr_Value(*ira, var->fullpath);
754void File::Retrieve_H5_Attr_Value(
Attribute *attr,
const string & obj_name)
761 hid_t memtype_id = -1;
762 hid_t aspace_id = -1;
767 obj_id = H5Oopen(this->fileid, obj_name.c_str(), H5P_DEFAULT);
769 throw2(
"Cannot open the object ", obj_name);
771 attr_id = H5Aopen(obj_id, (attr->name).c_str(), H5P_DEFAULT);
773 throw4(
"Cannot open the attribute ", attr->name,
" of object ", obj_name);
775 ty_id = H5Aget_type(attr_id);
777 throw4(
"Cannot obtain the datatype of the attribute ", attr->name,
" of object ", obj_name);
779 memtype_id = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
781 throw2(
"Cannot obtain the memory datatype for the attribute ", attr->name);
783 size_t ty_size = H5Tget_size(memtype_id);
785 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
787 size_t total_bytes = attr->count * ty_size;
790 if (H5VSTRING == attr->dtype) {
793 vector<char> temp_buf;
794 temp_buf.resize(total_bytes);
796 if (H5Aread(attr_id, memtype_id, temp_buf.data()) < 0)
797 throw4(
"Cannot obtain the value of the attribute ", attr->name,
" of object ", obj_name);
799 char *temp_bp =
nullptr;
800 char *ptr_1stvlen_ptr = temp_buf.data();
801 temp_bp = temp_buf.data();
802 char* onestring =
nullptr;
803 string total_vstring =
"";
805 attr->strsize.resize(attr->count);
807 for (
unsigned int temp_i = 0; temp_i < attr->count; temp_i++) {
810 onestring = *(
char **) temp_bp;
811 if (onestring !=
nullptr) {
812 total_vstring += string(onestring);
813 attr->strsize[temp_i] = (string(onestring)).size();
816 attr->strsize[temp_i] = 0;
822 if (ptr_1stvlen_ptr !=
nullptr) {
823 aspace_id = H5Aget_space(attr_id);
825 throw4(
"Cannot obtain space id for ", attr->name,
" of object ", obj_name);
828 if (H5Dvlen_reclaim(memtype_id, aspace_id, H5P_DEFAULT, temp_buf.data()) < 0)
829 throw4(
"Cannot reclaim VL memory for ", attr->name,
" of object ", obj_name);
835 throw4(
"Error to obtain the VL string type for attribute ", attr->name,
" of object ", obj_name);
837 attr->value.resize(total_vstring.size());
839 copy(total_vstring.begin(), total_vstring.end(), attr->value.begin());
844 if (attr->dtype == H5FSTRING) {
845 attr->fstrsize = ty_size;
848 attr->value.resize(total_bytes);
851 if (H5Aread(attr_id, memtype_id, (
void *) &attr->value[0]) < 0)
852 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
854 if (attr->dtype == H5FSTRING) {
856 size_t sect_size = ty_size;
860 (total_bytes % sect_size == 0) ? (total_bytes / sect_size) : (total_bytes / sect_size + 1);
862 throw4(
"The attribute datatype size is not a positive integer ", attr->name,
" of object ",
865 vector<size_t> sect_newsize;
866 sect_newsize.resize(num_sect);
868 auto total_fstring = string(attr->value.begin(), attr->value.end());
872 attr->value.resize(new_total_fstring.size());
873 copy(new_total_fstring.begin(), new_total_fstring.end(), attr->value.begin());
874 attr->strsize.resize(num_sect);
875 for (
int temp_i = 0; temp_i < num_sect; temp_i++)
876 attr->strsize[temp_i] = sect_newsize[temp_i];
880 cerr<<
"Attr name is "<<attr->name <<endl;
881 for (
int temp_i = 0; temp_i <num_sect; temp_i ++)
882 cerr<<
"string new section size = " << attr->strsize[temp_i] <<endl;
887 if (H5Tclose(memtype_id) < 0)
888 throw1(
"Fail to close the HDF5 memory datatype ID.");
889 if (H5Tclose(ty_id) < 0)
890 throw1(
"Fail to close the HDF5 datatype ID.");
891 if (H5Aclose(attr_id) < 0)
892 throw1(
"Fail to close the HDF5 attribute ID.");
893 if (H5Oclose(obj_id) < 0)
894 throw1(
"Fail to close the HDF5 object ID.");
900 if (memtype_id != -1) H5Tclose(memtype_id);
902 if (ty_id != -1) H5Tclose(ty_id);
904 if (aspace_id != -1) H5Sclose(aspace_id);
906 if (attr_id != -1) H5Aclose(attr_id);
908 if (obj_id != -1) H5Oclose(obj_id);
919 if (
true == include_attr) {
920 Handle_Group_Unsupported_Dtype();
921 Handle_VarAttr_Unsupported_Dtype();
924 Handle_Var_Unsupported_Dtype();
930if (
true == include_attr) {
931 if (
true == this->unsupported_attr_dtype) {
932 for (vector<Attribute *>::iterator ira = this->root_attrs.begin();
933 ira != this->root_attrs.end(); ) {
934 H5DataType temp_dtype = (*ira)->getType();
935 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
937 ira = this->root_attrs.erase(ira);
948if (
false == this->groups.empty()) {
949 for (vector<Group *>::iterator irg = this->groups.begin();
950 irg != this->groups.end(); ++irg) {
951 if (
false == (*irg)->attrs.empty()) {
952 if (
true == (*irg)->unsupported_attr_dtype) {
953 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin();
954 ira != (*irg)->attrs.end(); ) {
955 H5DataType temp_dtype = (*ira)->getType();
956 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
958 ira = (*irg)->attrs.erase(ira);
971if (
false == this->vars.empty()) {
972if (
true == include_attr) {
973 for (vector<Var *>::iterator irv = this->vars.begin();
974 irv != this->vars.end();++irv ) {
975 if (
false == (*irv)->attrs.empty()) {
976 if (
true == (*irv)->unsupported_attr_dtype) {
977 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
978 ira != (*irv)->attrs.end(); ) {
979 H5DataType temp_dtype = (*ira)->getType();
980 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
982 ira = (*irv)->attrs.erase(ira);
993if (
true == this->unsupported_var_dtype) {
995 for (vector<Var *>::iterator irv = this->vars.begin();
996 irv != this->vars.end(); ) {
997 H5DataType temp_dtype = (*irv)->getType();
998 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1000 irv = this->vars.erase(irv);
1010void File::Handle_Group_Unsupported_Dtype()
1015 if (
true == this->unsupported_attr_dtype) {
1016 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1017 H5DataType temp_dtype = (*ira)->getType();
1018 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1030 if (
false == this->
groups.empty()) {
1031 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1032 if (
false == (*irg)->attrs.empty()) {
1033 if (
true == (*irg)->unsupported_attr_dtype) {
1034 for (
auto ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1035 H5DataType temp_dtype = (*ira)->getType();
1036 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1038 ira = (*irg)->attrs.erase(ira);
1051void File::Gen_Group_Unsupported_Dtype_Info()
1057 for (
auto ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1058 H5DataType temp_dtype = (*ira)->getType();
1061 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1062 || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
1063 this->add_ignored_info_attrs(
true,
"/", (*ira)->name);
1070 if (
false == this->
groups.empty()) {
1071 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1072 if (
false == (*irg)->attrs.empty()) {
1074 for (
auto ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1075 H5DataType temp_dtype = (*ira)->getType();
1078 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1079 || temp_dtype == H5INT64 || temp_dtype==H5UINT64 ) {
1080 this->add_ignored_info_attrs(
true, (*irg)->path, (*ira)->name);
1090void File::Handle_Var_Unsupported_Dtype()
1092 if (
false == this->
vars.empty()) {
1093 if (
true == this->unsupported_var_dtype) {
1094 for (
auto irv = this->
vars.begin(); irv != this->vars.end();) {
1095 H5DataType temp_dtype = (*irv)->getType();
1096 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1098 irv = this->
vars.erase(irv);
1110void File::Gen_Var_Unsupported_Dtype_Info()
1113 if (
false == this->
vars.empty()) {
1115 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1116 H5DataType temp_dtype = (*irv)->getType();
1119 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1120 ||(H5INT64 == temp_dtype) ||(H5UINT64 == temp_dtype)) {
1121 this->add_ignored_info_objs(
false, (*irv)->fullpath);
1130void File::Handle_VarAttr_Unsupported_Dtype()
1132 if (
false == this->
vars.empty()) {
1133 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1134 if (
false == (*irv)->attrs.empty()) {
1135 if (
true == (*irv)->unsupported_attr_dtype) {
1136 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1137 H5DataType temp_dtype = (*ira)->getType();
1138 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1140 ira = (*irv)->attrs.erase(ira);
1153void File::Gen_VarAttr_Unsupported_Dtype_Info()
1156 if (
false == this->
vars.empty()) {
1157 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1158 if (
false == (*irv)->attrs.empty()) {
1160 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1161 H5DataType temp_dtype = (*ira)->getType();
1164 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1165 || (temp_dtype==H5INT64) || (temp_dtype == H5UINT64)) {
1166 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1179void File::Gen_DimScale_VarAttr_Unsupported_Dtype_Info()
1182 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1186 bool is_ignored = ignored_dimscale_ref_list((*irv));
1187 if (
false == (*irv)->attrs.empty()) {
1189 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1190 H5DataType temp_dtype = (*ira)->getType();
1192 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1193 || (temp_dtype == H5INT64) || (temp_dtype == H5UINT64)) {
1197 if ((
"DIMENSION_LIST" != (*ira)->name)
1198 && (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
1199 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1208void File::Handle_GroupAttr_Unsupported_Dspace()
1213 if (
true == this->unsupported_attr_dspace) {
1214 for (
auto ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1216 if ((*ira)->count == 0) {
1228 if (
false == this->
groups.empty()) {
1229 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1230 if (
false == (*irg)->attrs.empty()) {
1231 if (
true == (*irg)->unsupported_attr_dspace) {
1232 for (
auto ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1233 if ((*ira)->count == 0) {
1235 ira = (*irg)->attrs.erase(ira);
1248void File::Handle_VarAttr_Unsupported_Dspace()
1251 if (
false == this->
vars.empty()) {
1252 if (
true == this->unsupported_var_attr_dspace) {
1253 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1254 if (
false == (*irv)->attrs.empty()) {
1255 if (
true == (*irv)->unsupported_attr_dspace) {
1256 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1257 if (0 == (*ira)->count) {
1259 ira = (*irv)->attrs.erase(ira);
1277 if (
false == this->
vars.empty()) {
1278 if (
true == this->unsupported_var_dspace) {
1279 for (
auto irv = this->
vars.begin(); irv != this->vars.end();) {
1280 if (
true == (*irv)->unsupported_dspace) {
1282 irv = this->
vars.erase(irv);
1292 if (
true == include_attr) {
1293 Handle_GroupAttr_Unsupported_Dspace();
1294 Handle_VarAttr_Unsupported_Dspace();
1299void File::Gen_Unsupported_Dspace_Info()
1307 if (
false == this->
vars.empty()) {
1308 if (
true == this->unsupported_var_dspace) {
1309 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1310 if (
true == (*irv)->unsupported_dspace) {
1311 this->add_ignored_info_objs(
true, (*irv)->fullpath);
1323 if (
true == this->check_ignored &&
true == include_attr) {
1325 if (
true == HDF5RequestHandler::get_drop_long_string()) {
1329 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1330 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1331 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1332 this->add_ignored_droplongstr_hdr();
1333 this->add_ignored_grp_longstr_info(
"/", (*ira)->name);
1338 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1339 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1340 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1341 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1342 this->add_ignored_droplongstr_hdr();
1343 this->add_ignored_grp_longstr_info((*irg)->path, (*ira)->name);
1349 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1350 if (
true == Check_DropLongStr((*irv),
nullptr)) {
1351 this->add_ignored_droplongstr_hdr();
1352 this->add_ignored_var_longstr_info((*irv),
nullptr);
1356 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1357 if (
true == Check_DropLongStr((*irv), (*ira))) {
1358 this->add_ignored_droplongstr_hdr();
1359 this->add_ignored_var_longstr_info((*irv), (*ira));
1373 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1374 (*irv)->newname = get_CF_string((*irv)->newname);
1376 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1377 (*ird)->newname = get_CF_string((*ird)->newname);
1381 if (
true == include_attr) {
1383 for (
auto ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1384 (*ira)->newname = get_CF_string((*ira)->newname);
1387 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1388 (*irg)->newname = get_CF_string((*irg)->newname);
1389 for (
auto ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1390 (*ira)->newname = get_CF_string((*ira)->newname);
1394 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1395 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1396 (*ira)->newname = get_CF_string((*ira)->newname);
1403void File::Handle_Var_NameClashing(set<string>&objnameset)
1406 Handle_General_NameClashing(objnameset, this->
vars);
1410void File::Handle_Group_NameClashing(set<string> &objnameset)
1413 pair<set<string>::iterator,
bool> setret;
1423 setret = objnameset.insert(FILE_ATTR_TABLE_NAME);
1424 if (
false == setret.second) {
1426 int clash_index = 1;
1427 string fa_clash_name = FILE_ATTR_TABLE_NAME;
1428 HDF5CFUtil::gen_unique_name(fa_clash_name, objnameset, clash_index);
1429 FILE_ATTR_TABLE_NAME = fa_clash_name;
1433 Handle_General_NameClashing(objnameset, this->
groups);
1438void File::Handle_Obj_AttrNameClashing()
1449 set<string> objnameset;
1452 Handle_General_NameClashing(objnameset, this->
root_attrs);
1455 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1457 Handle_General_NameClashing(objnameset, (*irg)->attrs);
1461 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1463 Handle_General_NameClashing(objnameset, (*irv)->attrs);
1469template<
class T>
void File::Handle_General_NameClashing(set<string>&objnameset, vector<T*>& objvec)
1476 pair<set<string>::iterator,
bool> setret;
1477 set<string>::iterator iss;
1479 vector<string> clashnamelist;
1480 vector<string>::iterator ivs;
1482 map<int, int> cl_to_ol;
1487 typename vector<T*>::iterator irv;
1489 for (irv = objvec.begin(); irv != objvec.end(); ++irv) {
1490 setret = objnameset.insert((*irv)->newname);
1491 if (
false == setret.second) {
1492 clashnamelist.insert(clashnamelist.end(), (*irv)->newname);
1493 cl_to_ol[cl_index] = ol_index;
1501 for (ivs = clashnamelist.begin(); ivs != clashnamelist.end(); ivs++) {
1502 int clash_index = 1;
1503 string temp_clashname = *ivs +
'_';
1504 HDF5CFUtil::gen_unique_name(temp_clashname, objnameset, clash_index);
1505 *ivs = temp_clashname;
1509 for (
unsigned int i = 0; i < clashnamelist.size(); i++)
1510 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
1515void File::Handle_GeneralObj_NameClashing(
bool include_attr, set<string>& objnameset)
1518 Handle_Var_NameClashing(objnameset);
1519 if (
true == include_attr) {
1520 Handle_Group_NameClashing(objnameset);
1521 Handle_Obj_AttrNameClashing();
1526string File::get_CF_string(
string s)
1529 if (
"" == s)
return s;
1530 string insertString(1,
'_');
1533 if (
true == isdigit(s[0])) s.insert(0, insertString);
1535 for (
unsigned int i = 0; i < s.length(); i++)
1536 if ((
false == isalnum(s[i])) && (s[i] !=
'_')) s[i] =
'_';
1543void File::Insert_One_NameSizeMap_Element(
string name, hsize_t size,
bool unlimited)
1545 pair<map<string, hsize_t>::iterator,
bool> mapret;
1546 mapret = dimname_to_dimsize.insert(pair<string, hsize_t>(name, size));
1547 if (
false == mapret.second)
1548 throw4(
"The dimension name ", name,
" should map to ", size);
1550 pair<map<string, bool>::iterator,
bool> mapret2;
1551 mapret2 = dimname_to_unlimited.insert(pair<string, bool>(name, unlimited));
1552 if (
false == mapret2.second)
1553 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1558void File::Insert_One_NameSizeMap_Element2(map<string, hsize_t>& name_to_size, map<string, bool>& name_to_unlimited,
1559 string name, hsize_t size,
bool unlimited)
1561 pair<map<string, hsize_t>::iterator,
bool> mapret;
1562 mapret = name_to_size.insert(pair<string, hsize_t>(name, size));
1563 if (
false == mapret.second)
1564 throw4(
"The dimension name ", name,
" should map to ", size);
1566 pair<map<string, bool>::iterator,
bool> mapret2;
1567 mapret2 = name_to_unlimited.insert(pair<string, bool>(name, unlimited));
1568 if (
false == mapret2.second)
1569 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1586void File::Add_One_FakeDim_Name(
Dimension *dim)
1589 stringstream sfakedimindex;
1590 string fakedimstr =
"FakeDim";
1591 pair<set<string>::iterator,
bool> setret;
1592 map<hsize_t, string>::iterator im;
1593 pair<map<hsize_t, string>::iterator,
bool> mapret;
1595 sfakedimindex << addeddimindex;
1596 string added_dimname = fakedimstr + sfakedimindex.str();
1600 if (
false == mapret.second) {
1602 dim->newname = dim->name;
1609 setret = dimnamelist.insert(added_dimname);
1610 if (
false == setret.second) {
1611 int clash_index = 1;
1612 string temp_clashname = added_dimname +
'_';
1613 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1614 dim->name = temp_clashname;
1615 dim->newname = dim->name;
1616 setret = dimnamelist.insert(dim->name);
1617 if (
false == setret.second)
1618 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1624 if (
false == mapret.second)
1625 throw4(
"The dimension size ", dim->size,
" should map to ", dim->name);
1629 dim->name = added_dimname;
1630 dim->newname = dim->name;
1631 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1639void File::Adjust_Duplicate_FakeDim_Name(
Dimension * dim)
1647 stringstream sfakedimindex;
1648 pair<set<string>::iterator,
bool> setret;
1651 sfakedimindex << addeddimindex;
1652 string added_dimname =
"FakeDim" + sfakedimindex.str();
1653 setret = dimnamelist.insert(added_dimname);
1654 if (
false == setret.second) {
1655 int clash_index = 1;
1656 string temp_clashname = added_dimname +
'_';
1657 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1658 dim->name = temp_clashname;
1659 dim->newname = dim->name;
1660 setret = dimnamelist.insert(dim->name);
1661 if (
false == setret.second)
1662 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1664 dim->name = added_dimname;
1665 dim->newname = dim->name;
1666 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1679void File::Adjust_Duplicate_FakeDim_Name2(
Dimension * dim,
int dup_dim_size_index)
1687 bool dup_dim_size_exist =
false;
1688 int temp_dup_dim_size_index = 0;
1689 for (
unsigned i = 0; i <dup_dimsize_dimname.size();i++) {
1692 if(dim->size == dup_dimsize_dimname[i].first) {
1693 temp_dup_dim_size_index++;
1695 if(dup_dim_size_index == temp_dup_dim_size_index) {
1696 dup_dim_size_exist =
true;
1697 dim->name = dup_dimsize_dimname[i].second;
1698 dim->newname = dim->name;
1706 if(dup_dim_size_exist ==
false) {
1708 stringstream sfakedimindex;
1709 pair<set<string>::iterator,
bool> setret;
1711 sfakedimindex << addeddimindex;
1712 string added_dimname =
"FakeDim" + sfakedimindex.str();
1713 setret = dimnamelist.insert(added_dimname);
1714 if (
false == setret.second) {
1715 throw2(
"Inside Adjust_Duplicate_FakeDim_Name2(), Fail to insert the unique dim name ", dim->name);
1717 dim->name = added_dimname;
1718 dim->newname = dim->name;
1719 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1721 dup_dimsize_dimname.push_back(make_pair(dim->size,dim->name));
1730void File::Replace_Dim_Name_All(
const string orig_dim_name,
const string new_dim_name) {
1733 for (vector<Var *>::iterator irv = this->
vars.begin();
1734 irv != this->vars.end(); ++irv) {
1735 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1736 ird != (*irv)->dims.end(); ++ird) {
1737 if((*ird)->name == orig_dim_name) {
1738 (*ird)->name = new_dim_name;
1739 (*ird)->newname = new_dim_name;
1748void File::Use_Dim_Name_With_Size_All(
const string dim_name,
const size_t dim_size) {
1751 for (vector<Var *>::iterator irv = this->
vars.begin();
1752 irv != this->vars.end(); ++irv) {
1753 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1754 ird != (*irv)->dims.end(); ++ird) {
1755 if((*ird)->size == orig_dim_name) {
1756 (*ird)->name = new_dim_name;
1757 (*ird)->newname = new_dim_name;
1767void File::Add_Str_Attr(
Attribute* attr,
const string &attrname,
const string& strvalue)
1770 attr->name = attrname;
1771 attr->newname = attr->name;
1772 attr->dtype = H5FSTRING;
1774 attr->fstrsize = strvalue.size();
1775 attr->strsize.resize(1);
1776 attr->strsize[0] = attr->fstrsize;
1777 attr->value.resize(strvalue.size());
1778 copy(strvalue.begin(), strvalue.end(), attr->value.begin());
1783File:: Var_Has_Attr(
Var*var,
const string &attrname) {
1785 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end(); ++ira) {
1789 if((*ira)->name == attrname || (*ira)->newname == attrname) {
1798string File::Retrieve_Str_Attr_Value(
Attribute *attr,
const string & var_path)
1801 if (attr !=
nullptr && var_path !=
"") {
1802 Retrieve_H5_Attr_Value(attr, var_path);
1803 string orig_attr_value(attr->value.begin(), attr->value.end());
1804 return orig_attr_value;
1811bool File::Is_Str_Attr(
Attribute* attr,
const string& varfullpath,
const string &attrname,
const string& strvalue)
1813 bool ret_value =
false;
1814 if (attrname == get_CF_string(attr->newname)) {
1815 Retrieve_H5_Attr_Value(attr, varfullpath);
1816 string attr_value(attr->value.begin(), attr->value.end());
1817 if (attr_value == strvalue) ret_value =
true;
1823bool File::has_latlon_cf_units(
Attribute *attr,
const string &varfullpath,
bool is_lat)
1825 string attr_name =
"units";
1826 if (
true == is_lat) {
1827 string lat_unit_value =
"degrees_north";
1828 return Is_Str_Attr(attr, varfullpath, attr_name, lat_unit_value);
1831 string lon_unit_value =
"degrees_east";
1832 return Is_Str_Attr(attr, varfullpath, attr_name, lon_unit_value);
1837void File::Add_One_Float_Attr(
Attribute* attr,
const string &attrname,
float float_value)
1839 attr->name = attrname;
1840 attr->newname = attr->name;
1841 attr->dtype = H5FLOAT32;
1843 attr->value.resize(
sizeof(
float));
1844 memcpy(&(attr->value[0]), (
void*) (&float_value),
sizeof(
float));
1849void File::Change_Attr_One_Str_to_Others(
Attribute* attr,
const Var*var)
1854 long int num_sli = 0;
1855 if (attr->dtype != H5FSTRING)
1856 throw2(
"Currently we only convert fixed-size string to other datatypes. ", attr->name);
1857 if (attr->count != 1)
1858 throw4(
"The fixed-size string count must be 1 and the current count is ", attr->count,
" for the attribute ",
1861 Retrieve_H5_Attr_Value(attr, var->fullpath);
1863 attr_value.resize(attr->value.size());
1864 copy(attr->value.begin(), attr->value.end(), attr_value.begin());
1866 switch (var->dtype) {
1869 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1870 if (num_sli < 0 || num_sli > UCHAR_MAX)
1871 throw5(
"Attribute type is unsigned char, the current attribute ", attr->name,
" has the value ", num_sli,
1872 ". It is overflowed. ");
1874 unsigned char num_suc = (
unsigned char) num_sli;
1875 attr->dtype = H5UCHAR;
1876 attr->value.resize(
sizeof(
unsigned char));
1877 memcpy(&(attr->value[0]), (
void*) (&num_suc),
sizeof(
unsigned char));
1883 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1884 if (num_sli < SCHAR_MIN || num_sli > SCHAR_MAX)
1885 throw5(
"Attribute type is signed char, the current attribute ", attr->name,
" has the value ", num_sli,
1886 ". It is overflowed. ");
1888 char num_sc = (char) num_sli;
1889 attr->dtype = H5CHAR;
1890 attr->value.resize(
sizeof(
char));
1891 memcpy(&(attr->value[0]), (
void*) (&num_sc),
sizeof(
char));
1897 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1898 if (num_sli < SHRT_MIN || num_sli > SHRT_MAX)
1899 throw5(
"Attribute type is 16-bit integer, the current attribute ", attr->name,
" has the value ", num_sli,
1900 ". It is overflowed. ");
1902 short num_ss = (short) num_sli;
1903 attr->dtype = H5INT16;
1904 attr->value.resize(
sizeof(
short));
1905 memcpy(&(attr->value[0]), (
void*) (&num_ss),
sizeof(
short));
1911 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1912 if (num_sli < 0 || num_sli > USHRT_MAX)
1913 throw5(
"Attribute type is unsigned 16-bit integer, the current attribute ", attr->name,
" has the value ",
1914 num_sli,
". It is overflowed. ");
1916 unsigned short num_uss = (
unsigned short) num_sli;
1917 attr->dtype = H5UINT16;
1918 attr->value.resize(
sizeof(
unsigned short));
1919 memcpy(&(attr->value[0]), (
void*) (&num_uss),
sizeof(
unsigned short));
1924 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1930 attr->dtype = H5INT32;
1931 attr->value.resize(
sizeof(
long int));
1932 memcpy(&(attr->value[0]), (
void*) (&num_sli),
sizeof(
long int));
1937 unsigned long int num_suli = strtoul(&(attr->value[0]), &pEnd, 10);
1939 attr->dtype = H5UINT32;
1940 attr->value.resize(
sizeof(
unsigned long int));
1941 memcpy(&(attr->value[0]), (
void*) (&num_suli),
sizeof(
unsigned long int));
1945 float num_sf = strtof(&(attr->value[0]),
nullptr);
1947 attr->dtype = H5FLOAT32;
1948 attr->value.resize(
sizeof(
float));
1949 memcpy(&(attr->value[0]), (
void*) (&num_sf),
sizeof(
float));
1953 double num_sd = strtod(&(attr->value[0]),
nullptr);
1955 attr->dtype = H5FLOAT64;
1956 attr->value.resize(
sizeof(
double));
1957 memcpy(&(attr->value[0]), (
void*) (&num_sd),
sizeof(
double));
1962 throw4(
"Unsupported HDF5 datatype that the string is converted to for the attribute ", attr->name,
1963 " of the variable ", var->fullpath);
1969void File::Replace_Var_Str_Attr(
Var* var,
const string &attr_name,
const string& strvalue)
1972 bool rep_attr =
true;
1973 bool rem_attr =
false;
1974 for (
auto ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1975 if ((*ira)->name == attr_name) {
1976 if (
true == Is_Str_Attr(*ira, var->fullpath, attr_name, strvalue))
1985 if (
true == rem_attr) {
1986 for (
auto ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1987 if ((*ira)->name == attr_name) {
1989 var->attrs.erase(ira);
1996 if (
true == rep_attr) {
1998 Add_Str_Attr(attr, attr_name, strvalue);
1999 var->attrs.push_back(attr);
2004bool File::Is_geolatlon(
const string & var_name,
bool is_lat)
2007 bool ret_value =
false;
2008 if (
true == is_lat) {
2009 string lat1 =
"lat";
2010 string lat2 =
"latitude";
2011 string lat3 =
"Latitude";
2013 if (var_name.compare(lat1) == 0 || var_name.compare(lat2) == 0 || var_name.compare(lat3) == 0) ret_value =
true;
2017 string lon1 =
"lon";
2018 string lon2 =
"longitude";
2019 string lon3 =
"Longitude";
2020 if (var_name.compare(lon1) == 0 || var_name.compare(lon2) == 0 || var_name.compare(lon3) == 0) ret_value =
true;
2030 if (
false == add_path)
return;
2033 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2035 const string varname = (*irv)->name;
2036 const string attrname =
"origname";
2037 Add_Str_Attr(attr, attrname, varname);
2038 (*irv)->attrs.push_back(attr);
2041 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2045 if((*irv)->zero_storage_size==
false
2046 || HDF5RequestHandler::get_no_zero_size_fullnameattr() ==
false) {
2048 const string varname = (*irv)->fullpath;
2049 const string attrname =
"fullnamepath";
2050 Add_Str_Attr(attr, attrname, varname);
2051 (*irv)->attrs.push_back(attr);
2056 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
2058 if (
false == (*irg)->attrs.empty()) {
2061 const string varname = (*irg)->path;
2062 const string attrname =
"fullnamepath";
2063 Add_Str_Attr(attr, attrname, varname);
2064 (*irg)->attrs.push_back(attr);
2073void File::Replace_Var_Info(
Var *src,
Var *target)
2077 for_each (target->dims.begin (), target->dims.end (),
2079 for_each (target->attrs.begin (), target->attrs.end (),
2083 target->newname = src->newname;
2084 target->name = src->name;
2085 target->fullpath = src->fullpath;
2086 target->rank = src->rank;
2087 target->dtype = src->dtype;
2088 target->unsupported_attr_dtype = src->unsupported_attr_dtype;
2089 target->unsupported_dspace = src->unsupported_dspace;
2091 for (
auto ira = target->attrs.begin();
2092 ira!=target->attrs.end(); ++ira) {
2094 target->attrs.erase(ira);
2098 for (
auto ird = target->dims.begin(); ird != target->dims.end();) {
2100 ird = target->dims.erase(ird);
2105 for (vector<Attribute*>::iterator ira = src->attrs.begin();
2106 ira!=src->attrs.end(); ++ira) {
2108 attr->name = (*ira)->name;
2109 attr->newname = (*ira)->newname;
2110 attr->dtype =(*ira)->dtype;
2111 attr->count =(*ira)->count;
2112 attr->strsize = (*ira)->strsize;
2113 attr->fstrsize = (*ira)->fstrsize;
2114 attr->value =(*ira)->value;
2115 target->attrs.push_back(attr);
2119 for (
auto ird = src->dims.begin(); ird != src->dims.end(); ++ird) {
2121 dim->name = (*ird)->name;
2122 dim->newname = (*ird)->newname;
2123 target->dims.push_back(dim);
2129void File::Replace_Var_Attrs(
Var *src,
Var *target)
2133 for_each (target->dims.begin (), target->dims.end (),
2135 for_each (target->attrs.begin (), target->attrs.end (),
2139 for (
auto ira = target->attrs.begin(); ira != target->attrs.end();) {
2141 ira = target->attrs.erase(ira);
2143 for (
auto ira = src->attrs.begin(); ira != src->attrs.end(); ++ira) {
2145 attr->name = (*ira)->name;
2146 attr->newname = (*ira)->newname;
2147 attr->dtype = (*ira)->dtype;
2148 attr->count = (*ira)->count;
2149 attr->strsize = (*ira)->strsize;
2150 attr->fstrsize = (*ira)->fstrsize;
2151 attr->value = (*ira)->value;
2152 target->attrs.push_back(attr);
2160bool File::is_var_under_group(
const string &varname,
const string &grpname,
const int var_rank,
2161 vector<size_t> & var_size)
2164 bool ret_value =
false;
2165 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2167 if ((*irv)->rank == var_rank) {
2168 if ((*irv)->name == varname) {
2171 string var_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
2174 if (grpname == var_path) {
2176 for (
int i = 0; i < var_rank; i++)
2177 var_size[i] = (*irv)->getDimensions()[i]->size;
2190 bool ret_value =
false;
2191 for (
auto irv = this->
vars.begin();
2192 irv != this->vars.end(); ++irv) {
2193 for (
auto ira = (*irv)->attrs.begin();
2194 ira != (*irv)->attrs.end(); ++ira) {
2195 if((*ira)->name ==
"grid_mapping") {
2200 if(
true == ret_value)
2210 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2212 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
2213 if((*ira)->name ==
"grid_mapping") {
2214 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
2215 attr_value.resize((*ira)->value.size());
2216 copy((*ira)->value.begin(), (*ira)->value.end(), attr_value.begin());
2221 if(attr_value.find(
'/') ==string::npos){
2222 string new_name = Check_Grid_Mapping_VarName(attr_value,(*irv)->fullpath);
2224 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2228 string new_name = Check_Grid_Mapping_FullPath(attr_value);
2231 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2237string File::Check_Grid_Mapping_VarName(
const string & a_value,
const string & var_fpath) {
2239 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var_fpath);
2240 string gmap_new_name;
2241 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2242 if((*irv)->name == a_value){
2243 if(var_path == HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) {
2244 gmap_new_name = (*irv)->newname;
2249 return gmap_new_name;
2253string File::Check_Grid_Mapping_FullPath(
const string & a_value) {
2255 string gmap_new_name;
2256 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2257 if((*irv)->fullpath == a_value){
2258 gmap_new_name = (*irv)->newname;
2263 return gmap_new_name;
2266void File::remove_netCDF_internal_attributes(
bool include_attr) {
2268 if(
true == include_attr) {
2269 for (
auto irv = this->
vars.begin();
2270 irv != this->vars.end(); ++irv) {
2271 bool var_has_dimscale =
false;
2273 for(
auto ira = (*irv)->attrs.begin();
2274 ira != (*irv)->attrs.end();) {
2275 if((*ira)->name ==
"CLASS") {
2276 string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2280 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2282 ira = (*irv)->attrs.erase(ira);
2283 var_has_dimscale =
true;
2296 else if((*ira)->name ==
"NAME") {
2297 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2298 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
2300 ira =(*irv)->attrs.erase(ira);
2303 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
2304 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
2306 ira =(*irv)->attrs.erase(ira);
2315 else if((*ira)->name ==
"_Netcdf4Dimid") {
2317 ira =(*irv)->attrs.erase(ira);
2319 else if((*ira)->name ==
"_Netcdf4Coordinates") {
2321 ira =(*irv)->attrs.erase(ira);
2324 else if((*ira)->name ==
"_nc3_strict") {
2326 ira =(*irv)->attrs.erase(ira);
2334 if(
true == var_has_dimscale) {
2335 for(
auto ira = (*irv)->attrs.begin();
2336 ira != (*irv)->attrs.end();++ira) {
2337 if((*ira)->name ==
"NAME") {
2339 ira =(*irv)->attrs.erase(ira);
2349void File::add_ignored_info_page_header()
2352 " \n This page is for HDF5 CF hyrax data providers or distributors to check if any HDF5 object or attribute information are ignored during the mapping. \n\n";
2356void File::add_ignored_info_obj_header()
2359 ignored_msg +=
" Some HDF5 objects or the object information are ignored when mapping to DAP2 by the HDF5 OPeNDAP";
2360 ignored_msg +=
" handler due to the restrictions of DAP2, CF conventions or CF tools.";
2361 ignored_msg +=
" Please use HDF5 tools(h5dump or HDFView) to check carefully and make sure that these objects";
2363 " are OK to ignore for your service. For questions or requests to find a way to handle the ignored objects, please";
2364 ignored_msg +=
" contact the HDF5 OPeNDAP handler developer or send an email to help@hdfgroup.org.\n";
2366 ignored_msg +=
" \n In general, ignored HDF5 objects include HDF5 soft links, external links and named datatype.\n";
2368 " \n The HDF5 datasets(variables in the CF term) and attributes that have the following datatypes are ignored: \n";
2370 " Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2371 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2374 " \n The HDF5 datasets(variables in the CF term) and attributes associated with the following dimensions are ignored: \n";
2375 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2376 ignored_msg +=
" 2) attributes that have any zero size dimensions(not reported due to extreme rarity and non-trivial coding)\n\n";
2381void File::add_ignored_info_links_header()
2384 if (
false == this->have_ignored) {
2385 add_ignored_info_obj_header();
2386 have_ignored =
true;
2389 string lh_msg =
"******WARNING******\n";
2390 lh_msg +=
"IGNORED soft links or external links are: ";
2391 if (ignored_msg.rfind(lh_msg) == string::npos) ignored_msg += lh_msg +
"\n";
2398File:: add_ignored_info_obj_dtype_header() {
2401 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported datatypes. \n";
2402 ignored_msg +=
" In general, the unsupported datatypes include: \n";
2403 ignored_msg +=
" Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2404 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2409File:: add_ignored_info_obj_dspace_header() {
2412 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported dimensions. \n";
2413 ignored_msg +=
" In general, the unsupported dimensions include: \n";
2414 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2415 ignored_msg +=
" 2) variables that have any zero size dimensions\n";
2421void File::add_ignored_info_links(
const string & link_path)
2423 if (ignored_msg.find(
"Link paths: ") == string::npos)
2424 ignored_msg +=
" Link paths: " + link_path;
2426 ignored_msg +=
" " + link_path;
2430void File::add_ignored_info_namedtypes(
const string& grp_name,
const string& named_dtype_name)
2433 if (
false == this->have_ignored) {
2434 add_ignored_info_obj_header();
2435 have_ignored =
true;
2438 string ignored_HDF5_named_dtype_hdr =
"\n******WARNING******";
2439 ignored_HDF5_named_dtype_hdr +=
"\n IGNORED HDF5 named datatype objects:\n";
2440 string ignored_HDF5_named_dtype_msg =
" Group name: " + grp_name +
" HDF5 named datatype name: " + named_dtype_name.substr(0,named_dtype_name.size()-1)
2442 if (ignored_msg.find(ignored_HDF5_named_dtype_hdr) == string::npos)
2443 ignored_msg += ignored_HDF5_named_dtype_hdr + ignored_HDF5_named_dtype_msg;
2445 ignored_msg += ignored_HDF5_named_dtype_msg;
2451void File::add_ignored_info_attrs(
bool is_grp,
const string & obj_path,
const string & attr_name)
2454 if (
false == this->have_ignored) {
2455 add_ignored_info_obj_header();
2456 have_ignored =
true;
2460 string ignored_warning_str =
"\n******WARNING******";
2461 string ignored_HDF5_grp_hdr = ignored_warning_str +
"\n Ignored attributes under root and groups:\n";
2462 string ignored_HDF5_grp_msg =
" Group path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2463 string ignored_HDF5_var_hdr = ignored_warning_str +
"\n Ignored attributes for variables:\n";
2464 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2467 if (
true == is_grp) {
2468 if (ignored_msg.find(ignored_HDF5_grp_hdr) == string::npos)
2469 ignored_msg += ignored_HDF5_grp_hdr + ignored_HDF5_grp_msg;
2471 ignored_msg += ignored_HDF5_grp_msg;
2474 if (ignored_msg.find(ignored_HDF5_var_hdr) == string::npos)
2475 ignored_msg += ignored_HDF5_var_hdr + ignored_HDF5_var_msg;
2477 ignored_msg += ignored_HDF5_var_msg;
2484void File::add_ignored_info_objs(
bool is_dim_related,
const string & obj_path)
2487 if (
false == this->have_ignored) {
2488 add_ignored_info_obj_header();
2489 have_ignored =
true;
2492 string ignored_warning_str =
"\n******WARNING******";
2493 string ignored_HDF5_dtype_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported datatypes:\n";
2494 string ignored_HDF5_dspace_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported dimensions:\n";
2495 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
"\n";
2497 if (
true == is_dim_related) {
2498 if (ignored_msg.find(ignored_HDF5_dspace_var_hdr) == string::npos)
2499 ignored_msg += ignored_HDF5_dspace_var_hdr + ignored_HDF5_var_msg;
2501 ignored_msg += ignored_HDF5_var_msg;
2505 if (ignored_msg.find(ignored_HDF5_dtype_var_hdr) == string::npos)
2506 ignored_msg += ignored_HDF5_dtype_var_hdr + ignored_HDF5_var_msg;
2508 ignored_msg += ignored_HDF5_var_msg;
2514void File::add_no_ignored_info()
2517 ignored_msg +=
"There are no ignored HDF5 objects or attributes.";
2523bool File::ignored_dimscale_ref_list(
Var *var)
2526 bool ignored_dimscale =
true;
2529 bool has_dimscale =
false;
2530 bool has_reference_list =
false;
2531 for (
auto ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
2532 if ((*ira)->name ==
"REFERENCE_LIST" &&
false == HDF5CFUtil::cf_strict_support_type((*ira)->getType(),_is_dap4))
2533 has_reference_list =
true;
2534 if ((*ira)->name ==
"CLASS") {
2535 Retrieve_H5_Attr_Value(*ira, var->fullpath);
2537 class_value.resize((*ira)->value.size());
2538 copy((*ira)->value.begin(), (*ira)->value.end(), class_value.begin());
2542 if (0 == class_value.compare(0, 15,
"DIMENSION_SCALE")) {
2543 has_dimscale =
true;
2547 if (
true == has_dimscale &&
true == has_reference_list) {
2548 ignored_dimscale =
false;
2554 return ignored_dimscale;
2558bool File::Check_DropLongStr(
const Var *var,
const Attribute * attr)
2561 bool drop_longstr =
false;
2562 if (
nullptr == attr) {
2563 if (H5FSTRING == var->dtype || H5VSTRING == var->dtype) {
2565 drop_longstr = Check_VarDropLongStr(var->fullpath, var->dims, var->dtype);
2568 throw1(
"Check_VarDropLongStr fails ");
2575 if (H5FSTRING == attr->dtype || H5VSTRING == attr->dtype) {
2576 if (attr->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
2577 drop_longstr =
true;
2583 return drop_longstr;
2589bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
const
2593 bool drop_longstr =
false;
2595 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2597 throw2(
"Cannot open the dataset ", varpath);
2599 hid_t dtype_id = -1;
2600 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2602 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2605 size_t ty_size = H5Tget_size(dtype_id);
2609 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2612 if (H5FSTRING == dtype) {
2613 if (ty_size > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2615 else if (H5VSTRING == dtype) {
2617 unsigned long long total_elms = 1;
2618 if (dims.size() != 0) {
2619 for (
unsigned int i = 0; i < dims.size(); i++)
2620 total_elms = total_elms * ((dims[i])->size);
2622 vector<char> strval;
2623 strval.resize(total_elms * ty_size);
2624 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) strval.data());
2628 throw2(
"Cannot read the data of the dataset ", varpath);
2631 vector<string> finstrval;
2632 finstrval.resize(total_elms);
2633 char*temp_bp = strval.data();
2634 char*onestring =
nullptr;
2635 for (
unsigned long long i = 0; i < total_elms; i++) {
2636 onestring = *(
char**) temp_bp;
2637 if (onestring !=
nullptr) {
2638 finstrval[i] = string(onestring);
2639 if(finstrval[i].size()>NC_JAVA_STR_SIZE_LIMIT) {
2640 drop_longstr =
true;
2647 if (
false == strval.empty()) {
2648 herr_t ret_vlen_claim;
2649 hid_t dspace_id = H5Dget_space(dset_id);
2650 if (dspace_id < 0) {
2653 throw2(
"Cannot obtain the dataspace id.", varpath);
2655 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) strval.data());
2656 if (ret_vlen_claim < 0) {
2658 H5Sclose(dspace_id);
2660 throw2(
"Cannot reclaim the vlen space ", varpath);
2662 if (H5Sclose(dspace_id) < 0) {
2665 throw2(
"Cannot close the HDF5 data space.", varpath);
2669 if (H5Tclose(dtype_id) < 0) {
2671 throw2(
"Cannot close the HDF5 data type.", varpath);
2673 if (H5Dclose(dset_id) < 0)
2674 throw2(
"Cannot close the HDF5 data type.", varpath);
2676 return drop_longstr;
2679bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
2683 bool drop_longstr =
false;
2685 unsigned long long total_elms = 1;
2686 if (dims.size() != 0) {
2687 for (
unsigned int i = 0; i < dims.size(); i++)
2688 total_elms = total_elms * ((dims[i])->size);
2691 if (total_elms > NC_JAVA_STR_SIZE_LIMIT)
2692 drop_longstr =
true;
2696 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2698 throw2(
"Cannot open the dataset ", varpath);
2700 hid_t dtype_id = -1;
2701 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2703 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2706 size_t ty_size = H5Tget_size(dtype_id);
2710 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2713 if (H5FSTRING == dtype) {
2714 if ((ty_size * total_elms) > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2716 else if (H5VSTRING == dtype) {
2718 vector<char> strval;
2719 strval.resize(total_elms * ty_size);
2720 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) strval.data());
2724 throw2(
"Cannot read the data of the dataset ", varpath);
2727 vector<string> finstrval;
2728 finstrval.resize(total_elms);
2729 char*temp_bp = strval.data();
2730 char*onestring =
nullptr;
2731 for (
unsigned long long i = 0; i < total_elms; i++) {
2732 onestring = *(
char**) temp_bp;
2733 if (onestring !=
nullptr)
2734 finstrval[i] = string(onestring);
2741 if (
false == strval.empty()) {
2742 herr_t ret_vlen_claim;
2743 hid_t dspace_id = H5Dget_space(dset_id);
2744 if (dspace_id < 0) {
2747 throw2(
"Cannot obtain the dataspace id.", varpath);
2749 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) strval.data());
2750 if (ret_vlen_claim < 0) {
2752 H5Sclose(dspace_id);
2754 throw2(
"Cannot reclaim the vlen space ", varpath);
2756 if (H5Sclose(dspace_id) < 0) {
2759 throw2(
"Cannot close the HDF5 data space.", varpath);
2762 unsigned long long total_str_size = 0;
2763 for (
unsigned long long i = 0; i < total_elms; i++) {
2764 total_str_size += finstrval[i].size();
2765 if (total_str_size > NC_JAVA_STR_SIZE_LIMIT) {
2766 drop_longstr =
true;
2771 if (H5Tclose(dtype_id) < 0) {
2773 throw2(
"Cannot close the HDF5 data type.", varpath);
2775 if (H5Dclose(dset_id) < 0)
2776 throw2(
"Cannot close the HDF5 data type.", varpath);
2778 return drop_longstr;
2784void File::add_ignored_grp_longstr_info(
const string& grp_path,
const string & attr_name)
2787 ignored_msg +=
"The HDF5 group: " + grp_path +
" has an empty-set string attribute: " + attr_name +
"\n";
2793void File::add_ignored_var_longstr_info(
const Var *var,
const Attribute *attr)
2796 if (
nullptr == attr)
2797 ignored_msg +=
"String variable: " + var->fullpath +
" value is set to empty.\n";
2799 ignored_msg +=
"The variable: " + var->fullpath +
" has an empty-set string attribute: " + attr->name +
"\n";
2806void File::add_ignored_droplongstr_hdr()
2809 if (
false == this->have_ignored) this->have_ignored =
true;
2810 string hdr =
"\n\n The values of the following string variables ";
2811 hdr +=
" are set to empty because at least one string size in this variable exceeds netCDF Java string limit(32767 bytes).\n";
2812 hdr +=
"To obtain the values, change the BES key H5.EnableDropLongString=true at the handler BES";
2813 hdr +=
" configuration file(h5.conf)\nto H5.EnableDropLongString=false.\n\n";
2815 if (ignored_msg.rfind(hdr) == string::npos) ignored_msg += hdr;
2820void File::release_standalone_var_vector(vector<Var*>&temp_vars)
2823 for (
auto i = temp_vars.begin(); i != temp_vars.end();) {
2825 i = temp_vars.erase(i);
This class specifies the core engineering of mapping HDF5 to DAP by following CF.
include the entry functions to execute the handlers
This class represents one attribute.
This class repersents one dimension of an HDF5 dataset(variable).
std::vector< Group * > groups
Non-root group vectors.
virtual void Retrieve_H5_Var_Attr_Values(Var *var)
Retrieve attribute values for a variable.
virtual void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for datasets.
std::map< hsize_t, std::string > dimsize_to_fakedimname
Handle added dimension names.
virtual void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
virtual void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes.
virtual void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes.
std::vector< Var * > vars
Var vectors.
virtual void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name.
virtual void Retrieve_H5_Info(const char *path, hid_t file_id, bool)
std::vector< Attribute * > root_attrs
Root attribute vectors.
virtual void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes.
virtual void Flatten_Obj_Name(bool)
Flatten the object name.
virtual bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
This class represents an HDF5 group. The group will be flattened according to the CF conventions.
This class represents one HDF5 dataset(CF variable)
Helper functions for generating DAS attributes and a function to check BES Key.
static H5DataType H5type_to_H5DAPtype(hid_t h5_type_id)
Map HDF5 Datatype to the intermediate H5DAPtype for the future use.
static std::string trim_string(hid_t dtypeid, const std::string &s, int num_sect, size_t section_size, std::vector< size_t > §_newsize)