46 using namespace HDF5CF;
51 newname = var->newname;
53 fullpath = var->fullpath;
55 total_elems = var->total_elems;
57 comp_ratio = var->comp_ratio;
58 unsupported_attr_dtype = var->unsupported_attr_dtype;
59 unsupported_attr_dspace = var->unsupported_attr_dspace;
60 unsupported_dspace = var->unsupported_dspace;
61 unsupported_attr_dspace = var->unsupported_attr_dspace;
62 dimnameflag = var->dimnameflag;
64 for (vector<Attribute*>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
66 attr->name = (*ira)->name;
67 attr->newname = (*ira)->newname;
68 attr->dtype = (*ira)->dtype;
69 attr->count = (*ira)->count;
70 attr->strsize = (*ira)->strsize;
71 attr->fstrsize = (*ira)->fstrsize;
72 attr->value = (*ira)->value;
73 attrs.push_back(attr);
76 for (vector<Dimension*>::iterator ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
78 dim->name = (*ird)->name;
79 dim->newname = (*ird)->newname;
80 dim->unlimited_dim = (*ird)->unlimited_dim;
86 bool CVar::isLatLon()
const
89 bool ret_value =
false;
90 if (CV_EXIST == this->cvartype || CV_MODIFY == this->cvartype || CV_SPECIAL == this->cvartype) {
91 string attr_name =
"units";
92 string lat_unit_value =
"degrees_north";
93 string lon_unit_value =
"degrees_east";
95 for (vector<Attribute *>::const_iterator ira = this->attrs.begin(); ira != this->attrs.end(); ira++) {
97 if ((H5FSTRING == (*ira)->getType()) || (H5VSTRING == (*ira)->getType())) {
98 if (attr_name == (*ira)->newname) {
99 string attr_value1((*ira)->getValue().begin(), (*ira)->getValue().end());
101 if ((*ira)->getCount() == 1) {
102 string attr_value((*ira)->getValue().begin(), (*ira)->getValue().end());
103 if (attr_value.compare(0, lat_unit_value.size(), lat_unit_value) == 0) {
104 if (attr_value.size() == lat_unit_value.size()) {
108 else if (attr_value.size() == (lat_unit_value.size() + 1)) {
109 if (attr_value[attr_value.size() - 1] ==
'\0'
110 || attr_value[attr_value.size() - 1] ==
' ') {
116 else if (attr_value.compare(0, lon_unit_value.size(), lon_unit_value) == 0) {
117 if (attr_value.size() == lon_unit_value.size()) {
121 else if (attr_value.size() == (lon_unit_value.size() + 1)) {
122 if (attr_value[attr_value.size() - 1] ==
'\0'
123 || attr_value[attr_value.size() - 1] ==
' ') {
136 else if (this->cvartype == CV_LAT_MISS || this->cvartype == CV_LON_MISS) ret_value =
true;
143 if (this->fileid >= 0) {
144 if (this->rootid >= 0) {
155 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
160 for_each(this->dims.begin(), this->dims.end(),
delete_elem());
161 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
164 Attribute::~Attribute()
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 = 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;
228 void 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++) {
250 size_t dummy_name_len = 1;
253 oname_size = H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, NULL, 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[0], (
size_t) (oname_size + 1),
264 throw2(
"Error getting the hdf5 object name from the group: ", gname);
268 if (H5Lget_info(grp_id, &oname[0], &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 = 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 var->comp_ratio = Retrieve_H5_VarCompRatio(var, cdset);
377 if (
true == include_attr) {
379 int num_attrs = oinfo.num_attrs;
380 bool temp_unsup_attr_dtype =
false;
381 bool temp_unsup_attr_dspace =
false;
383 for (
int j = 0; j < num_attrs; j++) {
387 Retrieve_H5_Attr_Info(attr, cdset, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
388 var->attrs.push_back(attr);
392 var->unsupported_attr_dtype = temp_unsup_attr_dtype;
393 var->unsupported_attr_dspace = temp_unsup_attr_dspace;
395 if (!this->unsupported_var_attr_dspace && temp_unsup_attr_dspace)
396 this->unsupported_var_attr_dspace =
true;
399 this->
vars.push_back(var);
400 if (H5Dclose(cdset) < 0)
401 throw2(
"Error closing the HDF5 dataset ", full_path_name);
405 case H5O_TYPE_NAMED_DATATYPE: {
407 if (
true == include_attr &&
true == check_ignored) {
408 this->add_ignored_info_namedtypes(
string(gname),
string(oname.begin(), oname.end()));
433 if (cgroup != -1) H5Gclose(cgroup);
435 if (cdset != -1) H5Dclose(cdset);
444 float File::Retrieve_H5_VarCompRatio(
Var *var, hid_t dset_id)
447 float comp_ratio = 1.0;
449 hid_t dset_create_plist = H5Dget_create_plist(dset_id);
450 if (dset_create_plist < 0)
451 throw1(
"unable to obtain hdf5 dataset creation property list ");
452 H5D_layout_t dset_layout = H5Pget_layout(dset_create_plist);
453 if (dset_layout < 0) {
454 H5Pclose(dset_create_plist);
455 throw1(
"unable to obtain hdf5 dataset creation property list storage layout");
458 if (dset_layout == H5D_CHUNKED) {
460 hsize_t dstorage_size = H5Dget_storage_size(dset_id);
461 if (dstorage_size > 0 && var->total_elems > 0) {
465 if ((ty_id = H5Dget_type(dset_id)) < 0)
466 throw1(
"unable to obtain hdf5 datatype for the dataset ");
467 size_t type_size = H5Tget_size(ty_id);
468 comp_ratio = ((float) (var->total_elems) * type_size) / dstorage_size;
473 H5Pclose(dset_create_plist);
478 void File::Retrieve_H5_VarType(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dtype)
484 if ((ty_id = H5Dget_type(dset_id)) < 0)
485 throw2(
"unable to obtain hdf5 datatype for the dataset ", varname);
504 if (
false == HDF5CFUtil::cf_strict_support_type(var->dtype)) unsup_var_dtype =
true;
506 if (H5Tclose(ty_id) < 0)
507 throw1(
"Unable to close the HDF5 datatype ");;
511 void File::Retrieve_H5_VarDim(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dspace)
514 vector<hsize_t> dsize;
515 vector<hsize_t> maxsize;
517 hid_t dspace_id = -1;
521 if ((dspace_id = H5Dget_space(dset_id)) < 0)
522 throw2(
"Cannot get hdf5 dataspace id for the variable ", varname);
524 H5S_class_t space_class = H5S_NO_CLASS;
525 if ((space_class = H5Sget_simple_extent_type(dspace_id)) < 0)
526 throw2(
"Cannot obtain the HDF5 dataspace class for the variable ", varname);
528 if (H5S_NULL == space_class)
529 unsup_var_dspace =
true;
531 if (
false == unsup_var_dspace) {
533 hssize_t h5_total_elms = H5Sget_simple_extent_npoints(dspace_id);
534 if (h5_total_elms < 0)
535 throw2(
"Cannot get the total number of elements of HDF5 dataset ", varname);
537 var->total_elems = (size_t) h5_total_elms;
538 int ndims = H5Sget_simple_extent_ndims(dspace_id);
540 throw2(
"Cannot get the hdf5 dataspace number of dimension for the variable ", varname);
545 maxsize.resize(ndims);
550 if (H5Sget_simple_extent_dims(dspace_id, &dsize[0], &maxsize[0]) < 0)
551 throw2(
"Cannot obtain the dim. info for the variable ", varname);
553 for (
int i = 0; i < ndims; i++) {
555 if (maxsize[i] == H5S_UNLIMITED) {
556 dim->unlimited_dim =
true;
557 if (
false == have_udim) have_udim =
true;
559 var->dims.push_back(dim);
564 var->unsupported_dspace = unsup_var_dspace;
566 if (H5Sclose(dspace_id) < 0)
567 throw1(
"Cannot close the HDF5 dataspace .");
573 if (dspace_id != -1) H5Sclose(dspace_id);
575 if (ty_id != -1) H5Tclose(ty_id);
582 void File::Retrieve_H5_Attr_Info(
Attribute * attr, hid_t obj_id,
const int j,
bool &unsup_attr_dtype,
583 bool &unsup_attr_dspace)
589 hid_t aspace_id = -1;
595 if ((attrid = H5Aopen_by_idx(obj_id,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) j, H5P_DEFAULT,
597 throw1(
"Unable to open attribute by index ");
600 ssize_t name_size = H5Aget_name(attrid, 0, NULL);
602 throw1(
"Unable to obtain the size of the hdf5 attribute name ");
605 attr_name.resize(name_size + 1);
608 if ((H5Aget_name(attrid, name_size + 1, &attr_name[0])) < 0)
609 throw1(
"unable to obtain the hdf5 attribute name ");
612 if ((ty_id = H5Aget_type(attrid)) < 0)
613 throw2(
"unable to obtain hdf5 datatype for the attribute ", attr_name);
631 if (
false == HDF5CFUtil::cf_strict_support_type(attr->dtype)) unsup_attr_dtype =
true;
633 if(H5VSTRING == attr->dtype || H5FSTRING == attr->dtype) {
634 H5T_cset_t c_set_type = H5Tget_cset(ty_id);
636 throw2(
"Cannot get hdf5 character set type for the attribute ", attr_name);
639 attr->is_cset_ascii =
false;
642 if ((aspace_id = H5Aget_space(attrid)) < 0)
643 throw2(
"Cannot get hdf5 dataspace id for the attribute ", attr_name);
645 int ndims = H5Sget_simple_extent_ndims(aspace_id);
647 throw2(
"Cannot get the hdf5 dataspace number of dimension for attribute ", attr_name);
654 vector<hsize_t> asize;
655 vector<hsize_t> maxsize;
657 maxsize.resize(ndims);
660 if (H5Sget_simple_extent_dims(aspace_id, &asize[0], &maxsize[0]) < 0)
661 throw2(
"Cannot obtain the dim. info for the attribute ", attr_name);
664 for (
int dim_count = 0;dim_count < ndims; dim_count ++) {
666 if (asize[dim_count] == 0) {
667 unsup_attr_dspace =
true;
672 if (
false == unsup_attr_dspace) {
674 for (
int dim_count = 0; dim_count< ndims; dim_count++)
675 nelmts *= asize[dim_count];
681 size_t ty_size = H5Tget_size(ty_id);
683 throw2(
"Cannot obtain the dtype size for the attribute ", attr_name);
685 memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
687 throw2(
"Cannot obtain the memory datatype for the attribute ", attr_name);
690 string temp_aname(attr_name.begin(), attr_name.end());
691 attr->name = temp_aname.substr(0, temp_aname.size() - 1);
692 attr->newname = attr->name;
693 attr->count = nelmts;
696 if (H5Tclose(ty_id) < 0)
697 throw1(
"Cannot successfully close the attribute datatype.");
698 if (H5Tclose(memtype) < 0)
699 throw1(
"Cannot successfully close the attribute memory datatype.");
700 if (H5Sclose(aspace_id) < 0)
701 throw1(
"Cannot successfully close the HDF5 dataspace.");
702 if (H5Aclose(attrid) < 0)
703 throw1(
"Cannot successfully close the HDF5 attribute.");
708 if (ty_id != -1) H5Tclose(ty_id);
710 if (memtype != -1) H5Tclose(memtype);
712 if (aspace_id != -1) H5Sclose(aspace_id);
714 if (attrid != -1) H5Aclose(attrid);
725 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira)
726 Retrieve_H5_Attr_Value(*ira,
"/");
728 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
729 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
730 Retrieve_H5_Attr_Value(*ira, (*irg)->path);
734 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
735 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
736 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
743 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
744 Retrieve_H5_Attr_Value(*ira, var->fullpath);
749 void File::Retrieve_H5_Attr_Value(
Attribute *attr,
string obj_name)
756 hid_t memtype_id = -1;
757 hid_t aspace_id = -1;
762 obj_id = H5Oopen(this->fileid, obj_name.c_str(), H5P_DEFAULT);
764 throw2(
"Cannot open the object ", obj_name);
766 attr_id = H5Aopen(obj_id, (attr->name).c_str(), H5P_DEFAULT);
768 throw4(
"Cannot open the attribute ", attr->name,
" of object ", obj_name);
770 ty_id = H5Aget_type(attr_id);
772 throw4(
"Cannot obtain the datatype of the attribute ", attr->name,
" of object ", obj_name);
774 memtype_id = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
776 throw2(
"Cannot obtain the memory datatype for the attribute ", attr->name);
778 size_t ty_size = H5Tget_size(memtype_id);
780 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
782 size_t total_bytes = attr->count * ty_size;
785 if (H5VSTRING == attr->dtype) {
788 vector<char> temp_buf;
789 temp_buf.resize(total_bytes);
791 if (H5Aread(attr_id, memtype_id, &temp_buf[0]) < 0)
792 throw4(
"Cannot obtain the value of the attribute ", attr->name,
" of object ", obj_name);
794 char *temp_bp = NULL;
795 char *ptr_1stvlen_ptr = &temp_buf[0];
796 temp_bp = &temp_buf[0];
797 char* onestring = NULL;
798 string total_vstring =
"";
800 attr->strsize.resize(attr->count);
802 for (
unsigned int temp_i = 0; temp_i < attr->count; temp_i++) {
805 onestring = *(
char **) temp_bp;
806 if (onestring != NULL) {
807 total_vstring += string(onestring);
808 attr->strsize[temp_i] = (string(onestring)).size();
811 attr->strsize[temp_i] = 0;
817 if (ptr_1stvlen_ptr != NULL) {
818 aspace_id = H5Aget_space(attr_id);
820 throw4(
"Cannot obtain space id for ", attr->name,
" of object ", obj_name);
823 if (H5Dvlen_reclaim(memtype_id, aspace_id, H5P_DEFAULT, &temp_buf[0]) < 0)
824 throw4(
"Cannot reclaim VL memory for ", attr->name,
" of object ", obj_name);
830 throw4(
"Error to obtain the VL string type for attribute ", attr->name,
" of object ", obj_name);
832 attr->value.resize(total_vstring.size());
834 copy(total_vstring.begin(), total_vstring.end(), attr->value.begin());
839 if (attr->dtype == H5FSTRING) {
840 attr->fstrsize = ty_size;
843 attr->value.resize(total_bytes);
846 if (H5Aread(attr_id, memtype_id, (
void *) &attr->value[0]) < 0)
847 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
849 if (attr->dtype == H5FSTRING) {
851 size_t sect_size = ty_size;
855 (total_bytes % sect_size == 0) ? (total_bytes / sect_size) : (total_bytes / sect_size + 1);
857 throw4(
"The attribute datatype size is not a positive integer ", attr->name,
" of object ",
860 vector<size_t> sect_newsize;
861 sect_newsize.resize(num_sect);
863 string total_fstring = string(attr->value.begin(), attr->value.end());
867 attr->value.resize(new_total_fstring.size());
868 copy(new_total_fstring.begin(), new_total_fstring.end(), attr->value.begin());
869 attr->strsize.resize(num_sect);
870 for (
int temp_i = 0; temp_i < num_sect; temp_i++)
871 attr->strsize[temp_i] = sect_newsize[temp_i];
875 for (
int temp_i = 0; temp_i <num_sect; temp_i ++)
876 "h5",
"string new section size = " << attr->strsize[temp_i] <<endl;
881 if (H5Tclose(memtype_id) < 0)
882 throw1(
"Fail to close the HDF5 memory datatype ID.");
883 if (H5Tclose(ty_id) < 0)
884 throw1(
"Fail to close the HDF5 datatype ID.");
885 if (H5Aclose(attr_id) < 0)
886 throw1(
"Fail to close the HDF5 attribute ID.");
887 if (H5Oclose(obj_id) < 0)
888 throw1(
"Fail to close the HDF5 object ID.");
894 if (memtype_id != -1) H5Tclose(memtype_id);
896 if (ty_id != -1) H5Tclose(ty_id);
898 if (aspace_id != -1) H5Sclose(aspace_id);
900 if (attr_id != -1) H5Aclose(attr_id);
902 if (obj_id != -1) H5Oclose(obj_id);
913 if (
true == include_attr) {
914 Handle_Group_Unsupported_Dtype();
915 Handle_VarAttr_Unsupported_Dtype();
918 Handle_Var_Unsupported_Dtype();
924 if (
true == include_attr) {
925 if (
true == this->unsupported_attr_dtype) {
926 for (vector<Attribute *>::iterator ira = this->root_attrs.begin();
927 ira != this->root_attrs.end(); ) {
928 H5DataType temp_dtype = (*ira)->getType();
929 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
931 ira = this->root_attrs.erase(ira);
942 if (
false == this->groups.empty()) {
943 for (vector<Group *>::iterator irg = this->groups.begin();
944 irg != this->groups.end(); ++irg) {
945 if (
false == (*irg)->attrs.empty()) {
946 if (
true == (*irg)->unsupported_attr_dtype) {
947 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin();
948 ira != (*irg)->attrs.end(); ) {
949 H5DataType temp_dtype = (*ira)->getType();
950 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
952 ira = (*irg)->attrs.erase(ira);
965 if (
false == this->vars.empty()) {
966 if (
true == include_attr) {
967 for (vector<Var *>::iterator irv = this->vars.begin();
968 irv != this->vars.end();++irv ) {
969 if (
false == (*irv)->attrs.empty()) {
970 if (
true == (*irv)->unsupported_attr_dtype) {
971 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
972 ira != (*irv)->attrs.end(); ) {
973 H5DataType temp_dtype = (*ira)->getType();
974 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
976 ira = (*irv)->attrs.erase(ira);
987 if (
true == this->unsupported_var_dtype) {
989 for (vector<Var *>::iterator irv = this->vars.begin();
990 irv != this->vars.end(); ) {
991 H5DataType temp_dtype = (*irv)->getType();
992 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
994 irv = this->vars.erase(irv);
1004 void File::Handle_Group_Unsupported_Dtype()
1009 if (
true == this->unsupported_attr_dtype) {
1010 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1011 H5DataType temp_dtype = (*ira)->getType();
1012 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1024 if (
false == this->
groups.empty()) {
1025 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1026 if (
false == (*irg)->attrs.empty()) {
1027 if (
true == (*irg)->unsupported_attr_dtype) {
1028 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1029 H5DataType temp_dtype = (*ira)->getType();
1030 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1032 ira = (*irg)->attrs.erase(ira);
1045 void File::Gen_Group_Unsupported_Dtype_Info()
1051 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1052 H5DataType temp_dtype = (*ira)->getType();
1053 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
1054 this->add_ignored_info_attrs(
true,
"/", (*ira)->name);
1061 if (
false == this->
groups.empty()) {
1062 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1063 if (
false == (*irg)->attrs.empty()) {
1065 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1066 H5DataType temp_dtype = (*ira)->getType();
1067 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype==H5UINT64 ) {
1068 this->add_ignored_info_attrs(
true, (*irg)->path, (*ira)->name);
1078 void File::Handle_Var_Unsupported_Dtype()
1080 if (
false == this->
vars.empty()) {
1081 if (
true == this->unsupported_var_dtype) {
1082 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end();) {
1083 H5DataType temp_dtype = (*irv)->getType();
1084 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1086 irv = this->
vars.erase(irv);
1098 void File::Gen_Var_Unsupported_Dtype_Info()
1101 if (
false == this->
vars.empty()) {
1103 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1104 H5DataType temp_dtype = (*irv)->getType();
1105 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)||(H5INT64 == temp_dtype) ||(H5UINT64 == temp_dtype)) {
1106 this->add_ignored_info_objs(
false, (*irv)->fullpath);
1115 void File::Handle_VarAttr_Unsupported_Dtype()
1117 if (
false == this->
vars.empty()) {
1118 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1119 if (
false == (*irv)->attrs.empty()) {
1120 if (
true == (*irv)->unsupported_attr_dtype) {
1121 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1122 H5DataType temp_dtype = (*ira)->getType();
1123 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1125 ira = (*irv)->attrs.erase(ira);
1138 void File::Gen_VarAttr_Unsupported_Dtype_Info()
1141 if (
false == this->
vars.empty()) {
1142 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1143 if (
false == (*irv)->attrs.empty()) {
1145 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1146 H5DataType temp_dtype = (*ira)->getType();
1147 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || (temp_dtype==H5INT64) || (temp_dtype == H5UINT64)) {
1148 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1161 void File::Gen_DimScale_VarAttr_Unsupported_Dtype_Info()
1164 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1168 bool is_ignored = ignored_dimscale_ref_list((*irv));
1169 if (
false == (*irv)->attrs.empty()) {
1171 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1172 H5DataType temp_dtype = (*ira)->getType();
1173 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || (temp_dtype == H5INT64) || (temp_dtype == H5UINT64)) {
1177 if ((
"DIMENSION_LIST" != (*ira)->name)
1178 && (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
1179 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1188 void File::Handle_GroupAttr_Unsupported_Dspace()
1193 if (
true == this->unsupported_attr_dspace) {
1194 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1196 if ((*ira)->count == 0) {
1208 if (
false == this->
groups.empty()) {
1209 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1210 if (
false == (*irg)->attrs.empty()) {
1211 if (
true == (*irg)->unsupported_attr_dspace) {
1212 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1213 if ((*ira)->count == 0) {
1215 ira = (*irg)->attrs.erase(ira);
1228 void File::Handle_VarAttr_Unsupported_Dspace()
1231 if (
false == this->
vars.empty()) {
1232 if (
true == this->unsupported_var_attr_dspace) {
1233 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1234 if (
false == (*irv)->attrs.empty()) {
1235 if (
true == (*irv)->unsupported_attr_dspace) {
1236 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1237 if (0 == (*ira)->count) {
1239 ira = (*irv)->attrs.erase(ira);
1257 if (
false == this->
vars.empty()) {
1258 if (
true == this->unsupported_var_dspace) {
1259 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end();) {
1260 if (
true == (*irv)->unsupported_dspace) {
1262 irv = this->
vars.erase(irv);
1272 if (
true == include_attr) {
1273 Handle_GroupAttr_Unsupported_Dspace();
1274 Handle_VarAttr_Unsupported_Dspace();
1279 void File::Gen_Unsupported_Dspace_Info()
1287 if (
false == this->
vars.empty()) {
1288 if (
true == this->unsupported_var_dspace) {
1289 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1290 if (
true == (*irv)->unsupported_dspace) {
1291 this->add_ignored_info_objs(
true, (*irv)->fullpath);
1303 if (
true == this->check_ignored &&
true == include_attr) {
1305 if (
true == HDF5RequestHandler::get_drop_long_string()) {
1309 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1310 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1311 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1312 this->add_ignored_droplongstr_hdr();
1313 this->add_ignored_grp_longstr_info(
"/", (*ira)->name);
1318 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1319 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1320 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1321 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1322 this->add_ignored_droplongstr_hdr();
1323 this->add_ignored_grp_longstr_info((*irg)->path, (*ira)->name);
1329 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1330 if (
true == Check_DropLongStr((*irv), NULL)) {
1331 this->add_ignored_droplongstr_hdr();
1332 this->add_ignored_var_longstr_info((*irv), NULL);
1336 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1337 if (
true == Check_DropLongStr((*irv), (*ira))) {
1338 this->add_ignored_droplongstr_hdr();
1339 this->add_ignored_var_longstr_info((*irv), (*ira));
1353 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1354 (*irv)->newname = get_CF_string((*irv)->newname);
1356 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1357 (*ird)->newname = get_CF_string((*ird)->newname);
1361 if (
true == include_attr) {
1363 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1364 (*ira)->newname = get_CF_string((*ira)->newname);
1367 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1368 (*irg)->newname = get_CF_string((*irg)->newname);
1369 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1370 (*ira)->newname = get_CF_string((*ira)->newname);
1374 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1375 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1376 (*ira)->newname = get_CF_string((*ira)->newname);
1383 void File::Handle_Var_NameClashing(set<string>&objnameset)
1386 Handle_General_NameClashing(objnameset, this->
vars);
1390 void File::Handle_Group_NameClashing(set<string> &objnameset)
1393 pair<set<string>::iterator,
bool> setret;
1403 setret = objnameset.insert(FILE_ATTR_TABLE_NAME);
1404 if (
false == setret.second) {
1406 int clash_index = 1;
1407 string fa_clash_name = FILE_ATTR_TABLE_NAME;
1408 HDF5CFUtil::gen_unique_name(fa_clash_name, objnameset, clash_index);
1409 FILE_ATTR_TABLE_NAME = fa_clash_name;
1413 Handle_General_NameClashing(objnameset, this->
groups);
1418 void File::Handle_Obj_AttrNameClashing()
1429 set<string> objnameset;
1432 Handle_General_NameClashing(objnameset, this->
root_attrs);
1435 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1437 Handle_General_NameClashing(objnameset, (*irg)->attrs);
1441 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1443 Handle_General_NameClashing(objnameset, (*irv)->attrs);
1449 template<
class T>
void File::Handle_General_NameClashing(set<string>&objnameset, vector<T*>& objvec)
1453 pair<set<string>::iterator,
bool> setret;
1454 set<string>::iterator iss;
1456 vector<string> clashnamelist;
1457 vector<string>::iterator ivs;
1459 map<int, int> cl_to_ol;
1464 typename vector<T*>::iterator irv;
1466 for (irv = objvec.begin(); irv != objvec.end(); ++irv) {
1467 setret = objnameset.insert((*irv)->newname);
1468 if (
false == setret.second) {
1469 clashnamelist.insert(clashnamelist.end(), (*irv)->newname);
1470 cl_to_ol[cl_index] = ol_index;
1478 for (ivs = clashnamelist.begin(); ivs != clashnamelist.end(); ivs++) {
1479 int clash_index = 1;
1480 string temp_clashname = *ivs +
'_';
1481 HDF5CFUtil::gen_unique_name(temp_clashname, objnameset, clash_index);
1482 *ivs = temp_clashname;
1486 for (
unsigned int i = 0; i < clashnamelist.size(); i++)
1487 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
1492 void File::Handle_GeneralObj_NameClashing(
bool include_attr, set<string>& objnameset)
1495 Handle_Var_NameClashing(objnameset);
1496 if (
true == include_attr) {
1497 Handle_Group_NameClashing(objnameset);
1498 Handle_Obj_AttrNameClashing();
1503 string File::get_CF_string(
string s)
1506 if (
"" == s)
return s;
1507 string insertString(1,
'_');
1510 if (
true == isdigit(s[0])) s.insert(0, insertString);
1512 for (
unsigned int i = 0; i < s.length(); i++)
1513 if ((
false == isalnum(s[i])) && (s[i] !=
'_')) s[i] =
'_';
1520 void File::Insert_One_NameSizeMap_Element(
string name, hsize_t size,
bool unlimited)
1522 pair<map<string, hsize_t>::iterator,
bool> mapret;
1523 mapret = dimname_to_dimsize.insert(pair<string, hsize_t>(name, size));
1524 if (
false == mapret.second)
1525 throw4(
"The dimension name ", name,
" should map to ", size);
1527 pair<map<string, bool>::iterator,
bool> mapret2;
1528 mapret2 = dimname_to_unlimited.insert(pair<string, bool>(name, unlimited));
1529 if (
false == mapret2.second)
1530 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1535 void File::Insert_One_NameSizeMap_Element2(map<string, hsize_t>& name_to_size, map<string, bool>& name_to_unlimited,
1536 string name, hsize_t size,
bool unlimited)
1538 pair<map<string, hsize_t>::iterator,
bool> mapret;
1539 mapret = name_to_size.insert(pair<string, hsize_t>(name, size));
1540 if (
false == mapret.second)
1541 throw4(
"The dimension name ", name,
" should map to ", size);
1543 pair<map<string, bool>::iterator,
bool> mapret2;
1544 mapret2 = name_to_unlimited.insert(pair<string, bool>(name, unlimited));
1545 if (
false == mapret2.second)
1546 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1563 void File::Add_One_FakeDim_Name(
Dimension *dim)
1566 stringstream sfakedimindex;
1567 string fakedimstr =
"FakeDim";
1568 pair<set<string>::iterator,
bool> setret;
1569 map<hsize_t, string>::iterator im;
1570 pair<map<hsize_t, string>::iterator,
bool> mapret;
1572 sfakedimindex << addeddimindex;
1573 string added_dimname = fakedimstr + sfakedimindex.str();
1577 if (
false == mapret.second) {
1579 dim->newname = dim->name;
1586 setret = dimnamelist.insert(added_dimname);
1587 if (
false == setret.second) {
1588 int clash_index = 1;
1589 string temp_clashname = added_dimname +
'_';
1590 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1591 dim->name = temp_clashname;
1592 dim->newname = dim->name;
1593 setret = dimnamelist.insert(dim->name);
1594 if (
false == setret.second)
1595 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1601 if (
false == mapret.second)
1602 throw4(
"The dimension size ", dim->size,
" should map to ", dim->name);
1606 dim->name = added_dimname;
1607 dim->newname = dim->name;
1608 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1616 void File::Adjust_Duplicate_FakeDim_Name(
Dimension * dim)
1624 stringstream sfakedimindex;
1625 pair<set<string>::iterator,
bool> setret;
1628 sfakedimindex << addeddimindex;
1629 string added_dimname =
"FakeDim" + sfakedimindex.str();
1630 setret = dimnamelist.insert(added_dimname);
1631 if (
false == setret.second) {
1632 int clash_index = 1;
1633 string temp_clashname = added_dimname +
'_';
1634 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1635 dim->name = temp_clashname;
1636 dim->newname = dim->name;
1637 setret = dimnamelist.insert(dim->name);
1638 if (
false == setret.second)
1639 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1641 dim->name = added_dimname;
1642 dim->newname = dim->name;
1643 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1651 void File::Replace_Dim_Name_All(
const string orig_dim_name,
const string new_dim_name) {
1654 for (vector<Var *>::iterator irv = this->
vars.begin();
1655 irv != this->vars.end(); ++irv) {
1656 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1657 ird != (*irv)->dims.end(); ++ird) {
1658 if((*ird)->name == orig_dim_name) {
1659 (*ird)->name = new_dim_name;
1660 (*ird)->newname = new_dim_name;
1669 void File::Use_Dim_Name_With_Size_All(
const string dim_name,
const size_t dim_size) {
1672 for (vector<Var *>::iterator irv = this->
vars.begin();
1673 irv != this->vars.end(); ++irv) {
1674 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1675 ird != (*irv)->dims.end(); ++ird) {
1676 if((*ird)->size == orig_dim_name) {
1677 (*ird)->name = new_dim_name;
1678 (*ird)->newname = new_dim_name;
1688 void File::Add_Str_Attr(
Attribute* attr,
const string &attrname,
const string& strvalue)
1691 attr->name = attrname;
1692 attr->newname = attr->name;
1693 attr->dtype = H5FSTRING;
1695 attr->fstrsize = strvalue.size();
1696 attr->strsize.resize(1);
1697 attr->strsize[0] = attr->fstrsize;
1698 attr->value.resize(strvalue.size());
1699 copy(strvalue.begin(), strvalue.end(), attr->value.begin());
1704 File:: Var_Has_Attr(
Var*var,
const string &attrname) {
1706 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end(); ++ira) {
1710 if((*ira)->name == attrname || (*ira)->newname == attrname) {
1719 string File::Retrieve_Str_Attr_Value(
Attribute *attr,
const string var_path)
1722 if (attr != NULL && var_path !=
"") {
1723 Retrieve_H5_Attr_Value(attr, var_path);
1724 string orig_attr_value(attr->value.begin(), attr->value.end());
1725 return orig_attr_value;
1732 bool File::Is_Str_Attr(
Attribute* attr,
string varfullpath,
const string &attrname,
const string& strvalue)
1734 bool ret_value =
false;
1735 if (attrname == get_CF_string(attr->newname)) {
1736 Retrieve_H5_Attr_Value(attr, varfullpath);
1737 string attr_value(attr->value.begin(), attr->value.end());
1738 if (attr_value == strvalue) ret_value =
true;
1744 bool File::has_latlon_cf_units(
Attribute *attr,
const string &varfullpath,
bool is_lat)
1746 string attr_name =
"units";
1747 if (
true == is_lat) {
1748 string lat_unit_value =
"degrees_north";
1749 return Is_Str_Attr(attr, varfullpath, attr_name, lat_unit_value);
1752 string lon_unit_value =
"degrees_east";
1753 return Is_Str_Attr(attr, varfullpath, attr_name, lon_unit_value);
1758 void File::Add_One_Float_Attr(
Attribute* attr,
const string &attrname,
float float_value)
1760 attr->name = attrname;
1761 attr->newname = attr->name;
1762 attr->dtype = H5FLOAT32;
1764 attr->value.resize(
sizeof(
float));
1765 memcpy(&(attr->value[0]), (
void*) (&float_value),
sizeof(
float));
1770 void File::Change_Attr_One_Str_to_Others(
Attribute* attr,
Var*var)
1775 long int num_sli = 0;
1776 if (attr->dtype != H5FSTRING)
1777 throw2(
"Currently we only convert fixed-size string to other datatypes. ", attr->name);
1778 if (attr->count != 1)
1779 throw4(
"The fixed-size string count must be 1 and the current count is ", attr->count,
" for the attribute ",
1782 Retrieve_H5_Attr_Value(attr, var->fullpath);
1784 attr_value.resize(attr->value.size());
1785 copy(attr->value.begin(), attr->value.end(), attr_value.begin());
1787 switch (var->dtype) {
1790 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1791 if (num_sli < 0 || num_sli > UCHAR_MAX)
1792 throw5(
"Attribute type is unsigned char, the current attribute ", attr->name,
" has the value ", num_sli,
1793 ". It is overflowed. ");
1795 unsigned char num_suc = (
unsigned char) num_sli;
1796 attr->dtype = H5UCHAR;
1797 attr->value.resize(
sizeof(
unsigned char));
1798 memcpy(&(attr->value[0]), (
void*) (&num_suc),
sizeof(
unsigned char));
1804 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1805 if (num_sli < SCHAR_MIN || num_sli > SCHAR_MAX)
1806 throw5(
"Attribute type is signed char, the current attribute ", attr->name,
" has the value ", num_sli,
1807 ". It is overflowed. ");
1809 char num_sc = (char) num_sli;
1810 attr->dtype = H5CHAR;
1811 attr->value.resize(
sizeof(
char));
1812 memcpy(&(attr->value[0]), (
void*) (&num_sc),
sizeof(
char));
1818 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1819 if (num_sli < SHRT_MIN || num_sli > SHRT_MAX)
1820 throw5(
"Attribute type is 16-bit integer, the current attribute ", attr->name,
" has the value ", num_sli,
1821 ". It is overflowed. ");
1823 short num_ss = (short) num_sli;
1824 attr->dtype = H5INT16;
1825 attr->value.resize(
sizeof(
short));
1826 memcpy(&(attr->value[0]), (
void*) (&num_ss),
sizeof(
short));
1832 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1833 if (num_sli < 0 || num_sli > USHRT_MAX)
1834 throw5(
"Attribute type is unsigned 16-bit integer, the current attribute ", attr->name,
" has the value ",
1835 num_sli,
". It is overflowed. ");
1837 unsigned short num_uss = (
unsigned short) num_sli;
1838 attr->dtype = H5UINT16;
1839 attr->value.resize(
sizeof(
unsigned short));
1840 memcpy(&(attr->value[0]), (
void*) (&num_uss),
sizeof(
unsigned short));
1845 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1851 attr->dtype = H5INT32;
1852 attr->value.resize(
sizeof(
long int));
1853 memcpy(&(attr->value[0]), (
void*) (&num_sli),
sizeof(
long int));
1858 unsigned long int num_suli = strtoul(&(attr->value[0]), &pEnd, 10);
1860 attr->dtype = H5UINT32;
1861 attr->value.resize(
sizeof(
unsigned long int));
1862 memcpy(&(attr->value[0]), (
void*) (&num_suli),
sizeof(
unsigned long int));
1866 float num_sf = strtof(&(attr->value[0]), NULL);
1868 attr->dtype = H5FLOAT32;
1869 attr->value.resize(
sizeof(
float));
1870 memcpy(&(attr->value[0]), (
void*) (&num_sf),
sizeof(
float));
1874 double num_sd = strtod(&(attr->value[0]), NULL);
1876 attr->dtype = H5FLOAT64;
1877 attr->value.resize(
sizeof(
double));
1878 memcpy(&(attr->value[0]), (
void*) (&num_sd),
sizeof(
double));
1883 throw4(
"Unsupported HDF5 datatype that the string is converted to for the attribute ", attr->name,
1884 " of the variable ", var->fullpath);
1890 void File::Replace_Var_Str_Attr(
Var* var,
const string &attr_name,
const string& strvalue)
1893 bool rep_attr =
true;
1894 bool rem_attr =
false;
1895 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1896 if ((*ira)->name == attr_name) {
1897 if (
true == Is_Str_Attr(*ira, var->fullpath, attr_name, strvalue))
1906 if (
true == rem_attr) {
1907 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1908 if ((*ira)->name == attr_name) {
1910 var->attrs.erase(ira);
1917 if (
true == rep_attr) {
1919 Add_Str_Attr(attr, attr_name, strvalue);
1920 var->attrs.push_back(attr);
1925 bool File::Is_geolatlon(
const string & var_name,
bool is_lat)
1928 bool ret_value =
false;
1929 if (
true == is_lat) {
1930 string lat1 =
"lat";
1931 string lat2 =
"latitude";
1932 string lat3 =
"Latitude";
1934 if (var_name.compare(lat1) == 0 || var_name.compare(lat2) == 0 || var_name.compare(lat3) == 0) ret_value =
true;
1938 string lon1 =
"lon";
1939 string lon2 =
"longitude";
1940 string lon3 =
"Longitude";
1941 if (var_name.compare(lon1) == 0 || var_name.compare(lon2) == 0 || var_name.compare(lon3) == 0) ret_value =
true;
1951 if (
false == add_path)
return;
1954 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1956 const string varname = (*irv)->name;
1957 const string attrname =
"origname";
1958 Add_Str_Attr(attr, attrname, varname);
1959 (*irv)->attrs.push_back(attr);
1962 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1964 const string varname = (*irv)->fullpath;
1965 const string attrname =
"fullnamepath";
1966 Add_Str_Attr(attr, attrname, varname);
1967 (*irv)->attrs.push_back(attr);
1971 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1973 if (
false == (*irg)->attrs.empty()) {
1976 const string varname = (*irg)->path;
1977 const string attrname =
"fullnamepath";
1978 Add_Str_Attr(attr, attrname, varname);
1979 (*irg)->attrs.push_back(attr);
1988 void File::Replace_Var_Info(
Var *src,
Var *target)
1992 for_each (target->dims.begin (), target->dims.end (),
1994 for_each (target->attrs.begin (), target->attrs.end (),
1998 target->newname = src->newname;
1999 target->name = src->name;
2000 target->fullpath = src->fullpath;
2001 target->rank = src->rank;
2002 target->dtype = src->dtype;
2003 target->unsupported_attr_dtype = src->unsupported_attr_dtype;
2004 target->unsupported_dspace = src->unsupported_dspace;
2006 for (vector<Attribute*>::iterator ira = target->attrs.begin();
2007 ira!=target->attrs.end(); ++ira) {
2009 target->attrs.erase(ira);
2013 for (vector<Dimension*>::iterator ird = target->dims.begin(); ird != target->dims.end();) {
2015 ird = target->dims.erase(ird);
2020 for (vector<Attribute*>::iterator ira = src->attrs.begin();
2021 ira!=src->attrs.end(); ++ira) {
2023 attr->name = (*ira)->name;
2024 attr->newname = (*ira)->newname;
2025 attr->dtype =(*ira)->dtype;
2026 attr->count =(*ira)->count;
2027 attr->strsize = (*ira)->strsize;
2028 attr->fstrsize = (*ira)->fstrsize;
2029 attr->value =(*ira)->value;
2030 target->attrs.push_back(attr);
2034 for (vector<Dimension*>::iterator ird = src->dims.begin(); ird != src->dims.end(); ++ird) {
2036 dim->name = (*ird)->name;
2037 dim->newname = (*ird)->newname;
2038 target->dims.push_back(dim);
2044 void File::Replace_Var_Attrs(
Var *src,
Var *target)
2048 for_each (target->dims.begin (), target->dims.end (),
2050 for_each (target->attrs.begin (), target->attrs.end (),
2054 for (vector<Attribute*>::iterator ira = target->attrs.begin(); ira != target->attrs.end();) {
2056 ira = target->attrs.erase(ira);
2058 for (vector<Attribute*>::iterator ira = src->attrs.begin(); ira != src->attrs.end(); ++ira) {
2060 attr->name = (*ira)->name;
2061 attr->newname = (*ira)->newname;
2062 attr->dtype = (*ira)->dtype;
2063 attr->count = (*ira)->count;
2064 attr->strsize = (*ira)->strsize;
2065 attr->fstrsize = (*ira)->fstrsize;
2066 attr->value = (*ira)->value;
2067 target->attrs.push_back(attr);
2075 bool File::is_var_under_group(
const string &varname,
const string &grpname,
const int var_rank,
2076 vector<size_t> & var_size)
2079 bool ret_value =
false;
2080 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2082 if ((*irv)->rank == var_rank) {
2083 if ((*irv)->name == varname) {
2086 string var_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
2089 if (grpname == var_path) {
2091 for (
int i = 0; i < var_rank; i++)
2092 var_size[i] = (*irv)->getDimensions()[i]->size;
2105 bool ret_value =
false;
2106 for (vector<Var *>::iterator irv = this->
vars.begin();
2107 irv != this->vars.end(); ++irv) {
2108 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2109 ira != (*irv)->attrs.end(); ++ira) {
2110 if((*ira)->name ==
"grid_mapping") {
2115 if(
true == ret_value)
2125 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2127 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
2128 if((*ira)->name ==
"grid_mapping") {
2129 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
2130 attr_value.resize((*ira)->value.size());
2131 copy((*ira)->value.begin(), (*ira)->value.end(), attr_value.begin());
2136 if(attr_value.find(
'/') ==string::npos){
2137 string new_name = Check_Grid_Mapping_VarName(attr_value,(*irv)->fullpath);
2139 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2143 string new_name = Check_Grid_Mapping_FullPath(attr_value);
2146 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2152 string File::Check_Grid_Mapping_VarName(
const string & a_value,
const string & var_fpath) {
2154 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var_fpath);
2155 string gmap_new_name;
2156 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2157 if((*irv)->name == a_value){
2158 if(var_path == HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) {
2159 gmap_new_name = (*irv)->newname;
2164 return gmap_new_name;
2168 string File::Check_Grid_Mapping_FullPath(
const string & a_value) {
2170 string gmap_new_name;
2171 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2172 if((*irv)->fullpath == a_value){
2173 gmap_new_name = (*irv)->newname;
2178 return gmap_new_name;
2181 void File::remove_netCDF_internal_attributes(
bool include_attr) {
2183 if(
true == include_attr) {
2184 for (vector<Var *>::iterator irv = this->
vars.begin();
2185 irv != this->vars.end(); ++irv) {
2186 bool var_has_dimscale =
false;
2188 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2189 ira != (*irv)->attrs.end();) {
2190 if((*ira)->name ==
"CLASS") {
2191 string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2195 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2197 ira = (*irv)->attrs.erase(ira);
2198 var_has_dimscale =
true;
2211 else if((*ira)->name ==
"NAME") {
2212 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2213 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
2215 ira =(*irv)->attrs.erase(ira);
2218 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
2219 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
2221 ira =(*irv)->attrs.erase(ira);
2230 else if((*ira)->name ==
"_Netcdf4Dimid") {
2232 ira =(*irv)->attrs.erase(ira);
2235 else if((*ira)->name ==
"_nc3_strict") {
2237 ira =(*irv)->attrs.erase(ira);
2245 if(
true == var_has_dimscale) {
2246 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2247 ira != (*irv)->attrs.end();++ira) {
2248 if((*ira)->name ==
"NAME") {
2250 ira =(*irv)->attrs.erase(ira);
2260 void File::add_ignored_info_page_header()
2263 " \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";
2267 void File::add_ignored_info_obj_header()
2270 ignored_msg +=
" Some HDF5 objects or the object information are ignored when mapping to DAP2 by the HDF5 OPeNDAP";
2271 ignored_msg +=
" handler due to the restrictions of DAP2, CF conventions or CF tools.";
2272 ignored_msg +=
" Please use HDF5 tools(h5dump or HDFView) to check carefully and make sure that these objects";
2274 " are OK to ignore for your service. For questions or requests to find a way to handle the ignored objects, please";
2275 ignored_msg +=
" contact the HDF5 OPeNDAP handler developer or send an email to help@hdfgroup.org.\n";
2277 ignored_msg +=
" \n In general, ignored HDF5 objects include HDF5 soft links, external links and named datatype.\n";
2279 " \n The HDF5 datasets(variables in the CF term) and attributes that have the following datatypes are ignored: \n";
2281 " Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2282 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2285 " \n The HDF5 datasets(variables in the CF term) and attributes associated with the following dimensions are ignored: \n";
2286 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2287 ignored_msg +=
" 2) attributes that have any zero size dimensions(not reported due to extreme rarity and non-trivial coding)\n\n";
2292 void File::add_ignored_info_links_header()
2295 if (
false == this->have_ignored) {
2296 add_ignored_info_obj_header();
2297 have_ignored =
true;
2300 string lh_msg =
"******WARNING******\n";
2301 lh_msg +=
"IGNORED soft links or external links are: ";
2302 if (ignored_msg.rfind(lh_msg) == string::npos) ignored_msg += lh_msg +
"\n";
2309 File:: add_ignored_info_obj_dtype_header() {
2312 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported datatypes. \n";
2313 ignored_msg +=
" In general, the unsupported datatypes include: \n";
2314 ignored_msg +=
" Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2315 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2320 File:: add_ignored_info_obj_dspace_header() {
2323 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported dimensions. \n";
2324 ignored_msg +=
" In general, the unsupported dimensions include: \n";
2325 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2326 ignored_msg +=
" 2) variables that have any zero size dimensions\n";
2332 void File::add_ignored_info_links(
const string & link_path)
2334 if (ignored_msg.find(
"Link paths: ") == string::npos)
2335 ignored_msg +=
" Link paths: " + link_path;
2337 ignored_msg +=
" " + link_path;
2341 void File::add_ignored_info_namedtypes(
const string& grp_name,
const string& named_dtype_name)
2344 if (
false == this->have_ignored) {
2345 add_ignored_info_obj_header();
2346 have_ignored =
true;
2349 string ignored_HDF5_named_dtype_hdr =
"\n******WARNING******";
2350 ignored_HDF5_named_dtype_hdr +=
"\n IGNORED HDF5 named datatype objects:\n";
2351 string ignored_HDF5_named_dtype_msg =
" Group name: " + grp_name +
" HDF5 named datatype name: " + named_dtype_name.substr(0,named_dtype_name.size()-1)
2353 if (ignored_msg.find(ignored_HDF5_named_dtype_hdr) == string::npos)
2354 ignored_msg += ignored_HDF5_named_dtype_hdr + ignored_HDF5_named_dtype_msg;
2356 ignored_msg += ignored_HDF5_named_dtype_msg;
2362 void File::add_ignored_info_attrs(
bool is_grp,
const string & obj_path,
const string & attr_name)
2365 if (
false == this->have_ignored) {
2366 add_ignored_info_obj_header();
2367 have_ignored =
true;
2371 string ignored_warning_str =
"\n******WARNING******";
2372 string ignored_HDF5_grp_hdr = ignored_warning_str +
"\n Ignored attributes under root and groups:\n";
2373 string ignored_HDF5_grp_msg =
" Group path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2374 string ignored_HDF5_var_hdr = ignored_warning_str +
"\n Ignored attributes for variables:\n";
2375 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2378 if (
true == is_grp) {
2379 if (ignored_msg.find(ignored_HDF5_grp_hdr) == string::npos)
2380 ignored_msg += ignored_HDF5_grp_hdr + ignored_HDF5_grp_msg;
2382 ignored_msg += ignored_HDF5_grp_msg;
2385 if (ignored_msg.find(ignored_HDF5_var_hdr) == string::npos)
2386 ignored_msg += ignored_HDF5_var_hdr + ignored_HDF5_var_msg;
2388 ignored_msg += ignored_HDF5_var_msg;
2395 void File::add_ignored_info_objs(
bool is_dim_related,
const string & obj_path)
2398 if (
false == this->have_ignored) {
2399 add_ignored_info_obj_header();
2400 have_ignored =
true;
2403 string ignored_warning_str =
"\n******WARNING******";
2404 string ignored_HDF5_dtype_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported datatypes:\n";
2405 string ignored_HDF5_dspace_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported dimensions:\n";
2406 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
"\n";
2408 if (
true == is_dim_related) {
2409 if (ignored_msg.find(ignored_HDF5_dspace_var_hdr) == string::npos)
2410 ignored_msg += ignored_HDF5_dspace_var_hdr + ignored_HDF5_var_msg;
2412 ignored_msg += ignored_HDF5_var_msg;
2416 if (ignored_msg.find(ignored_HDF5_dtype_var_hdr) == string::npos)
2417 ignored_msg += ignored_HDF5_dtype_var_hdr + ignored_HDF5_var_msg;
2419 ignored_msg += ignored_HDF5_var_msg;
2425 void File::add_no_ignored_info()
2428 ignored_msg +=
"There are no ignored HDF5 objects or attributes.";
2434 bool File::ignored_dimscale_ref_list(
Var *var)
2437 bool ignored_dimscale =
true;
2440 bool has_dimscale =
false;
2441 bool has_reference_list =
false;
2442 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
2443 if ((*ira)->name ==
"REFERENCE_LIST" &&
false == HDF5CFUtil::cf_strict_support_type((*ira)->getType()))
2444 has_reference_list =
true;
2445 if ((*ira)->name ==
"CLASS") {
2446 Retrieve_H5_Attr_Value(*ira, var->fullpath);
2448 class_value.resize((*ira)->value.size());
2449 copy((*ira)->value.begin(), (*ira)->value.end(), class_value.begin());
2453 if (0 == class_value.compare(0, 15,
"DIMENSION_SCALE")) {
2454 has_dimscale =
true;
2458 if (
true == has_dimscale &&
true == has_reference_list) {
2459 ignored_dimscale =
false;
2465 return ignored_dimscale;
2469 bool File::Check_DropLongStr(
Var *var,
Attribute * attr)
2472 bool drop_longstr =
false;
2474 if (H5FSTRING == var->dtype || H5VSTRING == var->dtype) {
2476 drop_longstr = Check_VarDropLongStr(var->fullpath, var->dims, var->dtype);
2479 throw1(
"Check_VarDropLongStr fails ");
2486 if (H5FSTRING == attr->dtype || H5VSTRING == attr->dtype) {
2487 if (attr->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
2488 drop_longstr =
true;
2494 return drop_longstr;
2500 bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
2504 bool drop_longstr =
false;
2506 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2508 throw2(
"Cannot open the dataset ", varpath);
2510 hid_t dtype_id = -1;
2511 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2513 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2516 size_t ty_size = H5Tget_size(dtype_id);
2520 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2523 if (H5FSTRING == dtype) {
2524 if (ty_size > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2526 else if (H5VSTRING == dtype) {
2528 unsigned long long total_elms = 1;
2529 if (dims.size() != 0) {
2530 for (
unsigned int i = 0; i < dims.size(); i++)
2531 total_elms = total_elms * ((dims[i])->size);
2533 vector<char> strval;
2534 strval.resize(total_elms * ty_size);
2535 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) &strval[0]);
2539 throw2(
"Cannot read the data of the dataset ", varpath);
2542 vector<string> finstrval;
2543 finstrval.resize(total_elms);
2544 char*temp_bp = &strval[0];
2545 char*onestring = NULL;
2546 for (
unsigned long long i = 0; i < total_elms; i++) {
2547 onestring = *(
char**) temp_bp;
2548 if (onestring != NULL) {
2549 finstrval[i] = string(onestring);
2550 if(finstrval[i].size()>NC_JAVA_STR_SIZE_LIMIT) {
2551 drop_longstr =
true;
2558 if (
false == strval.empty()) {
2559 herr_t ret_vlen_claim;
2560 hid_t dspace_id = H5Dget_space(dset_id);
2561 if (dspace_id < 0) {
2564 throw2(
"Cannot obtain the dataspace id.", varpath);
2566 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) &strval[0]);
2567 if (ret_vlen_claim < 0) {
2569 H5Sclose(dspace_id);
2571 throw2(
"Cannot reclaim the vlen space ", varpath);
2573 if (H5Sclose(dspace_id) < 0) {
2576 throw2(
"Cannot close the HDF5 data space.", varpath);
2580 if (H5Tclose(dtype_id) < 0) {
2582 throw2(
"Cannot close the HDF5 data type.", varpath);
2584 if (H5Dclose(dset_id) < 0)
2585 throw2(
"Cannot close the HDF5 data type.", varpath);
2587 return drop_longstr;
2590 bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
2594 bool drop_longstr =
false;
2596 unsigned long long total_elms = 1;
2597 if (dims.size() != 0) {
2598 for (
unsigned int i = 0; i < dims.size(); i++)
2599 total_elms = total_elms * ((dims[i])->size);
2602 if (total_elms > NC_JAVA_STR_SIZE_LIMIT)
2603 drop_longstr =
true;
2607 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2609 throw2(
"Cannot open the dataset ", varpath);
2611 hid_t dtype_id = -1;
2612 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2614 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2617 size_t ty_size = H5Tget_size(dtype_id);
2621 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2624 if (H5FSTRING == dtype) {
2625 if ((ty_size * total_elms) > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2627 else if (H5VSTRING == dtype) {
2629 vector<char> strval;
2630 strval.resize(total_elms * ty_size);
2631 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) &strval[0]);
2635 throw2(
"Cannot read the data of the dataset ", varpath);
2638 vector<string> finstrval;
2639 finstrval.resize(total_elms);
2640 char*temp_bp = &strval[0];
2641 char*onestring = NULL;
2642 for (
unsigned long long i = 0; i < total_elms; i++) {
2643 onestring = *(
char**) temp_bp;
2644 if (onestring != NULL)
2645 finstrval[i] = string(onestring);
2652 if (
false == strval.empty()) {
2653 herr_t ret_vlen_claim;
2654 hid_t dspace_id = H5Dget_space(dset_id);
2655 if (dspace_id < 0) {
2658 throw2(
"Cannot obtain the dataspace id.", varpath);
2660 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) &strval[0]);
2661 if (ret_vlen_claim < 0) {
2663 H5Sclose(dspace_id);
2665 throw2(
"Cannot reclaim the vlen space ", varpath);
2667 if (H5Sclose(dspace_id) < 0) {
2670 throw2(
"Cannot close the HDF5 data space.", varpath);
2673 unsigned long long total_str_size = 0;
2674 for (
unsigned long long i = 0; i < total_elms; i++) {
2675 total_str_size += finstrval[i].size();
2676 if (total_str_size > NC_JAVA_STR_SIZE_LIMIT) {
2677 drop_longstr =
true;
2682 if (H5Tclose(dtype_id) < 0) {
2684 throw2(
"Cannot close the HDF5 data type.", varpath);
2686 if (H5Dclose(dset_id) < 0)
2687 throw2(
"Cannot close the HDF5 data type.", varpath);
2689 return drop_longstr;
2695 void File::add_ignored_grp_longstr_info(
const string& grp_path,
const string & attr_name)
2698 ignored_msg +=
"The HDF5 group: " + grp_path +
" has an empty-set string attribute: " + attr_name +
"\n";
2704 void File::add_ignored_var_longstr_info(
Var *var,
Attribute *attr)
2708 ignored_msg +=
"String variable: " + var->fullpath +
" value is set to empty.\n";
2710 ignored_msg +=
"The variable: " + var->fullpath +
" has an empty-set string attribute: " + attr->name +
"\n";
2717 void File::add_ignored_droplongstr_hdr()
2720 if (
false == this->have_ignored) this->have_ignored =
true;
2721 string hdr =
"\n\n The values of the following string variables ";
2722 hdr +=
" are set to empty because at least one string size in this variable exceeds netCDF Java string limit(32767 bytes).\n";
2723 hdr +=
"To obtain the values, change the BES key H5.EnableDropLongString=true at the handler BES";
2724 hdr +=
" configuration file(h5.conf)\nto H5.EnableDropLongString=false.\n\n";
2726 if (ignored_msg.rfind(hdr) == string::npos) ignored_msg += hdr;
2731 void File::release_standalone_var_vector(vector<Var*>&temp_vars)
2734 for (vector<Var *>::iterator i = temp_vars.begin(); i != temp_vars.end();) {
2736 i = temp_vars.erase(i);
This class specifies the core engineering of mapping HDF5 to DAP by following CF.
#define throw1(a1)
The followings are convenient functions to throw exceptions with different.
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)