46 using namespace HDF5CF;
51 newname = var->newname;
53 fullpath = var->fullpath;
55 total_elems = var->total_elems;
56 zero_storage_size = var->zero_storage_size;
58 comp_ratio = var->comp_ratio;
59 unsupported_attr_dtype = var->unsupported_attr_dtype;
60 unsupported_attr_dspace = var->unsupported_attr_dspace;
61 unsupported_dspace = var->unsupported_dspace;
62 unsupported_attr_dspace = var->unsupported_attr_dspace;
63 dimnameflag = var->dimnameflag;
64 coord_attr_add_path = var->coord_attr_add_path;
66 for (vector<Attribute*>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
68 attr->name = (*ira)->name;
69 attr->newname = (*ira)->newname;
70 attr->dtype = (*ira)->dtype;
71 attr->count = (*ira)->count;
72 attr->strsize = (*ira)->strsize;
73 attr->fstrsize = (*ira)->fstrsize;
74 attr->value = (*ira)->value;
75 attrs.push_back(attr);
78 for (vector<Dimension*>::iterator ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
80 dim->name = (*ird)->name;
81 dim->newname = (*ird)->newname;
82 dim->unlimited_dim = (*ird)->unlimited_dim;
88 bool CVar::isLatLon()
const
91 bool ret_value =
false;
92 if (CV_EXIST == this->cvartype || CV_MODIFY == this->cvartype || CV_SPECIAL == this->cvartype) {
93 string attr_name =
"units";
94 string lat_unit_value =
"degrees_north";
95 string lon_unit_value =
"degrees_east";
97 for (vector<Attribute *>::const_iterator ira = this->attrs.begin(); ira != this->attrs.end(); ira++) {
99 if ((H5FSTRING == (*ira)->getType()) || (H5VSTRING == (*ira)->getType())) {
100 if (attr_name == (*ira)->newname) {
101 string attr_value1((*ira)->getValue().begin(), (*ira)->getValue().end());
103 if ((*ira)->getCount() == 1) {
104 string attr_value((*ira)->getValue().begin(), (*ira)->getValue().end());
105 if (attr_value.compare(0, lat_unit_value.size(), lat_unit_value) == 0) {
106 if (attr_value.size() == lat_unit_value.size()) {
110 else if (attr_value.size() == (lat_unit_value.size() + 1)) {
111 if (attr_value[attr_value.size() - 1] ==
'\0'
112 || attr_value[attr_value.size() - 1] ==
' ') {
118 else if (attr_value.compare(0, lon_unit_value.size(), lon_unit_value) == 0) {
119 if (attr_value.size() == lon_unit_value.size()) {
123 else if (attr_value.size() == (lon_unit_value.size() + 1)) {
124 if (attr_value[attr_value.size() - 1] ==
'\0'
125 || attr_value[attr_value.size() - 1] ==
' ') {
138 else if (this->cvartype == CV_LAT_MISS || this->cvartype == CV_LON_MISS) ret_value =
true;
145 if (this->fileid >= 0) {
146 if (this->rootid >= 0) {
157 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
162 for_each(this->dims.begin(), this->dims.end(),
delete_elem());
163 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
166 Attribute::~Attribute()
173 BESDEBUG(
"h5",
"coming to Retrieve_H5_Info" <<endl);
175 if (
true == include_attr) {
179 this->check_ignored = HDF5RequestHandler::get_check_ignore_obj();
180 if (
true == this->check_ignored) this->add_ignored_info_page_header();
185 if ((root_id = H5Gopen(file_id,
"/", H5P_DEFAULT)) < 0) {
186 throw1(
"Cannot open the HDF5 root group ");
188 this->rootid = root_id;
190 this->Retrieve_H5_Obj(root_id,
"/", include_attr);
197 if (
true == include_attr) {
205 if (H5Oget_info(root_id, &oinfo) < 0)
206 throw1(
"Error obtaining the info for the root group");
208 num_attrs = oinfo.num_attrs;
209 bool temp_unsup_attr_atype =
false;
210 bool temp_unsup_attr_dspace =
false;
212 for (
int j = 0; j < num_attrs; j++) {
215 this->Retrieve_H5_Attr_Info(attr, root_id, j, temp_unsup_attr_atype, temp_unsup_attr_dspace);
225 this->unsupported_attr_dtype = temp_unsup_attr_atype;
226 this->unsupported_attr_dspace = temp_unsup_attr_dspace;
230 void File::Retrieve_H5_Obj(hid_t grp_id,
const char*gname,
bool include_attr)
237 if (H5Gget_info(grp_id, &g_info) < 0)
238 throw2(
"Counting hdf5 group elements error for ", gname);
239 nelems = g_info.nlinks;
241 ssize_t oname_size = 0;
242 for (hsize_t i = 0; i < nelems; i++) {
252 size_t dummy_name_len = 1;
255 oname_size = H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, NULL, dummy_name_len,
258 throw2(
"Error getting the size of the hdf5 object from the group: ", gname);
262 oname.resize((
size_t) oname_size + 1);
264 if (H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oname[0], (
size_t) (oname_size + 1),
266 throw2(
"Error getting the hdf5 object name from the group: ", gname);
270 if (H5Lget_info(grp_id, &oname[0], &linfo, H5P_DEFAULT) < 0)
271 throw2(
"HDF5 link name error from ", gname);
274 if (H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type) {
275 if (
true == include_attr &&
true == check_ignored) {
276 this->add_ignored_info_links_header();
277 string full_path_name;
278 string temp_oname(oname.begin(), oname.end());
280 (string(gname) !=
"/") ?
281 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
282 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
283 this->add_ignored_info_links(full_path_name);
292 if (H5Oget_info_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT) < 0)
293 throw2(
"Error obtaining the info for the object ",
string(oname.begin(), oname.end()));
295 H5O_type_t obj_type = oinfo.type;
299 case H5O_TYPE_GROUP: {
302 string full_path_name;
303 string temp_oname(oname.begin(), oname.end());
306 (string(gname) !=
"/") ?
307 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
308 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
310 cgroup = H5Gopen(grp_id, full_path_name.c_str(), H5P_DEFAULT);
312 throw2(
"Error opening the group ", full_path_name);
315 group->path = full_path_name;
316 group->newname = full_path_name;
319 if (
true == include_attr) {
321 int num_attrs = oinfo.num_attrs;
322 bool temp_unsup_attr_dtype =
false;
323 bool temp_unsup_attr_dspace =
false;
325 for (
int j = 0; j < num_attrs; j++) {
328 Retrieve_H5_Attr_Info(attr, cgroup, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
329 group->attrs.push_back(attr);
333 group->unsupported_attr_dtype = temp_unsup_attr_dtype;
334 group->unsupported_attr_dspace = temp_unsup_attr_dspace;
336 this->
groups.push_back(group);
337 Retrieve_H5_Obj(cgroup, full_path_name.c_str(), include_attr);
338 if (H5Gclose(cgroup) < 0)
339 throw2(
"Error closing the group ", full_path_name);
342 case H5O_TYPE_DATASET: {
345 string temp_oname(oname.begin(), oname.end());
346 string full_path_name = (
347 (string(gname) !=
"/") ?
348 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
349 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
352 var->name = temp_oname.substr(0, temp_oname.size() - 1);
353 var->fullpath = full_path_name;
356 var->newname = full_path_name;
358 cdset = H5Dopen(grp_id, full_path_name.c_str(), H5P_DEFAULT);
360 throw2(
"Error opening the HDF5 dataset ", full_path_name);
363 bool temp_unsup_var_dtype =
false;
364 Retrieve_H5_VarType(var, cdset, full_path_name, temp_unsup_var_dtype);
367 if (!this->unsupported_var_dtype && temp_unsup_var_dtype) this->unsupported_var_dtype =
true;
370 bool temp_unsup_var_dspace =
false;
371 Retrieve_H5_VarDim(var, cdset, full_path_name, temp_unsup_var_dspace);
374 if (!this->unsupported_var_dspace && temp_unsup_var_dspace) this->unsupported_var_dspace =
true;
376 hsize_t d_storage_size = H5Dget_storage_size(cdset);
377 var->zero_storage_size =(d_storage_size ==0);
378 var->comp_ratio = Retrieve_H5_VarCompRatio(var, cdset);
381 if (
true == include_attr) {
383 int num_attrs = oinfo.num_attrs;
384 bool temp_unsup_attr_dtype =
false;
385 bool temp_unsup_attr_dspace =
false;
387 for (
int j = 0; j < num_attrs; j++) {
391 Retrieve_H5_Attr_Info(attr, cdset, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
392 var->attrs.push_back(attr);
396 var->unsupported_attr_dtype = temp_unsup_attr_dtype;
397 var->unsupported_attr_dspace = temp_unsup_attr_dspace;
399 if (!this->unsupported_var_attr_dspace && temp_unsup_attr_dspace)
400 this->unsupported_var_attr_dspace =
true;
403 this->
vars.push_back(var);
404 if (H5Dclose(cdset) < 0)
405 throw2(
"Error closing the HDF5 dataset ", full_path_name);
409 case H5O_TYPE_NAMED_DATATYPE: {
411 if (
true == include_attr &&
true == check_ignored) {
412 this->add_ignored_info_namedtypes(
string(gname),
string(oname.begin(), oname.end()));
437 if (cgroup != -1) H5Gclose(cgroup);
439 if (cdset != -1) H5Dclose(cdset);
448 float File::Retrieve_H5_VarCompRatio(
Var *var, hid_t dset_id)
451 float comp_ratio = 1.0;
453 hid_t dset_create_plist = H5Dget_create_plist(dset_id);
454 if (dset_create_plist < 0)
455 throw1(
"unable to obtain hdf5 dataset creation property list ");
456 H5D_layout_t dset_layout = H5Pget_layout(dset_create_plist);
457 if (dset_layout < 0) {
458 H5Pclose(dset_create_plist);
459 throw1(
"unable to obtain hdf5 dataset creation property list storage layout");
462 if (dset_layout == H5D_CHUNKED) {
464 hsize_t dstorage_size = H5Dget_storage_size(dset_id);
465 if (dstorage_size > 0 && var->total_elems > 0) {
469 if ((ty_id = H5Dget_type(dset_id)) < 0)
470 throw1(
"unable to obtain hdf5 datatype for the dataset ");
471 size_t type_size = H5Tget_size(ty_id);
472 comp_ratio = ((float) (var->total_elems) * type_size) / dstorage_size;
477 H5Pclose(dset_create_plist);
482 void File::Retrieve_H5_VarType(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dtype)
488 if ((ty_id = H5Dget_type(dset_id)) < 0)
489 throw2(
"unable to obtain hdf5 datatype for the dataset ", varname);
508 if (
false == HDF5CFUtil::cf_strict_support_type(var->dtype)) unsup_var_dtype =
true;
510 if (H5Tclose(ty_id) < 0)
511 throw1(
"Unable to close the HDF5 datatype ");;
515 void File::Retrieve_H5_VarDim(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dspace)
518 vector<hsize_t> dsize;
519 vector<hsize_t> maxsize;
521 hid_t dspace_id = -1;
525 if ((dspace_id = H5Dget_space(dset_id)) < 0)
526 throw2(
"Cannot get hdf5 dataspace id for the variable ", varname);
528 H5S_class_t space_class = H5S_NO_CLASS;
529 if ((space_class = H5Sget_simple_extent_type(dspace_id)) < 0)
530 throw2(
"Cannot obtain the HDF5 dataspace class for the variable ", varname);
532 if (H5S_NULL == space_class)
533 unsup_var_dspace =
true;
535 if (
false == unsup_var_dspace) {
537 hssize_t h5_total_elms = H5Sget_simple_extent_npoints(dspace_id);
538 if (h5_total_elms < 0)
539 throw2(
"Cannot get the total number of elements of HDF5 dataset ", varname);
541 var->total_elems = (size_t) h5_total_elms;
542 int ndims = H5Sget_simple_extent_ndims(dspace_id);
544 throw2(
"Cannot get the hdf5 dataspace number of dimension for the variable ", varname);
549 maxsize.resize(ndims);
554 if (H5Sget_simple_extent_dims(dspace_id, &dsize[0], &maxsize[0]) < 0)
555 throw2(
"Cannot obtain the dim. info for the variable ", varname);
557 for (
int i = 0; i < ndims; i++) {
559 if (maxsize[i] == H5S_UNLIMITED) {
560 dim->unlimited_dim =
true;
561 if (
false == have_udim) have_udim =
true;
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);
586 void 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, NULL);
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)) unsup_attr_dtype =
true;
637 if(H5VSTRING == attr->dtype || H5FSTRING == attr->dtype) {
638 H5T_cset_t c_set_type = H5Tget_cset(ty_id);
640 throw2(
"Cannot get hdf5 character set type for the attribute ", attr_name);
643 attr->is_cset_ascii =
false;
646 if ((aspace_id = H5Aget_space(attrid)) < 0)
647 throw2(
"Cannot get hdf5 dataspace id for the attribute ", attr_name);
649 int ndims = H5Sget_simple_extent_ndims(aspace_id);
651 throw2(
"Cannot get the hdf5 dataspace number of dimension for attribute ", attr_name);
658 vector<hsize_t> asize;
659 vector<hsize_t> maxsize;
661 maxsize.resize(ndims);
664 if (H5Sget_simple_extent_dims(aspace_id, &asize[0], &maxsize[0]) < 0)
665 throw2(
"Cannot obtain the dim. info for the attribute ", attr_name);
668 for (
int dim_count = 0;dim_count < ndims; dim_count ++) {
670 if (asize[dim_count] == 0) {
671 unsup_attr_dspace =
true;
676 if (
false == unsup_attr_dspace) {
678 for (
int dim_count = 0; dim_count< ndims; dim_count++)
679 nelmts *= asize[dim_count];
685 size_t ty_size = H5Tget_size(ty_id);
687 throw2(
"Cannot obtain the dtype size for the attribute ", attr_name);
689 memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
691 throw2(
"Cannot obtain the memory datatype for the attribute ", attr_name);
694 string temp_aname(attr_name.begin(), attr_name.end());
695 attr->name = temp_aname.substr(0, temp_aname.size() - 1);
696 attr->newname = attr->name;
697 attr->count = nelmts;
700 if (H5Tclose(ty_id) < 0)
701 throw1(
"Cannot successfully close the attribute datatype.");
702 if (H5Tclose(memtype) < 0)
703 throw1(
"Cannot successfully close the attribute memory datatype.");
704 if (H5Sclose(aspace_id) < 0)
705 throw1(
"Cannot successfully close the HDF5 dataspace.");
706 if (H5Aclose(attrid) < 0)
707 throw1(
"Cannot successfully close the HDF5 attribute.");
712 if (ty_id != -1) H5Tclose(ty_id);
714 if (memtype != -1) H5Tclose(memtype);
716 if (aspace_id != -1) H5Sclose(aspace_id);
718 if (attrid != -1) H5Aclose(attrid);
729 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira)
730 Retrieve_H5_Attr_Value(*ira,
"/");
732 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
733 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
734 Retrieve_H5_Attr_Value(*ira, (*irg)->path);
738 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
739 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
740 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
747 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
748 Retrieve_H5_Attr_Value(*ira, var->fullpath);
753 void File::Retrieve_H5_Attr_Value(
Attribute *attr,
string obj_name)
760 hid_t memtype_id = -1;
761 hid_t aspace_id = -1;
766 obj_id = H5Oopen(this->fileid, obj_name.c_str(), H5P_DEFAULT);
768 throw2(
"Cannot open the object ", obj_name);
770 attr_id = H5Aopen(obj_id, (attr->name).c_str(), H5P_DEFAULT);
772 throw4(
"Cannot open the attribute ", attr->name,
" of object ", obj_name);
774 ty_id = H5Aget_type(attr_id);
776 throw4(
"Cannot obtain the datatype of the attribute ", attr->name,
" of object ", obj_name);
778 memtype_id = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
780 throw2(
"Cannot obtain the memory datatype for the attribute ", attr->name);
782 size_t ty_size = H5Tget_size(memtype_id);
784 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
786 size_t total_bytes = attr->count * ty_size;
789 if (H5VSTRING == attr->dtype) {
792 vector<char> temp_buf;
793 temp_buf.resize(total_bytes);
795 if (H5Aread(attr_id, memtype_id, &temp_buf[0]) < 0)
796 throw4(
"Cannot obtain the value of the attribute ", attr->name,
" of object ", obj_name);
798 char *temp_bp = NULL;
799 char *ptr_1stvlen_ptr = &temp_buf[0];
800 temp_bp = &temp_buf[0];
801 char* onestring = NULL;
802 string total_vstring =
"";
804 attr->strsize.resize(attr->count);
806 for (
unsigned int temp_i = 0; temp_i < attr->count; temp_i++) {
809 onestring = *(
char **) temp_bp;
810 if (onestring != NULL) {
811 total_vstring += string(onestring);
812 attr->strsize[temp_i] = (string(onestring)).size();
815 attr->strsize[temp_i] = 0;
821 if (ptr_1stvlen_ptr != NULL) {
822 aspace_id = H5Aget_space(attr_id);
824 throw4(
"Cannot obtain space id for ", attr->name,
" of object ", obj_name);
827 if (H5Dvlen_reclaim(memtype_id, aspace_id, H5P_DEFAULT, &temp_buf[0]) < 0)
828 throw4(
"Cannot reclaim VL memory for ", attr->name,
" of object ", obj_name);
834 throw4(
"Error to obtain the VL string type for attribute ", attr->name,
" of object ", obj_name);
836 attr->value.resize(total_vstring.size());
838 copy(total_vstring.begin(), total_vstring.end(), attr->value.begin());
843 if (attr->dtype == H5FSTRING) {
844 attr->fstrsize = ty_size;
847 attr->value.resize(total_bytes);
850 if (H5Aread(attr_id, memtype_id, (
void *) &attr->value[0]) < 0)
851 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
853 if (attr->dtype == H5FSTRING) {
855 size_t sect_size = ty_size;
859 (total_bytes % sect_size == 0) ? (total_bytes / sect_size) : (total_bytes / sect_size + 1);
861 throw4(
"The attribute datatype size is not a positive integer ", attr->name,
" of object ",
864 vector<size_t> sect_newsize;
865 sect_newsize.resize(num_sect);
867 string total_fstring = string(attr->value.begin(), attr->value.end());
871 attr->value.resize(new_total_fstring.size());
872 copy(new_total_fstring.begin(), new_total_fstring.end(), attr->value.begin());
873 attr->strsize.resize(num_sect);
874 for (
int temp_i = 0; temp_i < num_sect; temp_i++)
875 attr->strsize[temp_i] = sect_newsize[temp_i];
879 for (
int temp_i = 0; temp_i <num_sect; temp_i ++)
880 "h5",
"string new section size = " << attr->strsize[temp_i] <<endl;
885 if (H5Tclose(memtype_id) < 0)
886 throw1(
"Fail to close the HDF5 memory datatype ID.");
887 if (H5Tclose(ty_id) < 0)
888 throw1(
"Fail to close the HDF5 datatype ID.");
889 if (H5Aclose(attr_id) < 0)
890 throw1(
"Fail to close the HDF5 attribute ID.");
891 if (H5Oclose(obj_id) < 0)
892 throw1(
"Fail to close the HDF5 object ID.");
898 if (memtype_id != -1) H5Tclose(memtype_id);
900 if (ty_id != -1) H5Tclose(ty_id);
902 if (aspace_id != -1) H5Sclose(aspace_id);
904 if (attr_id != -1) H5Aclose(attr_id);
906 if (obj_id != -1) H5Oclose(obj_id);
917 if (
true == include_attr) {
918 Handle_Group_Unsupported_Dtype();
919 Handle_VarAttr_Unsupported_Dtype();
922 Handle_Var_Unsupported_Dtype();
928 if (
true == include_attr) {
929 if (
true == this->unsupported_attr_dtype) {
930 for (vector<Attribute *>::iterator ira = this->root_attrs.begin();
931 ira != this->root_attrs.end(); ) {
932 H5DataType temp_dtype = (*ira)->getType();
933 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
935 ira = this->root_attrs.erase(ira);
946 if (
false == this->groups.empty()) {
947 for (vector<Group *>::iterator irg = this->groups.begin();
948 irg != this->groups.end(); ++irg) {
949 if (
false == (*irg)->attrs.empty()) {
950 if (
true == (*irg)->unsupported_attr_dtype) {
951 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin();
952 ira != (*irg)->attrs.end(); ) {
953 H5DataType temp_dtype = (*ira)->getType();
954 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
956 ira = (*irg)->attrs.erase(ira);
969 if (
false == this->vars.empty()) {
970 if (
true == include_attr) {
971 for (vector<Var *>::iterator irv = this->vars.begin();
972 irv != this->vars.end();++irv ) {
973 if (
false == (*irv)->attrs.empty()) {
974 if (
true == (*irv)->unsupported_attr_dtype) {
975 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
976 ira != (*irv)->attrs.end(); ) {
977 H5DataType temp_dtype = (*ira)->getType();
978 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
980 ira = (*irv)->attrs.erase(ira);
991 if (
true == this->unsupported_var_dtype) {
993 for (vector<Var *>::iterator irv = this->vars.begin();
994 irv != this->vars.end(); ) {
995 H5DataType temp_dtype = (*irv)->getType();
996 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
998 irv = this->vars.erase(irv);
1008 void File::Handle_Group_Unsupported_Dtype()
1013 if (
true == this->unsupported_attr_dtype) {
1014 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1015 H5DataType temp_dtype = (*ira)->getType();
1016 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1028 if (
false == this->
groups.empty()) {
1029 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1030 if (
false == (*irg)->attrs.empty()) {
1031 if (
true == (*irg)->unsupported_attr_dtype) {
1032 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1033 H5DataType temp_dtype = (*ira)->getType();
1034 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1036 ira = (*irg)->attrs.erase(ira);
1049 void File::Gen_Group_Unsupported_Dtype_Info()
1055 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1056 H5DataType temp_dtype = (*ira)->getType();
1057 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
1058 this->add_ignored_info_attrs(
true,
"/", (*ira)->name);
1065 if (
false == this->
groups.empty()) {
1066 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1067 if (
false == (*irg)->attrs.empty()) {
1069 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1070 H5DataType temp_dtype = (*ira)->getType();
1071 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype==H5UINT64 ) {
1072 this->add_ignored_info_attrs(
true, (*irg)->path, (*ira)->name);
1082 void File::Handle_Var_Unsupported_Dtype()
1084 if (
false == this->
vars.empty()) {
1085 if (
true == this->unsupported_var_dtype) {
1086 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end();) {
1087 H5DataType temp_dtype = (*irv)->getType();
1088 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1090 irv = this->
vars.erase(irv);
1102 void File::Gen_Var_Unsupported_Dtype_Info()
1105 if (
false == this->
vars.empty()) {
1107 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1108 H5DataType temp_dtype = (*irv)->getType();
1109 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)||(H5INT64 == temp_dtype) ||(H5UINT64 == temp_dtype)) {
1110 this->add_ignored_info_objs(
false, (*irv)->fullpath);
1119 void File::Handle_VarAttr_Unsupported_Dtype()
1121 if (
false == this->
vars.empty()) {
1122 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1123 if (
false == (*irv)->attrs.empty()) {
1124 if (
true == (*irv)->unsupported_attr_dtype) {
1125 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1126 H5DataType temp_dtype = (*ira)->getType();
1127 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1129 ira = (*irv)->attrs.erase(ira);
1142 void File::Gen_VarAttr_Unsupported_Dtype_Info()
1145 if (
false == this->
vars.empty()) {
1146 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1147 if (
false == (*irv)->attrs.empty()) {
1149 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1150 H5DataType temp_dtype = (*ira)->getType();
1151 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || (temp_dtype==H5INT64) || (temp_dtype == H5UINT64)) {
1152 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1165 void File::Gen_DimScale_VarAttr_Unsupported_Dtype_Info()
1168 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1172 bool is_ignored = ignored_dimscale_ref_list((*irv));
1173 if (
false == (*irv)->attrs.empty()) {
1175 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1176 H5DataType temp_dtype = (*ira)->getType();
1177 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || (temp_dtype == H5INT64) || (temp_dtype == H5UINT64)) {
1181 if ((
"DIMENSION_LIST" != (*ira)->name)
1182 && (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
1183 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1192 void File::Handle_GroupAttr_Unsupported_Dspace()
1197 if (
true == this->unsupported_attr_dspace) {
1198 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1200 if ((*ira)->count == 0) {
1212 if (
false == this->
groups.empty()) {
1213 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1214 if (
false == (*irg)->attrs.empty()) {
1215 if (
true == (*irg)->unsupported_attr_dspace) {
1216 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1217 if ((*ira)->count == 0) {
1219 ira = (*irg)->attrs.erase(ira);
1232 void File::Handle_VarAttr_Unsupported_Dspace()
1235 if (
false == this->
vars.empty()) {
1236 if (
true == this->unsupported_var_attr_dspace) {
1237 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1238 if (
false == (*irv)->attrs.empty()) {
1239 if (
true == (*irv)->unsupported_attr_dspace) {
1240 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1241 if (0 == (*ira)->count) {
1243 ira = (*irv)->attrs.erase(ira);
1261 if (
false == this->
vars.empty()) {
1262 if (
true == this->unsupported_var_dspace) {
1263 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end();) {
1264 if (
true == (*irv)->unsupported_dspace) {
1266 irv = this->
vars.erase(irv);
1276 if (
true == include_attr) {
1277 Handle_GroupAttr_Unsupported_Dspace();
1278 Handle_VarAttr_Unsupported_Dspace();
1283 void File::Gen_Unsupported_Dspace_Info()
1291 if (
false == this->
vars.empty()) {
1292 if (
true == this->unsupported_var_dspace) {
1293 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1294 if (
true == (*irv)->unsupported_dspace) {
1295 this->add_ignored_info_objs(
true, (*irv)->fullpath);
1307 if (
true == this->check_ignored &&
true == include_attr) {
1309 if (
true == HDF5RequestHandler::get_drop_long_string()) {
1313 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1314 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1315 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1316 this->add_ignored_droplongstr_hdr();
1317 this->add_ignored_grp_longstr_info(
"/", (*ira)->name);
1322 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1323 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1324 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1325 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1326 this->add_ignored_droplongstr_hdr();
1327 this->add_ignored_grp_longstr_info((*irg)->path, (*ira)->name);
1333 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1334 if (
true == Check_DropLongStr((*irv), NULL)) {
1335 this->add_ignored_droplongstr_hdr();
1336 this->add_ignored_var_longstr_info((*irv), NULL);
1340 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1341 if (
true == Check_DropLongStr((*irv), (*ira))) {
1342 this->add_ignored_droplongstr_hdr();
1343 this->add_ignored_var_longstr_info((*irv), (*ira));
1357 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1358 (*irv)->newname = get_CF_string((*irv)->newname);
1360 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1361 (*ird)->newname = get_CF_string((*ird)->newname);
1365 if (
true == include_attr) {
1367 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1368 (*ira)->newname = get_CF_string((*ira)->newname);
1371 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1372 (*irg)->newname = get_CF_string((*irg)->newname);
1373 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1374 (*ira)->newname = get_CF_string((*ira)->newname);
1378 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1379 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1380 (*ira)->newname = get_CF_string((*ira)->newname);
1387 void File::Handle_Var_NameClashing(set<string>&objnameset)
1390 Handle_General_NameClashing(objnameset, this->
vars);
1394 void File::Handle_Group_NameClashing(set<string> &objnameset)
1397 pair<set<string>::iterator,
bool> setret;
1407 setret = objnameset.insert(FILE_ATTR_TABLE_NAME);
1408 if (
false == setret.second) {
1410 int clash_index = 1;
1411 string fa_clash_name = FILE_ATTR_TABLE_NAME;
1412 HDF5CFUtil::gen_unique_name(fa_clash_name, objnameset, clash_index);
1413 FILE_ATTR_TABLE_NAME = fa_clash_name;
1417 Handle_General_NameClashing(objnameset, this->
groups);
1422 void File::Handle_Obj_AttrNameClashing()
1433 set<string> objnameset;
1436 Handle_General_NameClashing(objnameset, this->
root_attrs);
1439 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1441 Handle_General_NameClashing(objnameset, (*irg)->attrs);
1445 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1447 Handle_General_NameClashing(objnameset, (*irv)->attrs);
1453 template<
class T>
void File::Handle_General_NameClashing(set<string>&objnameset, vector<T*>& objvec)
1457 pair<set<string>::iterator,
bool> setret;
1458 set<string>::iterator iss;
1460 vector<string> clashnamelist;
1461 vector<string>::iterator ivs;
1463 map<int, int> cl_to_ol;
1468 typename vector<T*>::iterator irv;
1470 for (irv = objvec.begin(); irv != objvec.end(); ++irv) {
1471 setret = objnameset.insert((*irv)->newname);
1472 if (
false == setret.second) {
1473 clashnamelist.insert(clashnamelist.end(), (*irv)->newname);
1474 cl_to_ol[cl_index] = ol_index;
1482 for (ivs = clashnamelist.begin(); ivs != clashnamelist.end(); ivs++) {
1483 int clash_index = 1;
1484 string temp_clashname = *ivs +
'_';
1485 HDF5CFUtil::gen_unique_name(temp_clashname, objnameset, clash_index);
1486 *ivs = temp_clashname;
1490 for (
unsigned int i = 0; i < clashnamelist.size(); i++)
1491 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
1496 void File::Handle_GeneralObj_NameClashing(
bool include_attr, set<string>& objnameset)
1499 Handle_Var_NameClashing(objnameset);
1500 if (
true == include_attr) {
1501 Handle_Group_NameClashing(objnameset);
1502 Handle_Obj_AttrNameClashing();
1507 string File::get_CF_string(
string s)
1510 if (
"" == s)
return s;
1511 string insertString(1,
'_');
1514 if (
true == isdigit(s[0])) s.insert(0, insertString);
1516 for (
unsigned int i = 0; i < s.length(); i++)
1517 if ((
false == isalnum(s[i])) && (s[i] !=
'_')) s[i] =
'_';
1524 void File::Insert_One_NameSizeMap_Element(
string name, hsize_t size,
bool unlimited)
1526 pair<map<string, hsize_t>::iterator,
bool> mapret;
1527 mapret = dimname_to_dimsize.insert(pair<string, hsize_t>(name, size));
1528 if (
false == mapret.second)
1529 throw4(
"The dimension name ", name,
" should map to ", size);
1531 pair<map<string, bool>::iterator,
bool> mapret2;
1532 mapret2 = dimname_to_unlimited.insert(pair<string, bool>(name, unlimited));
1533 if (
false == mapret2.second)
1534 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1539 void File::Insert_One_NameSizeMap_Element2(map<string, hsize_t>& name_to_size, map<string, bool>& name_to_unlimited,
1540 string name, hsize_t size,
bool unlimited)
1542 pair<map<string, hsize_t>::iterator,
bool> mapret;
1543 mapret = name_to_size.insert(pair<string, hsize_t>(name, size));
1544 if (
false == mapret.second)
1545 throw4(
"The dimension name ", name,
" should map to ", size);
1547 pair<map<string, bool>::iterator,
bool> mapret2;
1548 mapret2 = name_to_unlimited.insert(pair<string, bool>(name, unlimited));
1549 if (
false == mapret2.second)
1550 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1567 void File::Add_One_FakeDim_Name(
Dimension *dim)
1570 stringstream sfakedimindex;
1571 string fakedimstr =
"FakeDim";
1572 pair<set<string>::iterator,
bool> setret;
1573 map<hsize_t, string>::iterator im;
1574 pair<map<hsize_t, string>::iterator,
bool> mapret;
1576 sfakedimindex << addeddimindex;
1577 string added_dimname = fakedimstr + sfakedimindex.str();
1581 if (
false == mapret.second) {
1583 dim->newname = dim->name;
1590 setret = dimnamelist.insert(added_dimname);
1591 if (
false == setret.second) {
1592 int clash_index = 1;
1593 string temp_clashname = added_dimname +
'_';
1594 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1595 dim->name = temp_clashname;
1596 dim->newname = dim->name;
1597 setret = dimnamelist.insert(dim->name);
1598 if (
false == setret.second)
1599 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1605 if (
false == mapret.second)
1606 throw4(
"The dimension size ", dim->size,
" should map to ", dim->name);
1610 dim->name = added_dimname;
1611 dim->newname = dim->name;
1612 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1620 void File::Adjust_Duplicate_FakeDim_Name(
Dimension * dim)
1628 stringstream sfakedimindex;
1629 pair<set<string>::iterator,
bool> setret;
1632 sfakedimindex << addeddimindex;
1633 string added_dimname =
"FakeDim" + sfakedimindex.str();
1634 setret = dimnamelist.insert(added_dimname);
1635 if (
false == setret.second) {
1636 int clash_index = 1;
1637 string temp_clashname = added_dimname +
'_';
1638 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1639 dim->name = temp_clashname;
1640 dim->newname = dim->name;
1641 setret = dimnamelist.insert(dim->name);
1642 if (
false == setret.second)
1643 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1645 dim->name = added_dimname;
1646 dim->newname = dim->name;
1647 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1655 void File::Replace_Dim_Name_All(
const string orig_dim_name,
const string new_dim_name) {
1658 for (vector<Var *>::iterator irv = this->
vars.begin();
1659 irv != this->vars.end(); ++irv) {
1660 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1661 ird != (*irv)->dims.end(); ++ird) {
1662 if((*ird)->name == orig_dim_name) {
1663 (*ird)->name = new_dim_name;
1664 (*ird)->newname = new_dim_name;
1673 void File::Use_Dim_Name_With_Size_All(
const string dim_name,
const size_t dim_size) {
1676 for (vector<Var *>::iterator irv = this->
vars.begin();
1677 irv != this->vars.end(); ++irv) {
1678 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1679 ird != (*irv)->dims.end(); ++ird) {
1680 if((*ird)->size == orig_dim_name) {
1681 (*ird)->name = new_dim_name;
1682 (*ird)->newname = new_dim_name;
1692 void File::Add_Str_Attr(
Attribute* attr,
const string &attrname,
const string& strvalue)
1695 attr->name = attrname;
1696 attr->newname = attr->name;
1697 attr->dtype = H5FSTRING;
1699 attr->fstrsize = strvalue.size();
1700 attr->strsize.resize(1);
1701 attr->strsize[0] = attr->fstrsize;
1702 attr->value.resize(strvalue.size());
1703 copy(strvalue.begin(), strvalue.end(), attr->value.begin());
1708 File:: Var_Has_Attr(
Var*var,
const string &attrname) {
1710 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end(); ++ira) {
1714 if((*ira)->name == attrname || (*ira)->newname == attrname) {
1723 string File::Retrieve_Str_Attr_Value(
Attribute *attr,
const string var_path)
1726 if (attr != NULL && var_path !=
"") {
1727 Retrieve_H5_Attr_Value(attr, var_path);
1728 string orig_attr_value(attr->value.begin(), attr->value.end());
1729 return orig_attr_value;
1736 bool File::Is_Str_Attr(
Attribute* attr,
string varfullpath,
const string &attrname,
const string& strvalue)
1738 bool ret_value =
false;
1739 if (attrname == get_CF_string(attr->newname)) {
1740 Retrieve_H5_Attr_Value(attr, varfullpath);
1741 string attr_value(attr->value.begin(), attr->value.end());
1742 if (attr_value == strvalue) ret_value =
true;
1748 bool File::has_latlon_cf_units(
Attribute *attr,
const string &varfullpath,
bool is_lat)
1750 string attr_name =
"units";
1751 if (
true == is_lat) {
1752 string lat_unit_value =
"degrees_north";
1753 return Is_Str_Attr(attr, varfullpath, attr_name, lat_unit_value);
1756 string lon_unit_value =
"degrees_east";
1757 return Is_Str_Attr(attr, varfullpath, attr_name, lon_unit_value);
1762 void File::Add_One_Float_Attr(
Attribute* attr,
const string &attrname,
float float_value)
1764 attr->name = attrname;
1765 attr->newname = attr->name;
1766 attr->dtype = H5FLOAT32;
1768 attr->value.resize(
sizeof(
float));
1769 memcpy(&(attr->value[0]), (
void*) (&float_value),
sizeof(
float));
1774 void File::Change_Attr_One_Str_to_Others(
Attribute* attr,
Var*var)
1779 long int num_sli = 0;
1780 if (attr->dtype != H5FSTRING)
1781 throw2(
"Currently we only convert fixed-size string to other datatypes. ", attr->name);
1782 if (attr->count != 1)
1783 throw4(
"The fixed-size string count must be 1 and the current count is ", attr->count,
" for the attribute ",
1786 Retrieve_H5_Attr_Value(attr, var->fullpath);
1788 attr_value.resize(attr->value.size());
1789 copy(attr->value.begin(), attr->value.end(), attr_value.begin());
1791 switch (var->dtype) {
1794 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1795 if (num_sli < 0 || num_sli > UCHAR_MAX)
1796 throw5(
"Attribute type is unsigned char, the current attribute ", attr->name,
" has the value ", num_sli,
1797 ". It is overflowed. ");
1799 unsigned char num_suc = (
unsigned char) num_sli;
1800 attr->dtype = H5UCHAR;
1801 attr->value.resize(
sizeof(
unsigned char));
1802 memcpy(&(attr->value[0]), (
void*) (&num_suc),
sizeof(
unsigned char));
1808 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1809 if (num_sli < SCHAR_MIN || num_sli > SCHAR_MAX)
1810 throw5(
"Attribute type is signed char, the current attribute ", attr->name,
" has the value ", num_sli,
1811 ". It is overflowed. ");
1813 char num_sc = (char) num_sli;
1814 attr->dtype = H5CHAR;
1815 attr->value.resize(
sizeof(
char));
1816 memcpy(&(attr->value[0]), (
void*) (&num_sc),
sizeof(
char));
1822 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1823 if (num_sli < SHRT_MIN || num_sli > SHRT_MAX)
1824 throw5(
"Attribute type is 16-bit integer, the current attribute ", attr->name,
" has the value ", num_sli,
1825 ". It is overflowed. ");
1827 short num_ss = (short) num_sli;
1828 attr->dtype = H5INT16;
1829 attr->value.resize(
sizeof(
short));
1830 memcpy(&(attr->value[0]), (
void*) (&num_ss),
sizeof(
short));
1836 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1837 if (num_sli < 0 || num_sli > USHRT_MAX)
1838 throw5(
"Attribute type is unsigned 16-bit integer, the current attribute ", attr->name,
" has the value ",
1839 num_sli,
". It is overflowed. ");
1841 unsigned short num_uss = (
unsigned short) num_sli;
1842 attr->dtype = H5UINT16;
1843 attr->value.resize(
sizeof(
unsigned short));
1844 memcpy(&(attr->value[0]), (
void*) (&num_uss),
sizeof(
unsigned short));
1849 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1855 attr->dtype = H5INT32;
1856 attr->value.resize(
sizeof(
long int));
1857 memcpy(&(attr->value[0]), (
void*) (&num_sli),
sizeof(
long int));
1862 unsigned long int num_suli = strtoul(&(attr->value[0]), &pEnd, 10);
1864 attr->dtype = H5UINT32;
1865 attr->value.resize(
sizeof(
unsigned long int));
1866 memcpy(&(attr->value[0]), (
void*) (&num_suli),
sizeof(
unsigned long int));
1870 float num_sf = strtof(&(attr->value[0]), NULL);
1872 attr->dtype = H5FLOAT32;
1873 attr->value.resize(
sizeof(
float));
1874 memcpy(&(attr->value[0]), (
void*) (&num_sf),
sizeof(
float));
1878 double num_sd = strtod(&(attr->value[0]), NULL);
1880 attr->dtype = H5FLOAT64;
1881 attr->value.resize(
sizeof(
double));
1882 memcpy(&(attr->value[0]), (
void*) (&num_sd),
sizeof(
double));
1887 throw4(
"Unsupported HDF5 datatype that the string is converted to for the attribute ", attr->name,
1888 " of the variable ", var->fullpath);
1894 void File::Replace_Var_Str_Attr(
Var* var,
const string &attr_name,
const string& strvalue)
1897 bool rep_attr =
true;
1898 bool rem_attr =
false;
1899 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1900 if ((*ira)->name == attr_name) {
1901 if (
true == Is_Str_Attr(*ira, var->fullpath, attr_name, strvalue))
1910 if (
true == rem_attr) {
1911 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1912 if ((*ira)->name == attr_name) {
1914 var->attrs.erase(ira);
1921 if (
true == rep_attr) {
1923 Add_Str_Attr(attr, attr_name, strvalue);
1924 var->attrs.push_back(attr);
1929 bool File::Is_geolatlon(
const string & var_name,
bool is_lat)
1932 bool ret_value =
false;
1933 if (
true == is_lat) {
1934 string lat1 =
"lat";
1935 string lat2 =
"latitude";
1936 string lat3 =
"Latitude";
1938 if (var_name.compare(lat1) == 0 || var_name.compare(lat2) == 0 || var_name.compare(lat3) == 0) ret_value =
true;
1942 string lon1 =
"lon";
1943 string lon2 =
"longitude";
1944 string lon3 =
"Longitude";
1945 if (var_name.compare(lon1) == 0 || var_name.compare(lon2) == 0 || var_name.compare(lon3) == 0) ret_value =
true;
1955 if (
false == add_path)
return;
1958 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1960 const string varname = (*irv)->name;
1961 const string attrname =
"origname";
1962 Add_Str_Attr(attr, attrname, varname);
1963 (*irv)->attrs.push_back(attr);
1966 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1970 if((*irv)->zero_storage_size==
false
1971 || HDF5RequestHandler::get_no_zero_size_fullnameattr() ==
false) {
1973 const string varname = (*irv)->fullpath;
1974 const string attrname =
"fullnamepath";
1975 Add_Str_Attr(attr, attrname, varname);
1976 (*irv)->attrs.push_back(attr);
1981 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1983 if (
false == (*irg)->attrs.empty()) {
1986 const string varname = (*irg)->path;
1987 const string attrname =
"fullnamepath";
1988 Add_Str_Attr(attr, attrname, varname);
1989 (*irg)->attrs.push_back(attr);
1998 void File::Replace_Var_Info(
Var *src,
Var *target)
2002 for_each (target->dims.begin (), target->dims.end (),
2004 for_each (target->attrs.begin (), target->attrs.end (),
2008 target->newname = src->newname;
2009 target->name = src->name;
2010 target->fullpath = src->fullpath;
2011 target->rank = src->rank;
2012 target->dtype = src->dtype;
2013 target->unsupported_attr_dtype = src->unsupported_attr_dtype;
2014 target->unsupported_dspace = src->unsupported_dspace;
2016 for (vector<Attribute*>::iterator ira = target->attrs.begin();
2017 ira!=target->attrs.end(); ++ira) {
2019 target->attrs.erase(ira);
2023 for (vector<Dimension*>::iterator ird = target->dims.begin(); ird != target->dims.end();) {
2025 ird = target->dims.erase(ird);
2030 for (vector<Attribute*>::iterator ira = src->attrs.begin();
2031 ira!=src->attrs.end(); ++ira) {
2033 attr->name = (*ira)->name;
2034 attr->newname = (*ira)->newname;
2035 attr->dtype =(*ira)->dtype;
2036 attr->count =(*ira)->count;
2037 attr->strsize = (*ira)->strsize;
2038 attr->fstrsize = (*ira)->fstrsize;
2039 attr->value =(*ira)->value;
2040 target->attrs.push_back(attr);
2044 for (vector<Dimension*>::iterator ird = src->dims.begin(); ird != src->dims.end(); ++ird) {
2046 dim->name = (*ird)->name;
2047 dim->newname = (*ird)->newname;
2048 target->dims.push_back(dim);
2054 void File::Replace_Var_Attrs(
Var *src,
Var *target)
2058 for_each (target->dims.begin (), target->dims.end (),
2060 for_each (target->attrs.begin (), target->attrs.end (),
2064 for (vector<Attribute*>::iterator ira = target->attrs.begin(); ira != target->attrs.end();) {
2066 ira = target->attrs.erase(ira);
2068 for (vector<Attribute*>::iterator ira = src->attrs.begin(); ira != src->attrs.end(); ++ira) {
2070 attr->name = (*ira)->name;
2071 attr->newname = (*ira)->newname;
2072 attr->dtype = (*ira)->dtype;
2073 attr->count = (*ira)->count;
2074 attr->strsize = (*ira)->strsize;
2075 attr->fstrsize = (*ira)->fstrsize;
2076 attr->value = (*ira)->value;
2077 target->attrs.push_back(attr);
2085 bool File::is_var_under_group(
const string &varname,
const string &grpname,
const int var_rank,
2086 vector<size_t> & var_size)
2089 bool ret_value =
false;
2090 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2092 if ((*irv)->rank == var_rank) {
2093 if ((*irv)->name == varname) {
2096 string var_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
2099 if (grpname == var_path) {
2101 for (
int i = 0; i < var_rank; i++)
2102 var_size[i] = (*irv)->getDimensions()[i]->size;
2115 bool ret_value =
false;
2116 for (vector<Var *>::iterator irv = this->
vars.begin();
2117 irv != this->vars.end(); ++irv) {
2118 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2119 ira != (*irv)->attrs.end(); ++ira) {
2120 if((*ira)->name ==
"grid_mapping") {
2125 if(
true == ret_value)
2135 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2137 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
2138 if((*ira)->name ==
"grid_mapping") {
2139 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
2140 attr_value.resize((*ira)->value.size());
2141 copy((*ira)->value.begin(), (*ira)->value.end(), attr_value.begin());
2146 if(attr_value.find(
'/') ==string::npos){
2147 string new_name = Check_Grid_Mapping_VarName(attr_value,(*irv)->fullpath);
2149 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2153 string new_name = Check_Grid_Mapping_FullPath(attr_value);
2156 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2162 string File::Check_Grid_Mapping_VarName(
const string & a_value,
const string & var_fpath) {
2164 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var_fpath);
2165 string gmap_new_name;
2166 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2167 if((*irv)->name == a_value){
2168 if(var_path == HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) {
2169 gmap_new_name = (*irv)->newname;
2174 return gmap_new_name;
2178 string File::Check_Grid_Mapping_FullPath(
const string & a_value) {
2180 string gmap_new_name;
2181 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2182 if((*irv)->fullpath == a_value){
2183 gmap_new_name = (*irv)->newname;
2188 return gmap_new_name;
2191 void File::remove_netCDF_internal_attributes(
bool include_attr) {
2193 if(
true == include_attr) {
2194 for (vector<Var *>::iterator irv = this->
vars.begin();
2195 irv != this->vars.end(); ++irv) {
2196 bool var_has_dimscale =
false;
2198 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2199 ira != (*irv)->attrs.end();) {
2200 if((*ira)->name ==
"CLASS") {
2201 string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2205 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2207 ira = (*irv)->attrs.erase(ira);
2208 var_has_dimscale =
true;
2221 else if((*ira)->name ==
"NAME") {
2222 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2223 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
2225 ira =(*irv)->attrs.erase(ira);
2228 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
2229 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
2231 ira =(*irv)->attrs.erase(ira);
2240 else if((*ira)->name ==
"_Netcdf4Dimid") {
2242 ira =(*irv)->attrs.erase(ira);
2244 else if((*ira)->name ==
"_Netcdf4Coordinates") {
2246 ira =(*irv)->attrs.erase(ira);
2249 else if((*ira)->name ==
"_nc3_strict") {
2251 ira =(*irv)->attrs.erase(ira);
2259 if(
true == var_has_dimscale) {
2260 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2261 ira != (*irv)->attrs.end();++ira) {
2262 if((*ira)->name ==
"NAME") {
2264 ira =(*irv)->attrs.erase(ira);
2274 void File::add_ignored_info_page_header()
2277 " \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";
2281 void File::add_ignored_info_obj_header()
2284 ignored_msg +=
" Some HDF5 objects or the object information are ignored when mapping to DAP2 by the HDF5 OPeNDAP";
2285 ignored_msg +=
" handler due to the restrictions of DAP2, CF conventions or CF tools.";
2286 ignored_msg +=
" Please use HDF5 tools(h5dump or HDFView) to check carefully and make sure that these objects";
2288 " are OK to ignore for your service. For questions or requests to find a way to handle the ignored objects, please";
2289 ignored_msg +=
" contact the HDF5 OPeNDAP handler developer or send an email to help@hdfgroup.org.\n";
2291 ignored_msg +=
" \n In general, ignored HDF5 objects include HDF5 soft links, external links and named datatype.\n";
2293 " \n The HDF5 datasets(variables in the CF term) and attributes that have the following datatypes are ignored: \n";
2295 " Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2296 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2299 " \n The HDF5 datasets(variables in the CF term) and attributes associated with the following dimensions are ignored: \n";
2300 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2301 ignored_msg +=
" 2) attributes that have any zero size dimensions(not reported due to extreme rarity and non-trivial coding)\n\n";
2306 void File::add_ignored_info_links_header()
2309 if (
false == this->have_ignored) {
2310 add_ignored_info_obj_header();
2311 have_ignored =
true;
2314 string lh_msg =
"******WARNING******\n";
2315 lh_msg +=
"IGNORED soft links or external links are: ";
2316 if (ignored_msg.rfind(lh_msg) == string::npos) ignored_msg += lh_msg +
"\n";
2323 File:: add_ignored_info_obj_dtype_header() {
2326 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported datatypes. \n";
2327 ignored_msg +=
" In general, the unsupported datatypes include: \n";
2328 ignored_msg +=
" Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2329 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2334 File:: add_ignored_info_obj_dspace_header() {
2337 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported dimensions. \n";
2338 ignored_msg +=
" In general, the unsupported dimensions include: \n";
2339 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2340 ignored_msg +=
" 2) variables that have any zero size dimensions\n";
2346 void File::add_ignored_info_links(
const string & link_path)
2348 if (ignored_msg.find(
"Link paths: ") == string::npos)
2349 ignored_msg +=
" Link paths: " + link_path;
2351 ignored_msg +=
" " + link_path;
2355 void File::add_ignored_info_namedtypes(
const string& grp_name,
const string& named_dtype_name)
2358 if (
false == this->have_ignored) {
2359 add_ignored_info_obj_header();
2360 have_ignored =
true;
2363 string ignored_HDF5_named_dtype_hdr =
"\n******WARNING******";
2364 ignored_HDF5_named_dtype_hdr +=
"\n IGNORED HDF5 named datatype objects:\n";
2365 string ignored_HDF5_named_dtype_msg =
" Group name: " + grp_name +
" HDF5 named datatype name: " + named_dtype_name.substr(0,named_dtype_name.size()-1)
2367 if (ignored_msg.find(ignored_HDF5_named_dtype_hdr) == string::npos)
2368 ignored_msg += ignored_HDF5_named_dtype_hdr + ignored_HDF5_named_dtype_msg;
2370 ignored_msg += ignored_HDF5_named_dtype_msg;
2376 void File::add_ignored_info_attrs(
bool is_grp,
const string & obj_path,
const string & attr_name)
2379 if (
false == this->have_ignored) {
2380 add_ignored_info_obj_header();
2381 have_ignored =
true;
2385 string ignored_warning_str =
"\n******WARNING******";
2386 string ignored_HDF5_grp_hdr = ignored_warning_str +
"\n Ignored attributes under root and groups:\n";
2387 string ignored_HDF5_grp_msg =
" Group path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2388 string ignored_HDF5_var_hdr = ignored_warning_str +
"\n Ignored attributes for variables:\n";
2389 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2392 if (
true == is_grp) {
2393 if (ignored_msg.find(ignored_HDF5_grp_hdr) == string::npos)
2394 ignored_msg += ignored_HDF5_grp_hdr + ignored_HDF5_grp_msg;
2396 ignored_msg += ignored_HDF5_grp_msg;
2399 if (ignored_msg.find(ignored_HDF5_var_hdr) == string::npos)
2400 ignored_msg += ignored_HDF5_var_hdr + ignored_HDF5_var_msg;
2402 ignored_msg += ignored_HDF5_var_msg;
2409 void File::add_ignored_info_objs(
bool is_dim_related,
const string & obj_path)
2412 if (
false == this->have_ignored) {
2413 add_ignored_info_obj_header();
2414 have_ignored =
true;
2417 string ignored_warning_str =
"\n******WARNING******";
2418 string ignored_HDF5_dtype_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported datatypes:\n";
2419 string ignored_HDF5_dspace_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported dimensions:\n";
2420 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
"\n";
2422 if (
true == is_dim_related) {
2423 if (ignored_msg.find(ignored_HDF5_dspace_var_hdr) == string::npos)
2424 ignored_msg += ignored_HDF5_dspace_var_hdr + ignored_HDF5_var_msg;
2426 ignored_msg += ignored_HDF5_var_msg;
2430 if (ignored_msg.find(ignored_HDF5_dtype_var_hdr) == string::npos)
2431 ignored_msg += ignored_HDF5_dtype_var_hdr + ignored_HDF5_var_msg;
2433 ignored_msg += ignored_HDF5_var_msg;
2439 void File::add_no_ignored_info()
2442 ignored_msg +=
"There are no ignored HDF5 objects or attributes.";
2448 bool File::ignored_dimscale_ref_list(
Var *var)
2451 bool ignored_dimscale =
true;
2454 bool has_dimscale =
false;
2455 bool has_reference_list =
false;
2456 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
2457 if ((*ira)->name ==
"REFERENCE_LIST" &&
false == HDF5CFUtil::cf_strict_support_type((*ira)->getType()))
2458 has_reference_list =
true;
2459 if ((*ira)->name ==
"CLASS") {
2460 Retrieve_H5_Attr_Value(*ira, var->fullpath);
2462 class_value.resize((*ira)->value.size());
2463 copy((*ira)->value.begin(), (*ira)->value.end(), class_value.begin());
2467 if (0 == class_value.compare(0, 15,
"DIMENSION_SCALE")) {
2468 has_dimscale =
true;
2472 if (
true == has_dimscale &&
true == has_reference_list) {
2473 ignored_dimscale =
false;
2479 return ignored_dimscale;
2483 bool File::Check_DropLongStr(
Var *var,
Attribute * attr)
2486 bool drop_longstr =
false;
2488 if (H5FSTRING == var->dtype || H5VSTRING == var->dtype) {
2490 drop_longstr = Check_VarDropLongStr(var->fullpath, var->dims, var->dtype);
2493 throw1(
"Check_VarDropLongStr fails ");
2500 if (H5FSTRING == attr->dtype || H5VSTRING == attr->dtype) {
2501 if (attr->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
2502 drop_longstr =
true;
2508 return drop_longstr;
2514 bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
const
2518 bool drop_longstr =
false;
2520 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2522 throw2(
"Cannot open the dataset ", varpath);
2524 hid_t dtype_id = -1;
2525 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2527 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2530 size_t ty_size = H5Tget_size(dtype_id);
2534 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2537 if (H5FSTRING == dtype) {
2538 if (ty_size > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2540 else if (H5VSTRING == dtype) {
2542 unsigned long long total_elms = 1;
2543 if (dims.size() != 0) {
2544 for (
unsigned int i = 0; i < dims.size(); i++)
2545 total_elms = total_elms * ((dims[i])->size);
2547 vector<char> strval;
2548 strval.resize(total_elms * ty_size);
2549 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) &strval[0]);
2553 throw2(
"Cannot read the data of the dataset ", varpath);
2556 vector<string> finstrval;
2557 finstrval.resize(total_elms);
2558 char*temp_bp = &strval[0];
2559 char*onestring = NULL;
2560 for (
unsigned long long i = 0; i < total_elms; i++) {
2561 onestring = *(
char**) temp_bp;
2562 if (onestring != NULL) {
2563 finstrval[i] = string(onestring);
2564 if(finstrval[i].size()>NC_JAVA_STR_SIZE_LIMIT) {
2565 drop_longstr =
true;
2572 if (
false == strval.empty()) {
2573 herr_t ret_vlen_claim;
2574 hid_t dspace_id = H5Dget_space(dset_id);
2575 if (dspace_id < 0) {
2578 throw2(
"Cannot obtain the dataspace id.", varpath);
2580 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) &strval[0]);
2581 if (ret_vlen_claim < 0) {
2583 H5Sclose(dspace_id);
2585 throw2(
"Cannot reclaim the vlen space ", varpath);
2587 if (H5Sclose(dspace_id) < 0) {
2590 throw2(
"Cannot close the HDF5 data space.", varpath);
2594 if (H5Tclose(dtype_id) < 0) {
2596 throw2(
"Cannot close the HDF5 data type.", varpath);
2598 if (H5Dclose(dset_id) < 0)
2599 throw2(
"Cannot close the HDF5 data type.", varpath);
2601 return drop_longstr;
2604 bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
2608 bool drop_longstr =
false;
2610 unsigned long long total_elms = 1;
2611 if (dims.size() != 0) {
2612 for (
unsigned int i = 0; i < dims.size(); i++)
2613 total_elms = total_elms * ((dims[i])->size);
2616 if (total_elms > NC_JAVA_STR_SIZE_LIMIT)
2617 drop_longstr =
true;
2621 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2623 throw2(
"Cannot open the dataset ", varpath);
2625 hid_t dtype_id = -1;
2626 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2628 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2631 size_t ty_size = H5Tget_size(dtype_id);
2635 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2638 if (H5FSTRING == dtype) {
2639 if ((ty_size * total_elms) > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2641 else if (H5VSTRING == dtype) {
2643 vector<char> strval;
2644 strval.resize(total_elms * ty_size);
2645 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) &strval[0]);
2649 throw2(
"Cannot read the data of the dataset ", varpath);
2652 vector<string> finstrval;
2653 finstrval.resize(total_elms);
2654 char*temp_bp = &strval[0];
2655 char*onestring = NULL;
2656 for (
unsigned long long i = 0; i < total_elms; i++) {
2657 onestring = *(
char**) temp_bp;
2658 if (onestring != NULL)
2659 finstrval[i] = string(onestring);
2666 if (
false == strval.empty()) {
2667 herr_t ret_vlen_claim;
2668 hid_t dspace_id = H5Dget_space(dset_id);
2669 if (dspace_id < 0) {
2672 throw2(
"Cannot obtain the dataspace id.", varpath);
2674 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) &strval[0]);
2675 if (ret_vlen_claim < 0) {
2677 H5Sclose(dspace_id);
2679 throw2(
"Cannot reclaim the vlen space ", varpath);
2681 if (H5Sclose(dspace_id) < 0) {
2684 throw2(
"Cannot close the HDF5 data space.", varpath);
2687 unsigned long long total_str_size = 0;
2688 for (
unsigned long long i = 0; i < total_elms; i++) {
2689 total_str_size += finstrval[i].size();
2690 if (total_str_size > NC_JAVA_STR_SIZE_LIMIT) {
2691 drop_longstr =
true;
2696 if (H5Tclose(dtype_id) < 0) {
2698 throw2(
"Cannot close the HDF5 data type.", varpath);
2700 if (H5Dclose(dset_id) < 0)
2701 throw2(
"Cannot close the HDF5 data type.", varpath);
2703 return drop_longstr;
2709 void File::add_ignored_grp_longstr_info(
const string& grp_path,
const string & attr_name)
2712 ignored_msg +=
"The HDF5 group: " + grp_path +
" has an empty-set string attribute: " + attr_name +
"\n";
2718 void File::add_ignored_var_longstr_info(
Var *var,
Attribute *attr)
2722 ignored_msg +=
"String variable: " + var->fullpath +
" value is set to empty.\n";
2724 ignored_msg +=
"The variable: " + var->fullpath +
" has an empty-set string attribute: " + attr->name +
"\n";
2731 void File::add_ignored_droplongstr_hdr()
2734 if (
false == this->have_ignored) this->have_ignored =
true;
2735 string hdr =
"\n\n The values of the following string variables ";
2736 hdr +=
" are set to empty because at least one string size in this variable exceeds netCDF Java string limit(32767 bytes).\n";
2737 hdr +=
"To obtain the values, change the BES key H5.EnableDropLongString=true at the handler BES";
2738 hdr +=
" configuration file(h5.conf)\nto H5.EnableDropLongString=false.\n\n";
2740 if (ignored_msg.rfind(hdr) == string::npos) ignored_msg += hdr;
2745 void File::release_standalone_var_vector(vector<Var*>&temp_vars)
2748 for (vector<Var *>::iterator i = temp_vars.begin(); i != temp_vars.end();) {
2750 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)