44 #include "h5apicompatible.h"
47 using namespace HDF5CF;
52 newname = var->newname;
54 fullpath = var->fullpath;
56 total_elems = var->total_elems;
57 zero_storage_size = var->zero_storage_size;
59 comp_ratio = var->comp_ratio;
60 unsupported_attr_dtype = var->unsupported_attr_dtype;
61 unsupported_attr_dspace = var->unsupported_attr_dspace;
62 unsupported_dspace = var->unsupported_dspace;
63 unsupported_attr_dspace = var->unsupported_attr_dspace;
64 dimnameflag = var->dimnameflag;
65 coord_attr_add_path = var->coord_attr_add_path;
67 for (vector<Attribute*>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
69 attr->name = (*ira)->name;
70 attr->newname = (*ira)->newname;
71 attr->dtype = (*ira)->dtype;
72 attr->count = (*ira)->count;
73 attr->strsize = (*ira)->strsize;
74 attr->fstrsize = (*ira)->fstrsize;
75 attr->value = (*ira)->value;
76 attrs.push_back(attr);
79 for (vector<Dimension*>::iterator ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
81 dim->name = (*ird)->name;
82 dim->newname = (*ird)->newname;
83 dim->unlimited_dim = (*ird)->unlimited_dim;
89 bool CVar::isLatLon()
const
92 bool ret_value =
false;
93 if (CV_EXIST == this->cvartype || CV_MODIFY == this->cvartype || CV_SPECIAL == this->cvartype) {
94 string attr_name =
"units";
95 string lat_unit_value =
"degrees_north";
96 string lon_unit_value =
"degrees_east";
98 for (vector<Attribute *>::const_iterator ira = this->attrs.begin(); ira != this->attrs.end(); ira++) {
100 if ((H5FSTRING == (*ira)->getType()) || (H5VSTRING == (*ira)->getType())) {
101 if (attr_name == (*ira)->newname) {
102 string attr_value1((*ira)->getValue().begin(), (*ira)->getValue().end());
104 if ((*ira)->getCount() == 1) {
105 string attr_value((*ira)->getValue().begin(), (*ira)->getValue().end());
106 if (attr_value.compare(0, lat_unit_value.size(), lat_unit_value) == 0) {
107 if (attr_value.size() == lat_unit_value.size()) {
111 else if (attr_value.size() == (lat_unit_value.size() + 1)) {
112 if (attr_value[attr_value.size() - 1] ==
'\0'
113 || attr_value[attr_value.size() - 1] ==
' ') {
119 else if (attr_value.compare(0, lon_unit_value.size(), lon_unit_value) == 0) {
120 if (attr_value.size() == lon_unit_value.size()) {
124 else if (attr_value.size() == (lon_unit_value.size() + 1)) {
125 if (attr_value[attr_value.size() - 1] ==
'\0'
126 || attr_value[attr_value.size() - 1] ==
' ') {
139 else if (this->cvartype == CV_LAT_MISS || this->cvartype == CV_LON_MISS) ret_value =
true;
146 if (this->fileid >= 0) {
147 if (this->rootid >= 0) {
158 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
163 for_each(this->dims.begin(), this->dims.end(),
delete_elem());
164 for_each(this->attrs.begin(), this->attrs.end(),
delete_elem());
167 Attribute::~Attribute()
174 BESDEBUG(
"h5",
"coming to Retrieve_H5_Info" <<endl);
176 if (
true == include_attr) {
180 this->check_ignored = HDF5RequestHandler::get_check_ignore_obj();
181 if (
true == this->check_ignored) this->add_ignored_info_page_header();
186 if ((root_id = H5Gopen(file_id,
"/", H5P_DEFAULT)) < 0) {
187 throw1(
"Cannot open the HDF5 root group ");
189 this->rootid = root_id;
191 this->Retrieve_H5_Obj(root_id,
"/", include_attr);
198 if (
true == include_attr) {
206 if (H5OGET_INFO(root_id, &oinfo) < 0)
207 throw1(
"Error obtaining the info for the root group");
209 num_attrs = oinfo.num_attrs;
210 bool temp_unsup_attr_atype =
false;
211 bool temp_unsup_attr_dspace =
false;
213 for (
int j = 0; j < num_attrs; j++) {
216 this->Retrieve_H5_Attr_Info(attr, root_id, j, temp_unsup_attr_atype, temp_unsup_attr_dspace);
226 this->unsupported_attr_dtype = temp_unsup_attr_atype;
227 this->unsupported_attr_dspace = temp_unsup_attr_dspace;
231 void File::Retrieve_H5_Obj(hid_t grp_id,
const char*gname,
bool include_attr)
238 if (H5Gget_info(grp_id, &g_info) < 0)
239 throw2(
"Counting hdf5 group elements error for ", gname);
240 nelems = g_info.nlinks;
242 ssize_t oname_size = 0;
243 for (hsize_t i = 0; i < nelems; i++) {
253 size_t dummy_name_len = 1;
256 oname_size = H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, NULL, dummy_name_len,
259 throw2(
"Error getting the size of the hdf5 object from the group: ", gname);
263 oname.resize((
size_t) oname_size + 1);
265 if (H5Lget_name_by_idx(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oname[0], (
size_t) (oname_size + 1),
267 throw2(
"Error getting the hdf5 object name from the group: ", gname);
271 if (H5Lget_info(grp_id, &oname[0], &linfo, H5P_DEFAULT) < 0)
272 throw2(
"HDF5 link name error from ", gname);
275 if (H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type) {
276 if (
true == include_attr &&
true == check_ignored) {
277 this->add_ignored_info_links_header();
278 string full_path_name;
279 string temp_oname(oname.begin(), oname.end());
281 (string(gname) !=
"/") ?
282 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
283 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
284 this->add_ignored_info_links(full_path_name);
293 if (H5OGET_INFO_BY_IDX(grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT) < 0)
294 throw2(
"Error obtaining the info for the object ",
string(oname.begin(), oname.end()));
296 H5O_type_t obj_type = oinfo.type;
300 case H5O_TYPE_GROUP: {
303 string full_path_name;
304 string temp_oname(oname.begin(), oname.end());
307 (string(gname) !=
"/") ?
308 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
309 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
311 cgroup = H5Gopen(grp_id, full_path_name.c_str(), H5P_DEFAULT);
313 throw2(
"Error opening the group ", full_path_name);
316 group->path = full_path_name;
317 group->newname = full_path_name;
320 if (
true == include_attr) {
322 int num_attrs = oinfo.num_attrs;
323 bool temp_unsup_attr_dtype =
false;
324 bool temp_unsup_attr_dspace =
false;
326 for (
int j = 0; j < num_attrs; j++) {
329 Retrieve_H5_Attr_Info(attr, cgroup, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
330 group->attrs.push_back(attr);
334 group->unsupported_attr_dtype = temp_unsup_attr_dtype;
335 group->unsupported_attr_dspace = temp_unsup_attr_dspace;
337 this->
groups.push_back(group);
338 Retrieve_H5_Obj(cgroup, full_path_name.c_str(), include_attr);
339 if (H5Gclose(cgroup) < 0)
340 throw2(
"Error closing the group ", full_path_name);
343 case H5O_TYPE_DATASET: {
346 string temp_oname(oname.begin(), oname.end());
347 string full_path_name = (
348 (string(gname) !=
"/") ?
349 (
string(gname) +
"/" + temp_oname.substr(0, temp_oname.size() - 1)) :
350 (
"/" + temp_oname.substr(0, temp_oname.size() - 1)));
353 var->name = temp_oname.substr(0, temp_oname.size() - 1);
354 var->fullpath = full_path_name;
357 var->newname = full_path_name;
359 cdset = H5Dopen(grp_id, full_path_name.c_str(), H5P_DEFAULT);
361 throw2(
"Error opening the HDF5 dataset ", full_path_name);
364 bool temp_unsup_var_dtype =
false;
365 Retrieve_H5_VarType(var, cdset, full_path_name, temp_unsup_var_dtype);
368 if (!this->unsupported_var_dtype && temp_unsup_var_dtype) this->unsupported_var_dtype =
true;
371 bool temp_unsup_var_dspace =
false;
372 Retrieve_H5_VarDim(var, cdset, full_path_name, temp_unsup_var_dspace);
375 if (!this->unsupported_var_dspace && temp_unsup_var_dspace) this->unsupported_var_dspace =
true;
377 hsize_t d_storage_size = H5Dget_storage_size(cdset);
378 var->zero_storage_size =(d_storage_size ==0);
379 var->comp_ratio = Retrieve_H5_VarCompRatio(var, cdset);
382 if (
true == include_attr) {
384 int num_attrs = oinfo.num_attrs;
385 bool temp_unsup_attr_dtype =
false;
386 bool temp_unsup_attr_dspace =
false;
388 for (
int j = 0; j < num_attrs; j++) {
392 Retrieve_H5_Attr_Info(attr, cdset, j, temp_unsup_attr_dtype, temp_unsup_attr_dspace);
393 var->attrs.push_back(attr);
397 var->unsupported_attr_dtype = temp_unsup_attr_dtype;
398 var->unsupported_attr_dspace = temp_unsup_attr_dspace;
400 if (!this->unsupported_var_attr_dspace && temp_unsup_attr_dspace)
401 this->unsupported_var_attr_dspace =
true;
404 this->
vars.push_back(var);
405 if (H5Dclose(cdset) < 0)
406 throw2(
"Error closing the HDF5 dataset ", full_path_name);
410 case H5O_TYPE_NAMED_DATATYPE: {
412 if (
true == include_attr &&
true == check_ignored) {
413 this->add_ignored_info_namedtypes(
string(gname),
string(oname.begin(), oname.end()));
438 if (cgroup != -1) H5Gclose(cgroup);
440 if (cdset != -1) H5Dclose(cdset);
449 float File::Retrieve_H5_VarCompRatio(
Var *var, hid_t dset_id)
452 float comp_ratio = 1.0;
454 hid_t dset_create_plist = H5Dget_create_plist(dset_id);
455 if (dset_create_plist < 0)
456 throw1(
"unable to obtain hdf5 dataset creation property list ");
457 H5D_layout_t dset_layout = H5Pget_layout(dset_create_plist);
458 if (dset_layout < 0) {
459 H5Pclose(dset_create_plist);
460 throw1(
"unable to obtain hdf5 dataset creation property list storage layout");
463 if (dset_layout == H5D_CHUNKED) {
465 hsize_t dstorage_size = H5Dget_storage_size(dset_id);
466 if (dstorage_size > 0 && var->total_elems > 0) {
470 if ((ty_id = H5Dget_type(dset_id)) < 0)
471 throw1(
"unable to obtain hdf5 datatype for the dataset ");
472 size_t type_size = H5Tget_size(ty_id);
473 comp_ratio = ((float) (var->total_elems) * type_size) / dstorage_size;
478 H5Pclose(dset_create_plist);
483 void File::Retrieve_H5_VarType(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dtype)
489 if ((ty_id = H5Dget_type(dset_id)) < 0)
490 throw2(
"unable to obtain hdf5 datatype for the dataset ", varname);
509 if (
false == HDF5CFUtil::cf_strict_support_type(var->dtype,_is_dap4))
510 unsup_var_dtype =
true;
512 if (H5Tclose(ty_id) < 0)
513 throw1(
"Unable to close the HDF5 datatype ");;
517 void File::Retrieve_H5_VarDim(
Var *var, hid_t dset_id,
const string & varname,
bool &unsup_var_dspace)
520 vector<hsize_t> dsize;
521 vector<hsize_t> maxsize;
523 hid_t dspace_id = -1;
527 if ((dspace_id = H5Dget_space(dset_id)) < 0)
528 throw2(
"Cannot get hdf5 dataspace id for the variable ", varname);
530 H5S_class_t space_class = H5S_NO_CLASS;
531 if ((space_class = H5Sget_simple_extent_type(dspace_id)) < 0)
532 throw2(
"Cannot obtain the HDF5 dataspace class for the variable ", varname);
534 if (H5S_NULL == space_class)
535 unsup_var_dspace =
true;
537 if (
false == unsup_var_dspace) {
539 hssize_t h5_total_elms = H5Sget_simple_extent_npoints(dspace_id);
540 if (h5_total_elms < 0)
541 throw2(
"Cannot get the total number of elements of HDF5 dataset ", varname);
543 var->total_elems = (size_t) h5_total_elms;
544 int ndims = H5Sget_simple_extent_ndims(dspace_id);
546 throw2(
"Cannot get the hdf5 dataspace number of dimension for the variable ", varname);
551 maxsize.resize(ndims);
556 if (H5Sget_simple_extent_dims(dspace_id, &dsize[0], &maxsize[0]) < 0)
557 throw2(
"Cannot obtain the dim. info for the variable ", varname);
559 for (
int i = 0; i < ndims; i++) {
561 if (maxsize[i] == H5S_UNLIMITED) {
562 dim->unlimited_dim =
true;
563 if (
false == have_udim) have_udim =
true;
565 var->dims.push_back(dim);
570 var->unsupported_dspace = unsup_var_dspace;
572 if (H5Sclose(dspace_id) < 0)
573 throw1(
"Cannot close the HDF5 dataspace .");
579 if (dspace_id != -1) H5Sclose(dspace_id);
581 if (ty_id != -1) H5Tclose(ty_id);
588 void File::Retrieve_H5_Attr_Info(
Attribute * attr, hid_t obj_id,
const int j,
bool &unsup_attr_dtype,
589 bool &unsup_attr_dspace)
595 hid_t aspace_id = -1;
601 if ((attrid = H5Aopen_by_idx(obj_id,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) j, H5P_DEFAULT,
603 throw1(
"Unable to open attribute by index ");
606 ssize_t name_size = H5Aget_name(attrid, 0, NULL);
608 throw1(
"Unable to obtain the size of the hdf5 attribute name ");
611 attr_name.resize(name_size + 1);
614 if ((H5Aget_name(attrid, name_size + 1, &attr_name[0])) < 0)
615 throw1(
"unable to obtain the hdf5 attribute name ");
618 if ((ty_id = H5Aget_type(attrid)) < 0)
619 throw2(
"unable to obtain hdf5 datatype for the attribute ", attr_name);
637 if (
false == HDF5CFUtil::cf_strict_support_type(attr->dtype,_is_dap4))
638 unsup_attr_dtype =
true;
640 if(H5VSTRING == attr->dtype || H5FSTRING == attr->dtype) {
641 H5T_cset_t c_set_type = H5Tget_cset(ty_id);
643 throw2(
"Cannot get hdf5 character set type for the attribute ", attr_name);
646 attr->is_cset_ascii =
false;
649 if ((aspace_id = H5Aget_space(attrid)) < 0)
650 throw2(
"Cannot get hdf5 dataspace id for the attribute ", attr_name);
652 int ndims = H5Sget_simple_extent_ndims(aspace_id);
654 throw2(
"Cannot get the hdf5 dataspace number of dimension for attribute ", attr_name);
661 vector<hsize_t> asize;
662 vector<hsize_t> maxsize;
664 maxsize.resize(ndims);
667 if (H5Sget_simple_extent_dims(aspace_id, &asize[0], &maxsize[0]) < 0)
668 throw2(
"Cannot obtain the dim. info for the attribute ", attr_name);
671 for (
int dim_count = 0;dim_count < ndims; dim_count ++) {
673 if (asize[dim_count] == 0) {
674 unsup_attr_dspace =
true;
679 if (
false == unsup_attr_dspace) {
681 for (
int dim_count = 0; dim_count< ndims; dim_count++)
682 nelmts *= asize[dim_count];
688 size_t ty_size = H5Tget_size(ty_id);
690 throw2(
"Cannot obtain the dtype size for the attribute ", attr_name);
692 memtype = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
694 throw2(
"Cannot obtain the memory datatype for the attribute ", attr_name);
697 string temp_aname(attr_name.begin(), attr_name.end());
698 attr->name = temp_aname.substr(0, temp_aname.size() - 1);
699 attr->newname = attr->name;
700 attr->count = nelmts;
703 if (H5Tclose(ty_id) < 0)
704 throw1(
"Cannot successfully close the attribute datatype.");
705 if (H5Tclose(memtype) < 0)
706 throw1(
"Cannot successfully close the attribute memory datatype.");
707 if (H5Sclose(aspace_id) < 0)
708 throw1(
"Cannot successfully close the HDF5 dataspace.");
709 if (H5Aclose(attrid) < 0)
710 throw1(
"Cannot successfully close the HDF5 attribute.");
715 if (ty_id != -1) H5Tclose(ty_id);
717 if (memtype != -1) H5Tclose(memtype);
719 if (aspace_id != -1) H5Sclose(aspace_id);
721 if (attrid != -1) H5Aclose(attrid);
732 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira)
733 Retrieve_H5_Attr_Value(*ira,
"/");
735 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
736 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
737 Retrieve_H5_Attr_Value(*ira, (*irg)->path);
741 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
742 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
743 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
750 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ++ira) {
751 Retrieve_H5_Attr_Value(*ira, var->fullpath);
756 void File::Retrieve_H5_Attr_Value(
Attribute *attr,
string obj_name)
763 hid_t memtype_id = -1;
764 hid_t aspace_id = -1;
769 obj_id = H5Oopen(this->fileid, obj_name.c_str(), H5P_DEFAULT);
771 throw2(
"Cannot open the object ", obj_name);
773 attr_id = H5Aopen(obj_id, (attr->name).c_str(), H5P_DEFAULT);
775 throw4(
"Cannot open the attribute ", attr->name,
" of object ", obj_name);
777 ty_id = H5Aget_type(attr_id);
779 throw4(
"Cannot obtain the datatype of the attribute ", attr->name,
" of object ", obj_name);
781 memtype_id = H5Tget_native_type(ty_id, H5T_DIR_ASCEND);
783 throw2(
"Cannot obtain the memory datatype for the attribute ", attr->name);
785 size_t ty_size = H5Tget_size(memtype_id);
787 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
789 size_t total_bytes = attr->count * ty_size;
792 if (H5VSTRING == attr->dtype) {
795 vector<char> temp_buf;
796 temp_buf.resize(total_bytes);
798 if (H5Aread(attr_id, memtype_id, &temp_buf[0]) < 0)
799 throw4(
"Cannot obtain the value of the attribute ", attr->name,
" of object ", obj_name);
801 char *temp_bp = NULL;
802 char *ptr_1stvlen_ptr = &temp_buf[0];
803 temp_bp = &temp_buf[0];
804 char* onestring = NULL;
805 string total_vstring =
"";
807 attr->strsize.resize(attr->count);
809 for (
unsigned int temp_i = 0; temp_i < attr->count; temp_i++) {
812 onestring = *(
char **) temp_bp;
813 if (onestring != NULL) {
814 total_vstring += string(onestring);
815 attr->strsize[temp_i] = (string(onestring)).size();
818 attr->strsize[temp_i] = 0;
824 if (ptr_1stvlen_ptr != NULL) {
825 aspace_id = H5Aget_space(attr_id);
827 throw4(
"Cannot obtain space id for ", attr->name,
" of object ", obj_name);
830 if (H5Dvlen_reclaim(memtype_id, aspace_id, H5P_DEFAULT, &temp_buf[0]) < 0)
831 throw4(
"Cannot reclaim VL memory for ", attr->name,
" of object ", obj_name);
837 throw4(
"Error to obtain the VL string type for attribute ", attr->name,
" of object ", obj_name);
839 attr->value.resize(total_vstring.size());
841 copy(total_vstring.begin(), total_vstring.end(), attr->value.begin());
846 if (attr->dtype == H5FSTRING) {
847 attr->fstrsize = ty_size;
850 attr->value.resize(total_bytes);
853 if (H5Aread(attr_id, memtype_id, (
void *) &attr->value[0]) < 0)
854 throw4(
"Cannot obtain the dtype size for the attribute ", attr->name,
" of object ", obj_name);
856 if (attr->dtype == H5FSTRING) {
858 size_t sect_size = ty_size;
862 (total_bytes % sect_size == 0) ? (total_bytes / sect_size) : (total_bytes / sect_size + 1);
864 throw4(
"The attribute datatype size is not a positive integer ", attr->name,
" of object ",
867 vector<size_t> sect_newsize;
868 sect_newsize.resize(num_sect);
870 string total_fstring = string(attr->value.begin(), attr->value.end());
874 attr->value.resize(new_total_fstring.size());
875 copy(new_total_fstring.begin(), new_total_fstring.end(), attr->value.begin());
876 attr->strsize.resize(num_sect);
877 for (
int temp_i = 0; temp_i < num_sect; temp_i++)
878 attr->strsize[temp_i] = sect_newsize[temp_i];
882 cerr<<
"Attr name is "<<attr->name <<endl;
883 for (
int temp_i = 0; temp_i <num_sect; temp_i ++)
884 cerr<<
"string new section size = " << attr->strsize[temp_i] <<endl;
889 if (H5Tclose(memtype_id) < 0)
890 throw1(
"Fail to close the HDF5 memory datatype ID.");
891 if (H5Tclose(ty_id) < 0)
892 throw1(
"Fail to close the HDF5 datatype ID.");
893 if (H5Aclose(attr_id) < 0)
894 throw1(
"Fail to close the HDF5 attribute ID.");
895 if (H5Oclose(obj_id) < 0)
896 throw1(
"Fail to close the HDF5 object ID.");
902 if (memtype_id != -1) H5Tclose(memtype_id);
904 if (ty_id != -1) H5Tclose(ty_id);
906 if (aspace_id != -1) H5Sclose(aspace_id);
908 if (attr_id != -1) H5Aclose(attr_id);
910 if (obj_id != -1) H5Oclose(obj_id);
921 if (
true == include_attr) {
922 Handle_Group_Unsupported_Dtype();
923 Handle_VarAttr_Unsupported_Dtype();
926 Handle_Var_Unsupported_Dtype();
932 if (
true == include_attr) {
933 if (
true == this->unsupported_attr_dtype) {
934 for (vector<Attribute *>::iterator ira = this->root_attrs.begin();
935 ira != this->root_attrs.end(); ) {
936 H5DataType temp_dtype = (*ira)->getType();
937 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
939 ira = this->root_attrs.erase(ira);
950 if (
false == this->groups.empty()) {
951 for (vector<Group *>::iterator irg = this->groups.begin();
952 irg != this->groups.end(); ++irg) {
953 if (
false == (*irg)->attrs.empty()) {
954 if (
true == (*irg)->unsupported_attr_dtype) {
955 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin();
956 ira != (*irg)->attrs.end(); ) {
957 H5DataType temp_dtype = (*ira)->getType();
958 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
960 ira = (*irg)->attrs.erase(ira);
973 if (
false == this->vars.empty()) {
974 if (
true == include_attr) {
975 for (vector<Var *>::iterator irv = this->vars.begin();
976 irv != this->vars.end();++irv ) {
977 if (
false == (*irv)->attrs.empty()) {
978 if (
true == (*irv)->unsupported_attr_dtype) {
979 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
980 ira != (*irv)->attrs.end(); ) {
981 H5DataType temp_dtype = (*ira)->getType();
982 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
984 ira = (*irv)->attrs.erase(ira);
995 if (
true == this->unsupported_var_dtype) {
997 for (vector<Var *>::iterator irv = this->vars.begin();
998 irv != this->vars.end(); ) {
999 H5DataType temp_dtype = (*irv)->getType();
1000 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
1002 irv = this->vars.erase(irv);
1012 void File::Handle_Group_Unsupported_Dtype()
1017 if (
true == this->unsupported_attr_dtype) {
1018 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1019 H5DataType temp_dtype = (*ira)->getType();
1020 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1032 if (
false == this->
groups.empty()) {
1033 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1034 if (
false == (*irg)->attrs.empty()) {
1035 if (
true == (*irg)->unsupported_attr_dtype) {
1036 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1037 H5DataType temp_dtype = (*ira)->getType();
1038 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1040 ira = (*irg)->attrs.erase(ira);
1053 void File::Gen_Group_Unsupported_Dtype_Info()
1059 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1060 H5DataType temp_dtype = (*ira)->getType();
1063 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1064 || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
1065 this->add_ignored_info_attrs(
true,
"/", (*ira)->name);
1072 if (
false == this->
groups.empty()) {
1073 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1074 if (
false == (*irg)->attrs.empty()) {
1076 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1077 H5DataType temp_dtype = (*ira)->getType();
1080 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1081 || temp_dtype == H5INT64 || temp_dtype==H5UINT64 ) {
1082 this->add_ignored_info_attrs(
true, (*irg)->path, (*ira)->name);
1092 void File::Handle_Var_Unsupported_Dtype()
1094 if (
false == this->
vars.empty()) {
1095 if (
true == this->unsupported_var_dtype) {
1096 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end();) {
1097 H5DataType temp_dtype = (*irv)->getType();
1098 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1100 irv = this->
vars.erase(irv);
1112 void File::Gen_Var_Unsupported_Dtype_Info()
1115 if (
false == this->
vars.empty()) {
1117 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1118 H5DataType temp_dtype = (*irv)->getType();
1121 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1122 ||(H5INT64 == temp_dtype) ||(H5UINT64 == temp_dtype)) {
1123 this->add_ignored_info_objs(
false, (*irv)->fullpath);
1132 void File::Handle_VarAttr_Unsupported_Dtype()
1134 if (
false == this->
vars.empty()) {
1135 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1136 if (
false == (*irv)->attrs.empty()) {
1137 if (
true == (*irv)->unsupported_attr_dtype) {
1138 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1139 H5DataType temp_dtype = (*ira)->getType();
1140 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
1142 ira = (*irv)->attrs.erase(ira);
1155 void File::Gen_VarAttr_Unsupported_Dtype_Info()
1158 if (
false == this->
vars.empty()) {
1159 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1160 if (
false == (*irv)->attrs.empty()) {
1162 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1163 H5DataType temp_dtype = (*ira)->getType();
1166 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1167 || (temp_dtype==H5INT64) || (temp_dtype == H5UINT64)) {
1168 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1181 void File::Gen_DimScale_VarAttr_Unsupported_Dtype_Info()
1184 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1188 bool is_ignored = ignored_dimscale_ref_list((*irv));
1189 if (
false == (*irv)->attrs.empty()) {
1191 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1192 H5DataType temp_dtype = (*ira)->getType();
1194 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)
1195 || (temp_dtype == H5INT64) || (temp_dtype == H5UINT64)) {
1199 if ((
"DIMENSION_LIST" != (*ira)->name)
1200 && (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
1201 this->add_ignored_info_attrs(
false, (*irv)->fullpath, (*ira)->name);
1210 void File::Handle_GroupAttr_Unsupported_Dspace()
1215 if (
true == this->unsupported_attr_dspace) {
1216 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
1218 if ((*ira)->count == 0) {
1230 if (
false == this->
groups.empty()) {
1231 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1232 if (
false == (*irg)->attrs.empty()) {
1233 if (
true == (*irg)->unsupported_attr_dspace) {
1234 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();) {
1235 if ((*ira)->count == 0) {
1237 ira = (*irg)->attrs.erase(ira);
1250 void File::Handle_VarAttr_Unsupported_Dspace()
1253 if (
false == this->
vars.empty()) {
1254 if (
true == this->unsupported_var_attr_dspace) {
1255 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1256 if (
false == (*irv)->attrs.empty()) {
1257 if (
true == (*irv)->unsupported_attr_dspace) {
1258 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
1259 if (0 == (*ira)->count) {
1261 ira = (*irv)->attrs.erase(ira);
1279 if (
false == this->
vars.empty()) {
1280 if (
true == this->unsupported_var_dspace) {
1281 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end();) {
1282 if (
true == (*irv)->unsupported_dspace) {
1284 irv = this->
vars.erase(irv);
1294 if (
true == include_attr) {
1295 Handle_GroupAttr_Unsupported_Dspace();
1296 Handle_VarAttr_Unsupported_Dspace();
1301 void File::Gen_Unsupported_Dspace_Info()
1309 if (
false == this->
vars.empty()) {
1310 if (
true == this->unsupported_var_dspace) {
1311 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1312 if (
true == (*irv)->unsupported_dspace) {
1313 this->add_ignored_info_objs(
true, (*irv)->fullpath);
1325 if (
true == this->check_ignored &&
true == include_attr) {
1327 if (
true == HDF5RequestHandler::get_drop_long_string()) {
1331 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1332 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1333 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1334 this->add_ignored_droplongstr_hdr();
1335 this->add_ignored_grp_longstr_info(
"/", (*ira)->name);
1340 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1341 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1342 if (H5FSTRING == (*ira)->dtype || H5VSTRING == (*ira)->dtype) {
1343 if ((*ira)->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
1344 this->add_ignored_droplongstr_hdr();
1345 this->add_ignored_grp_longstr_info((*irg)->path, (*ira)->name);
1351 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1352 if (
true == Check_DropLongStr((*irv), NULL)) {
1353 this->add_ignored_droplongstr_hdr();
1354 this->add_ignored_var_longstr_info((*irv), NULL);
1358 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1359 if (
true == Check_DropLongStr((*irv), (*ira))) {
1360 this->add_ignored_droplongstr_hdr();
1361 this->add_ignored_var_longstr_info((*irv), (*ira));
1375 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1376 (*irv)->newname = get_CF_string((*irv)->newname);
1378 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1379 (*ird)->newname = get_CF_string((*ird)->newname);
1383 if (
true == include_attr) {
1385 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
1386 (*ira)->newname = get_CF_string((*ira)->newname);
1389 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1390 (*irg)->newname = get_CF_string((*irg)->newname);
1391 for (vector<Attribute *>::iterator ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end(); ++ira) {
1392 (*ira)->newname = get_CF_string((*ira)->newname);
1396 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1397 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1398 (*ira)->newname = get_CF_string((*ira)->newname);
1405 void File::Handle_Var_NameClashing(set<string>&objnameset)
1408 Handle_General_NameClashing(objnameset, this->
vars);
1412 void File::Handle_Group_NameClashing(set<string> &objnameset)
1415 pair<set<string>::iterator,
bool> setret;
1425 setret = objnameset.insert(FILE_ATTR_TABLE_NAME);
1426 if (
false == setret.second) {
1428 int clash_index = 1;
1429 string fa_clash_name = FILE_ATTR_TABLE_NAME;
1430 HDF5CFUtil::gen_unique_name(fa_clash_name, objnameset, clash_index);
1431 FILE_ATTR_TABLE_NAME = fa_clash_name;
1435 Handle_General_NameClashing(objnameset, this->
groups);
1440 void File::Handle_Obj_AttrNameClashing()
1451 set<string> objnameset;
1454 Handle_General_NameClashing(objnameset, this->
root_attrs);
1457 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
1459 Handle_General_NameClashing(objnameset, (*irg)->attrs);
1463 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1465 Handle_General_NameClashing(objnameset, (*irv)->attrs);
1471 template<
class T>
void File::Handle_General_NameClashing(set<string>&objnameset, vector<T*>& objvec)
1475 pair<set<string>::iterator,
bool> setret;
1476 set<string>::iterator iss;
1478 vector<string> clashnamelist;
1479 vector<string>::iterator ivs;
1481 map<int, int> cl_to_ol;
1486 typename vector<T*>::iterator irv;
1488 for (irv = objvec.begin(); irv != objvec.end(); ++irv) {
1489 setret = objnameset.insert((*irv)->newname);
1490 if (
false == setret.second) {
1491 clashnamelist.insert(clashnamelist.end(), (*irv)->newname);
1492 cl_to_ol[cl_index] = ol_index;
1500 for (ivs = clashnamelist.begin(); ivs != clashnamelist.end(); ivs++) {
1501 int clash_index = 1;
1502 string temp_clashname = *ivs +
'_';
1503 HDF5CFUtil::gen_unique_name(temp_clashname, objnameset, clash_index);
1504 *ivs = temp_clashname;
1508 for (
unsigned int i = 0; i < clashnamelist.size(); i++)
1509 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
1514 void File::Handle_GeneralObj_NameClashing(
bool include_attr, set<string>& objnameset)
1517 Handle_Var_NameClashing(objnameset);
1518 if (
true == include_attr) {
1519 Handle_Group_NameClashing(objnameset);
1520 Handle_Obj_AttrNameClashing();
1525 string File::get_CF_string(
string s)
1528 if (
"" == s)
return s;
1529 string insertString(1,
'_');
1532 if (
true == isdigit(s[0])) s.insert(0, insertString);
1534 for (
unsigned int i = 0; i < s.length(); i++)
1535 if ((
false == isalnum(s[i])) && (s[i] !=
'_')) s[i] =
'_';
1542 void File::Insert_One_NameSizeMap_Element(
string name, hsize_t size,
bool unlimited)
1544 pair<map<string, hsize_t>::iterator,
bool> mapret;
1545 mapret = dimname_to_dimsize.insert(pair<string, hsize_t>(name, size));
1546 if (
false == mapret.second)
1547 throw4(
"The dimension name ", name,
" should map to ", size);
1549 pair<map<string, bool>::iterator,
bool> mapret2;
1550 mapret2 = dimname_to_unlimited.insert(pair<string, bool>(name, unlimited));
1551 if (
false == mapret2.second)
1552 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1557 void File::Insert_One_NameSizeMap_Element2(map<string, hsize_t>& name_to_size, map<string, bool>& name_to_unlimited,
1558 string name, hsize_t size,
bool unlimited)
1560 pair<map<string, hsize_t>::iterator,
bool> mapret;
1561 mapret = name_to_size.insert(pair<string, hsize_t>(name, size));
1562 if (
false == mapret.second)
1563 throw4(
"The dimension name ", name,
" should map to ", size);
1565 pair<map<string, bool>::iterator,
bool> mapret2;
1566 mapret2 = name_to_unlimited.insert(pair<string, bool>(name, unlimited));
1567 if (
false == mapret2.second)
1568 throw3(
"The dimension name ", name,
" unlimited dimension info. should be provided.");
1585 void File::Add_One_FakeDim_Name(
Dimension *dim)
1588 stringstream sfakedimindex;
1589 string fakedimstr =
"FakeDim";
1590 pair<set<string>::iterator,
bool> setret;
1591 map<hsize_t, string>::iterator im;
1592 pair<map<hsize_t, string>::iterator,
bool> mapret;
1594 sfakedimindex << addeddimindex;
1595 string added_dimname = fakedimstr + sfakedimindex.str();
1599 if (
false == mapret.second) {
1601 dim->newname = dim->name;
1608 setret = dimnamelist.insert(added_dimname);
1609 if (
false == setret.second) {
1610 int clash_index = 1;
1611 string temp_clashname = added_dimname +
'_';
1612 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1613 dim->name = temp_clashname;
1614 dim->newname = dim->name;
1615 setret = dimnamelist.insert(dim->name);
1616 if (
false == setret.second)
1617 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1623 if (
false == mapret.second)
1624 throw4(
"The dimension size ", dim->size,
" should map to ", dim->name);
1628 dim->name = added_dimname;
1629 dim->newname = dim->name;
1630 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1638 void File::Adjust_Duplicate_FakeDim_Name(
Dimension * dim)
1646 stringstream sfakedimindex;
1647 pair<set<string>::iterator,
bool> setret;
1650 sfakedimindex << addeddimindex;
1651 string added_dimname =
"FakeDim" + sfakedimindex.str();
1652 setret = dimnamelist.insert(added_dimname);
1653 if (
false == setret.second) {
1654 int clash_index = 1;
1655 string temp_clashname = added_dimname +
'_';
1656 HDF5CFUtil::gen_unique_name(temp_clashname, dimnamelist, clash_index);
1657 dim->name = temp_clashname;
1658 dim->newname = dim->name;
1659 setret = dimnamelist.insert(dim->name);
1660 if (
false == setret.second)
1661 throw2(
"Fail to insert the unique dimsizede name ", dim->name);
1663 dim->name = added_dimname;
1664 dim->newname = dim->name;
1665 Insert_One_NameSizeMap_Element(dim->name, dim->size, dim->unlimited_dim);
1673 void File::Replace_Dim_Name_All(
const string orig_dim_name,
const string new_dim_name) {
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)->name == orig_dim_name) {
1681 (*ird)->name = new_dim_name;
1682 (*ird)->newname = new_dim_name;
1691 void File::Use_Dim_Name_With_Size_All(
const string dim_name,
const size_t dim_size) {
1694 for (vector<Var *>::iterator irv = this->
vars.begin();
1695 irv != this->vars.end(); ++irv) {
1696 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1697 ird != (*irv)->dims.end(); ++ird) {
1698 if((*ird)->size == orig_dim_name) {
1699 (*ird)->name = new_dim_name;
1700 (*ird)->newname = new_dim_name;
1710 void File::Add_Str_Attr(
Attribute* attr,
const string &attrname,
const string& strvalue)
1713 attr->name = attrname;
1714 attr->newname = attr->name;
1715 attr->dtype = H5FSTRING;
1717 attr->fstrsize = strvalue.size();
1718 attr->strsize.resize(1);
1719 attr->strsize[0] = attr->fstrsize;
1720 attr->value.resize(strvalue.size());
1721 copy(strvalue.begin(), strvalue.end(), attr->value.begin());
1726 File:: Var_Has_Attr(
Var*var,
const string &attrname) {
1728 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end(); ++ira) {
1732 if((*ira)->name == attrname || (*ira)->newname == attrname) {
1741 string File::Retrieve_Str_Attr_Value(
Attribute *attr,
const string var_path)
1744 if (attr != NULL && var_path !=
"") {
1745 Retrieve_H5_Attr_Value(attr, var_path);
1746 string orig_attr_value(attr->value.begin(), attr->value.end());
1747 return orig_attr_value;
1754 bool File::Is_Str_Attr(
Attribute* attr,
string varfullpath,
const string &attrname,
const string& strvalue)
1756 bool ret_value =
false;
1757 if (attrname == get_CF_string(attr->newname)) {
1758 Retrieve_H5_Attr_Value(attr, varfullpath);
1759 string attr_value(attr->value.begin(), attr->value.end());
1760 if (attr_value == strvalue) ret_value =
true;
1766 bool File::has_latlon_cf_units(
Attribute *attr,
const string &varfullpath,
bool is_lat)
1768 string attr_name =
"units";
1769 if (
true == is_lat) {
1770 string lat_unit_value =
"degrees_north";
1771 return Is_Str_Attr(attr, varfullpath, attr_name, lat_unit_value);
1774 string lon_unit_value =
"degrees_east";
1775 return Is_Str_Attr(attr, varfullpath, attr_name, lon_unit_value);
1780 void File::Add_One_Float_Attr(
Attribute* attr,
const string &attrname,
float float_value)
1782 attr->name = attrname;
1783 attr->newname = attr->name;
1784 attr->dtype = H5FLOAT32;
1786 attr->value.resize(
sizeof(
float));
1787 memcpy(&(attr->value[0]), (
void*) (&float_value),
sizeof(
float));
1792 void File::Change_Attr_One_Str_to_Others(
Attribute* attr,
Var*var)
1797 long int num_sli = 0;
1798 if (attr->dtype != H5FSTRING)
1799 throw2(
"Currently we only convert fixed-size string to other datatypes. ", attr->name);
1800 if (attr->count != 1)
1801 throw4(
"The fixed-size string count must be 1 and the current count is ", attr->count,
" for the attribute ",
1804 Retrieve_H5_Attr_Value(attr, var->fullpath);
1806 attr_value.resize(attr->value.size());
1807 copy(attr->value.begin(), attr->value.end(), attr_value.begin());
1809 switch (var->dtype) {
1812 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1813 if (num_sli < 0 || num_sli > UCHAR_MAX)
1814 throw5(
"Attribute type is unsigned char, the current attribute ", attr->name,
" has the value ", num_sli,
1815 ". It is overflowed. ");
1817 unsigned char num_suc = (
unsigned char) num_sli;
1818 attr->dtype = H5UCHAR;
1819 attr->value.resize(
sizeof(
unsigned char));
1820 memcpy(&(attr->value[0]), (
void*) (&num_suc),
sizeof(
unsigned char));
1826 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1827 if (num_sli < SCHAR_MIN || num_sli > SCHAR_MAX)
1828 throw5(
"Attribute type is signed char, the current attribute ", attr->name,
" has the value ", num_sli,
1829 ". It is overflowed. ");
1831 char num_sc = (char) num_sli;
1832 attr->dtype = H5CHAR;
1833 attr->value.resize(
sizeof(
char));
1834 memcpy(&(attr->value[0]), (
void*) (&num_sc),
sizeof(
char));
1840 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1841 if (num_sli < SHRT_MIN || num_sli > SHRT_MAX)
1842 throw5(
"Attribute type is 16-bit integer, the current attribute ", attr->name,
" has the value ", num_sli,
1843 ". It is overflowed. ");
1845 short num_ss = (short) num_sli;
1846 attr->dtype = H5INT16;
1847 attr->value.resize(
sizeof(
short));
1848 memcpy(&(attr->value[0]), (
void*) (&num_ss),
sizeof(
short));
1854 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1855 if (num_sli < 0 || num_sli > USHRT_MAX)
1856 throw5(
"Attribute type is unsigned 16-bit integer, the current attribute ", attr->name,
" has the value ",
1857 num_sli,
". It is overflowed. ");
1859 unsigned short num_uss = (
unsigned short) num_sli;
1860 attr->dtype = H5UINT16;
1861 attr->value.resize(
sizeof(
unsigned short));
1862 memcpy(&(attr->value[0]), (
void*) (&num_uss),
sizeof(
unsigned short));
1867 num_sli = strtol(&(attr->value[0]), &pEnd, 10);
1873 attr->dtype = H5INT32;
1874 attr->value.resize(
sizeof(
long int));
1875 memcpy(&(attr->value[0]), (
void*) (&num_sli),
sizeof(
long int));
1880 unsigned long int num_suli = strtoul(&(attr->value[0]), &pEnd, 10);
1882 attr->dtype = H5UINT32;
1883 attr->value.resize(
sizeof(
unsigned long int));
1884 memcpy(&(attr->value[0]), (
void*) (&num_suli),
sizeof(
unsigned long int));
1888 float num_sf = strtof(&(attr->value[0]), NULL);
1890 attr->dtype = H5FLOAT32;
1891 attr->value.resize(
sizeof(
float));
1892 memcpy(&(attr->value[0]), (
void*) (&num_sf),
sizeof(
float));
1896 double num_sd = strtod(&(attr->value[0]), NULL);
1898 attr->dtype = H5FLOAT64;
1899 attr->value.resize(
sizeof(
double));
1900 memcpy(&(attr->value[0]), (
void*) (&num_sd),
sizeof(
double));
1905 throw4(
"Unsupported HDF5 datatype that the string is converted to for the attribute ", attr->name,
1906 " of the variable ", var->fullpath);
1912 void File::Replace_Var_Str_Attr(
Var* var,
const string &attr_name,
const string& strvalue)
1915 bool rep_attr =
true;
1916 bool rem_attr =
false;
1917 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1918 if ((*ira)->name == attr_name) {
1919 if (
true == Is_Str_Attr(*ira, var->fullpath, attr_name, strvalue))
1928 if (
true == rem_attr) {
1929 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
1930 if ((*ira)->name == attr_name) {
1932 var->attrs.erase(ira);
1939 if (
true == rep_attr) {
1941 Add_Str_Attr(attr, attr_name, strvalue);
1942 var->attrs.push_back(attr);
1947 bool File::Is_geolatlon(
const string & var_name,
bool is_lat)
1950 bool ret_value =
false;
1951 if (
true == is_lat) {
1952 string lat1 =
"lat";
1953 string lat2 =
"latitude";
1954 string lat3 =
"Latitude";
1956 if (var_name.compare(lat1) == 0 || var_name.compare(lat2) == 0 || var_name.compare(lat3) == 0) ret_value =
true;
1960 string lon1 =
"lon";
1961 string lon2 =
"longitude";
1962 string lon3 =
"Longitude";
1963 if (var_name.compare(lon1) == 0 || var_name.compare(lon2) == 0 || var_name.compare(lon3) == 0) ret_value =
true;
1973 if (
false == add_path)
return;
1976 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1978 const string varname = (*irv)->name;
1979 const string attrname =
"origname";
1980 Add_Str_Attr(attr, attrname, varname);
1981 (*irv)->attrs.push_back(attr);
1984 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1988 if((*irv)->zero_storage_size==
false
1989 || HDF5RequestHandler::get_no_zero_size_fullnameattr() ==
false) {
1991 const string varname = (*irv)->fullpath;
1992 const string attrname =
"fullnamepath";
1993 Add_Str_Attr(attr, attrname, varname);
1994 (*irv)->attrs.push_back(attr);
1999 for (vector<Group *>::iterator irg = this->
groups.begin(); irg != this->groups.end(); ++irg) {
2001 if (
false == (*irg)->attrs.empty()) {
2004 const string varname = (*irg)->path;
2005 const string attrname =
"fullnamepath";
2006 Add_Str_Attr(attr, attrname, varname);
2007 (*irg)->attrs.push_back(attr);
2016 void File::Replace_Var_Info(
Var *src,
Var *target)
2020 for_each (target->dims.begin (), target->dims.end (),
2022 for_each (target->attrs.begin (), target->attrs.end (),
2026 target->newname = src->newname;
2027 target->name = src->name;
2028 target->fullpath = src->fullpath;
2029 target->rank = src->rank;
2030 target->dtype = src->dtype;
2031 target->unsupported_attr_dtype = src->unsupported_attr_dtype;
2032 target->unsupported_dspace = src->unsupported_dspace;
2034 for (vector<Attribute*>::iterator ira = target->attrs.begin();
2035 ira!=target->attrs.end(); ++ira) {
2037 target->attrs.erase(ira);
2041 for (vector<Dimension*>::iterator ird = target->dims.begin(); ird != target->dims.end();) {
2043 ird = target->dims.erase(ird);
2048 for (vector<Attribute*>::iterator ira = src->attrs.begin();
2049 ira!=src->attrs.end(); ++ira) {
2051 attr->name = (*ira)->name;
2052 attr->newname = (*ira)->newname;
2053 attr->dtype =(*ira)->dtype;
2054 attr->count =(*ira)->count;
2055 attr->strsize = (*ira)->strsize;
2056 attr->fstrsize = (*ira)->fstrsize;
2057 attr->value =(*ira)->value;
2058 target->attrs.push_back(attr);
2062 for (vector<Dimension*>::iterator ird = src->dims.begin(); ird != src->dims.end(); ++ird) {
2064 dim->name = (*ird)->name;
2065 dim->newname = (*ird)->newname;
2066 target->dims.push_back(dim);
2072 void File::Replace_Var_Attrs(
Var *src,
Var *target)
2076 for_each (target->dims.begin (), target->dims.end (),
2078 for_each (target->attrs.begin (), target->attrs.end (),
2082 for (vector<Attribute*>::iterator ira = target->attrs.begin(); ira != target->attrs.end();) {
2084 ira = target->attrs.erase(ira);
2086 for (vector<Attribute*>::iterator ira = src->attrs.begin(); ira != src->attrs.end(); ++ira) {
2088 attr->name = (*ira)->name;
2089 attr->newname = (*ira)->newname;
2090 attr->dtype = (*ira)->dtype;
2091 attr->count = (*ira)->count;
2092 attr->strsize = (*ira)->strsize;
2093 attr->fstrsize = (*ira)->fstrsize;
2094 attr->value = (*ira)->value;
2095 target->attrs.push_back(attr);
2103 bool File::is_var_under_group(
const string &varname,
const string &grpname,
const int var_rank,
2104 vector<size_t> & var_size)
2107 bool ret_value =
false;
2108 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2110 if ((*irv)->rank == var_rank) {
2111 if ((*irv)->name == varname) {
2114 string var_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
2117 if (grpname == var_path) {
2119 for (
int i = 0; i < var_rank; i++)
2120 var_size[i] = (*irv)->getDimensions()[i]->size;
2133 bool ret_value =
false;
2134 for (vector<Var *>::iterator irv = this->
vars.begin();
2135 irv != this->vars.end(); ++irv) {
2136 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2137 ira != (*irv)->attrs.end(); ++ira) {
2138 if((*ira)->name ==
"grid_mapping") {
2143 if(
true == ret_value)
2153 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2155 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
2156 if((*ira)->name ==
"grid_mapping") {
2157 Retrieve_H5_Attr_Value(*ira, (*irv)->fullpath);
2158 attr_value.resize((*ira)->value.size());
2159 copy((*ira)->value.begin(), (*ira)->value.end(), attr_value.begin());
2164 if(attr_value.find(
'/') ==string::npos){
2165 string new_name = Check_Grid_Mapping_VarName(attr_value,(*irv)->fullpath);
2167 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2171 string new_name = Check_Grid_Mapping_FullPath(attr_value);
2174 Replace_Var_Str_Attr((*irv),
"grid_mapping",new_name);
2180 string File::Check_Grid_Mapping_VarName(
const string & a_value,
const string & var_fpath) {
2182 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var_fpath);
2183 string gmap_new_name;
2184 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2185 if((*irv)->name == a_value){
2186 if(var_path == HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) {
2187 gmap_new_name = (*irv)->newname;
2192 return gmap_new_name;
2196 string File::Check_Grid_Mapping_FullPath(
const string & a_value) {
2198 string gmap_new_name;
2199 for (vector<Var *>::iterator irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2200 if((*irv)->fullpath == a_value){
2201 gmap_new_name = (*irv)->newname;
2206 return gmap_new_name;
2209 void File::remove_netCDF_internal_attributes(
bool include_attr) {
2211 if(
true == include_attr) {
2212 for (vector<Var *>::iterator irv = this->
vars.begin();
2213 irv != this->vars.end(); ++irv) {
2214 bool var_has_dimscale =
false;
2216 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2217 ira != (*irv)->attrs.end();) {
2218 if((*ira)->name ==
"CLASS") {
2219 string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2223 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2225 ira = (*irv)->attrs.erase(ira);
2226 var_has_dimscale =
true;
2239 else if((*ira)->name ==
"NAME") {
2240 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
2241 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
2243 ira =(*irv)->attrs.erase(ira);
2246 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
2247 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
2249 ira =(*irv)->attrs.erase(ira);
2258 else if((*ira)->name ==
"_Netcdf4Dimid") {
2260 ira =(*irv)->attrs.erase(ira);
2262 else if((*ira)->name ==
"_Netcdf4Coordinates") {
2264 ira =(*irv)->attrs.erase(ira);
2267 else if((*ira)->name ==
"_nc3_strict") {
2269 ira =(*irv)->attrs.erase(ira);
2277 if(
true == var_has_dimscale) {
2278 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
2279 ira != (*irv)->attrs.end();++ira) {
2280 if((*ira)->name ==
"NAME") {
2282 ira =(*irv)->attrs.erase(ira);
2292 void File::add_ignored_info_page_header()
2295 " \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";
2299 void File::add_ignored_info_obj_header()
2302 ignored_msg +=
" Some HDF5 objects or the object information are ignored when mapping to DAP2 by the HDF5 OPeNDAP";
2303 ignored_msg +=
" handler due to the restrictions of DAP2, CF conventions or CF tools.";
2304 ignored_msg +=
" Please use HDF5 tools(h5dump or HDFView) to check carefully and make sure that these objects";
2306 " are OK to ignore for your service. For questions or requests to find a way to handle the ignored objects, please";
2307 ignored_msg +=
" contact the HDF5 OPeNDAP handler developer or send an email to help@hdfgroup.org.\n";
2309 ignored_msg +=
" \n In general, ignored HDF5 objects include HDF5 soft links, external links and named datatype.\n";
2311 " \n The HDF5 datasets(variables in the CF term) and attributes that have the following datatypes are ignored: \n";
2313 " Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2314 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2317 " \n The HDF5 datasets(variables in the CF term) and attributes associated with the following dimensions are ignored: \n";
2318 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2319 ignored_msg +=
" 2) attributes that have any zero size dimensions(not reported due to extreme rarity and non-trivial coding)\n\n";
2324 void File::add_ignored_info_links_header()
2327 if (
false == this->have_ignored) {
2328 add_ignored_info_obj_header();
2329 have_ignored =
true;
2332 string lh_msg =
"******WARNING******\n";
2333 lh_msg +=
"IGNORED soft links or external links are: ";
2334 if (ignored_msg.rfind(lh_msg) == string::npos) ignored_msg += lh_msg +
"\n";
2341 File:: add_ignored_info_obj_dtype_header() {
2344 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported datatypes. \n";
2345 ignored_msg +=
" In general, the unsupported datatypes include: \n";
2346 ignored_msg +=
" Signed and unsigned 64-bit integers, HDF5 compound, HDF5 variable length(excluding variable length string),";
2347 ignored_msg +=
" HDF5 reference, HDF5 enum, HDF5 opaque , HDF5 bitfield, HDF5 Array and HDF5 Time datatypes.\n";
2352 File:: add_ignored_info_obj_dspace_header() {
2355 ignored_msg +=
" \n Variables and attributes ignored due to the unsupported dimensions. \n";
2356 ignored_msg +=
" In general, the unsupported dimensions include: \n";
2357 ignored_msg +=
" 1) variables that have HDF5 NULL dataspace(H5S_NULL)(rarely occurred)\n";
2358 ignored_msg +=
" 2) variables that have any zero size dimensions\n";
2364 void File::add_ignored_info_links(
const string & link_path)
2366 if (ignored_msg.find(
"Link paths: ") == string::npos)
2367 ignored_msg +=
" Link paths: " + link_path;
2369 ignored_msg +=
" " + link_path;
2373 void File::add_ignored_info_namedtypes(
const string& grp_name,
const string& named_dtype_name)
2376 if (
false == this->have_ignored) {
2377 add_ignored_info_obj_header();
2378 have_ignored =
true;
2381 string ignored_HDF5_named_dtype_hdr =
"\n******WARNING******";
2382 ignored_HDF5_named_dtype_hdr +=
"\n IGNORED HDF5 named datatype objects:\n";
2383 string ignored_HDF5_named_dtype_msg =
" Group name: " + grp_name +
" HDF5 named datatype name: " + named_dtype_name.substr(0,named_dtype_name.size()-1)
2385 if (ignored_msg.find(ignored_HDF5_named_dtype_hdr) == string::npos)
2386 ignored_msg += ignored_HDF5_named_dtype_hdr + ignored_HDF5_named_dtype_msg;
2388 ignored_msg += ignored_HDF5_named_dtype_msg;
2394 void File::add_ignored_info_attrs(
bool is_grp,
const string & obj_path,
const string & attr_name)
2397 if (
false == this->have_ignored) {
2398 add_ignored_info_obj_header();
2399 have_ignored =
true;
2403 string ignored_warning_str =
"\n******WARNING******";
2404 string ignored_HDF5_grp_hdr = ignored_warning_str +
"\n Ignored attributes under root and groups:\n";
2405 string ignored_HDF5_grp_msg =
" Group path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2406 string ignored_HDF5_var_hdr = ignored_warning_str +
"\n Ignored attributes for variables:\n";
2407 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
" Attribute names: " + attr_name +
"\n";
2410 if (
true == is_grp) {
2411 if (ignored_msg.find(ignored_HDF5_grp_hdr) == string::npos)
2412 ignored_msg += ignored_HDF5_grp_hdr + ignored_HDF5_grp_msg;
2414 ignored_msg += ignored_HDF5_grp_msg;
2417 if (ignored_msg.find(ignored_HDF5_var_hdr) == string::npos)
2418 ignored_msg += ignored_HDF5_var_hdr + ignored_HDF5_var_msg;
2420 ignored_msg += ignored_HDF5_var_msg;
2427 void File::add_ignored_info_objs(
bool is_dim_related,
const string & obj_path)
2430 if (
false == this->have_ignored) {
2431 add_ignored_info_obj_header();
2432 have_ignored =
true;
2435 string ignored_warning_str =
"\n******WARNING******";
2436 string ignored_HDF5_dtype_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported datatypes:\n";
2437 string ignored_HDF5_dspace_var_hdr = ignored_warning_str +
"\n IGNORED variables due to unsupported dimensions:\n";
2438 string ignored_HDF5_var_msg =
" Variable path: " + obj_path +
"\n";
2440 if (
true == is_dim_related) {
2441 if (ignored_msg.find(ignored_HDF5_dspace_var_hdr) == string::npos)
2442 ignored_msg += ignored_HDF5_dspace_var_hdr + ignored_HDF5_var_msg;
2444 ignored_msg += ignored_HDF5_var_msg;
2448 if (ignored_msg.find(ignored_HDF5_dtype_var_hdr) == string::npos)
2449 ignored_msg += ignored_HDF5_dtype_var_hdr + ignored_HDF5_var_msg;
2451 ignored_msg += ignored_HDF5_var_msg;
2457 void File::add_no_ignored_info()
2460 ignored_msg +=
"There are no ignored HDF5 objects or attributes.";
2466 bool File::ignored_dimscale_ref_list(
Var *var)
2469 bool ignored_dimscale =
true;
2472 bool has_dimscale =
false;
2473 bool has_reference_list =
false;
2474 for (vector<Attribute *>::iterator ira = var->attrs.begin(); ira != var->attrs.end(); ira++) {
2475 if ((*ira)->name ==
"REFERENCE_LIST" &&
false == HDF5CFUtil::cf_strict_support_type((*ira)->getType(),_is_dap4))
2476 has_reference_list =
true;
2477 if ((*ira)->name ==
"CLASS") {
2478 Retrieve_H5_Attr_Value(*ira, var->fullpath);
2480 class_value.resize((*ira)->value.size());
2481 copy((*ira)->value.begin(), (*ira)->value.end(), class_value.begin());
2485 if (0 == class_value.compare(0, 15,
"DIMENSION_SCALE")) {
2486 has_dimscale =
true;
2490 if (
true == has_dimscale &&
true == has_reference_list) {
2491 ignored_dimscale =
false;
2497 return ignored_dimscale;
2501 bool File::Check_DropLongStr(
Var *var,
Attribute * attr)
2504 bool drop_longstr =
false;
2506 if (H5FSTRING == var->dtype || H5VSTRING == var->dtype) {
2508 drop_longstr = Check_VarDropLongStr(var->fullpath, var->dims, var->dtype);
2511 throw1(
"Check_VarDropLongStr fails ");
2518 if (H5FSTRING == attr->dtype || H5VSTRING == attr->dtype) {
2519 if (attr->getBufSize() > NC_JAVA_STR_SIZE_LIMIT) {
2520 drop_longstr =
true;
2526 return drop_longstr;
2532 bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
const
2536 bool drop_longstr =
false;
2538 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2540 throw2(
"Cannot open the dataset ", varpath);
2542 hid_t dtype_id = -1;
2543 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2545 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2548 size_t ty_size = H5Tget_size(dtype_id);
2552 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2555 if (H5FSTRING == dtype) {
2556 if (ty_size > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2558 else if (H5VSTRING == dtype) {
2560 unsigned long long total_elms = 1;
2561 if (dims.size() != 0) {
2562 for (
unsigned int i = 0; i < dims.size(); i++)
2563 total_elms = total_elms * ((dims[i])->size);
2565 vector<char> strval;
2566 strval.resize(total_elms * ty_size);
2567 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) &strval[0]);
2571 throw2(
"Cannot read the data of the dataset ", varpath);
2574 vector<string> finstrval;
2575 finstrval.resize(total_elms);
2576 char*temp_bp = &strval[0];
2577 char*onestring = NULL;
2578 for (
unsigned long long i = 0; i < total_elms; i++) {
2579 onestring = *(
char**) temp_bp;
2580 if (onestring != NULL) {
2581 finstrval[i] = string(onestring);
2582 if(finstrval[i].size()>NC_JAVA_STR_SIZE_LIMIT) {
2583 drop_longstr =
true;
2590 if (
false == strval.empty()) {
2591 herr_t ret_vlen_claim;
2592 hid_t dspace_id = H5Dget_space(dset_id);
2593 if (dspace_id < 0) {
2596 throw2(
"Cannot obtain the dataspace id.", varpath);
2598 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) &strval[0]);
2599 if (ret_vlen_claim < 0) {
2601 H5Sclose(dspace_id);
2603 throw2(
"Cannot reclaim the vlen space ", varpath);
2605 if (H5Sclose(dspace_id) < 0) {
2608 throw2(
"Cannot close the HDF5 data space.", varpath);
2612 if (H5Tclose(dtype_id) < 0) {
2614 throw2(
"Cannot close the HDF5 data type.", varpath);
2616 if (H5Dclose(dset_id) < 0)
2617 throw2(
"Cannot close the HDF5 data type.", varpath);
2619 return drop_longstr;
2622 bool File::Check_VarDropLongStr(
const string & varpath,
const vector<Dimension *>& dims, H5DataType dtype)
2626 bool drop_longstr =
false;
2628 unsigned long long total_elms = 1;
2629 if (dims.size() != 0) {
2630 for (
unsigned int i = 0; i < dims.size(); i++)
2631 total_elms = total_elms * ((dims[i])->size);
2634 if (total_elms > NC_JAVA_STR_SIZE_LIMIT)
2635 drop_longstr =
true;
2639 hid_t dset_id = H5Dopen2(this->fileid, varpath.c_str(), H5P_DEFAULT);
2641 throw2(
"Cannot open the dataset ", varpath);
2643 hid_t dtype_id = -1;
2644 if ((dtype_id = H5Dget_type(dset_id)) < 0) {
2646 throw2(
"Cannot obtain the datatype of the dataset ", varpath);
2649 size_t ty_size = H5Tget_size(dtype_id);
2653 throw2(
"Cannot obtain the datatype size of the dataset ", varpath);
2656 if (H5FSTRING == dtype) {
2657 if ((ty_size * total_elms) > NC_JAVA_STR_SIZE_LIMIT) drop_longstr =
true;
2659 else if (H5VSTRING == dtype) {
2661 vector<char> strval;
2662 strval.resize(total_elms * ty_size);
2663 hid_t read_ret = H5Dread(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, (
void*) &strval[0]);
2667 throw2(
"Cannot read the data of the dataset ", varpath);
2670 vector<string> finstrval;
2671 finstrval.resize(total_elms);
2672 char*temp_bp = &strval[0];
2673 char*onestring = NULL;
2674 for (
unsigned long long i = 0; i < total_elms; i++) {
2675 onestring = *(
char**) temp_bp;
2676 if (onestring != NULL)
2677 finstrval[i] = string(onestring);
2684 if (
false == strval.empty()) {
2685 herr_t ret_vlen_claim;
2686 hid_t dspace_id = H5Dget_space(dset_id);
2687 if (dspace_id < 0) {
2690 throw2(
"Cannot obtain the dataspace id.", varpath);
2692 ret_vlen_claim = H5Dvlen_reclaim(dtype_id, dspace_id, H5P_DEFAULT, (
void*) &strval[0]);
2693 if (ret_vlen_claim < 0) {
2695 H5Sclose(dspace_id);
2697 throw2(
"Cannot reclaim the vlen space ", varpath);
2699 if (H5Sclose(dspace_id) < 0) {
2702 throw2(
"Cannot close the HDF5 data space.", varpath);
2705 unsigned long long total_str_size = 0;
2706 for (
unsigned long long i = 0; i < total_elms; i++) {
2707 total_str_size += finstrval[i].size();
2708 if (total_str_size > NC_JAVA_STR_SIZE_LIMIT) {
2709 drop_longstr =
true;
2714 if (H5Tclose(dtype_id) < 0) {
2716 throw2(
"Cannot close the HDF5 data type.", varpath);
2718 if (H5Dclose(dset_id) < 0)
2719 throw2(
"Cannot close the HDF5 data type.", varpath);
2721 return drop_longstr;
2727 void File::add_ignored_grp_longstr_info(
const string& grp_path,
const string & attr_name)
2730 ignored_msg +=
"The HDF5 group: " + grp_path +
" has an empty-set string attribute: " + attr_name +
"\n";
2736 void File::add_ignored_var_longstr_info(
Var *var,
Attribute *attr)
2740 ignored_msg +=
"String variable: " + var->fullpath +
" value is set to empty.\n";
2742 ignored_msg +=
"The variable: " + var->fullpath +
" has an empty-set string attribute: " + attr->name +
"\n";
2749 void File::add_ignored_droplongstr_hdr()
2752 if (
false == this->have_ignored) this->have_ignored =
true;
2753 string hdr =
"\n\n The values of the following string variables ";
2754 hdr +=
" are set to empty because at least one string size in this variable exceeds netCDF Java string limit(32767 bytes).\n";
2755 hdr +=
"To obtain the values, change the BES key H5.EnableDropLongString=true at the handler BES";
2756 hdr +=
" configuration file(h5.conf)\nto H5.EnableDropLongString=false.\n\n";
2758 if (ignored_msg.rfind(hdr) == string::npos) ignored_msg += hdr;
2763 void File::release_standalone_var_vector(vector<Var*>&temp_vars)
2766 for (vector<Var *>::iterator i = temp_vars.begin(); i != temp_vars.end();) {
2768 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)