33 #include <InternalErr.h>
43 H5GCFProduct check_product(hid_t file_id) {
46 H5GCFProduct product_type = General_Product;
49 if ((root_id = H5Gopen(file_id,ROOT_NAME,H5P_DEFAULT))<0){
50 string msg =
"cannot open the HDF5 root group ";
51 msg += string(ROOT_NAME);
52 throw InternalErr(__FILE__, __LINE__, msg);
65 if (
true == check_gpm_l1(root_id)){
66 product_type = GPM_L1;
70 else if (
true == check_gpms_l3(root_id)){
71 product_type = GPMS_L3;
74 else if (
true == check_gpmm_l3(root_id)) {
75 product_type = GPMM_L3;
79 else if (
true == check_measure_seawifs(root_id,s_level)) {
80 if (2 == s_level) product_type = Mea_SeaWiFS_L2;
81 if (3 == s_level) product_type = Mea_SeaWiFS_L3;
84 else if (
true == check_aquarius(root_id,a_level)){
85 if (3 == a_level) product_type = Aqu_L3;
87 else if (
true == check_obpg(root_id,a_level)){
88 if (3 == a_level) product_type = OBPG_L3;
91 else if (
true == check_measure_ozone(root_id)) {
92 product_type = Mea_Ozone;
95 int osmapl2s_flag = 1;
96 if (
true == check_osmapl2s_acosl2s_oco2l1b(root_id,osmapl2s_flag))
97 product_type = OSMAPL2S;
99 if (General_Product == product_type) {
101 int acosl2s_oco2l1b_flag = 2;
102 if (
true == check_osmapl2s_acosl2s_oco2l1b(root_id,acosl2s_oco2l1b_flag))
103 product_type = ACOS_L2S_OR_OCO2_L1B;
113 bool check_gpm_l1(hid_t s_root_id) {
115 htri_t has_gpm_l1_attr1 = -1;
116 bool ret_flag =
false;
120 has_gpm_l1_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
122 if(has_gpm_l1_attr1 >0) {
127 if(H5Gget_info(s_root_id,&g_info) <0) {
129 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully");
132 nelms = g_info.nlinks;
137 for (
unsigned int i = 0; i<nelms; i++) {
141 size_t dummy_name_len = 1;
145 H5Lget_name_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
146 dummy_name_len, H5P_DEFAULT);
148 throw InternalErr(__FILE__,__LINE__,
"Error getting the size of the hdf5 object from the root group. ");
152 oname.resize((
size_t)oname_size+1);
154 if (H5Lget_name_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
155 (
size_t)(oname_size+1), H5P_DEFAULT) < 0)
156 throw InternalErr(__FILE__,__LINE__,
"Error getting the hdf5 object name from the root group. ");
160 if (H5Lget_info(s_root_id,&oname[0],&linfo,H5P_DEFAULT)<0)
161 throw InternalErr (__FILE__,__LINE__,
"HDF5 link name error from the root group. ");
164 if(H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type)
169 if(H5Oget_info_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE, (hsize_t)i,&soinfo,H5P_DEFAULT)<0)
170 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully. ");
172 H5O_type_t obj_type = soinfo.type;
175 if(obj_type == H5O_TYPE_GROUP) {
178 cgroup = H5Gopen(s_root_id,&oname[0],H5P_DEFAULT);
180 throw InternalErr(__FILE__,__LINE__,
"Cannot open the group.");
182 int num_attrs = soinfo.num_attrs;
185 for (
int j = 0; j < num_attrs; j++) {
188 if ((attrid = H5Aopen_by_idx(cgroup,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
189 throw InternalErr(__FILE__,__LINE__,
"Unable to open attribute by index " );
192 ssize_t name_size = H5Aget_name(attrid, 0, NULL);
194 throw InternalErr(__FILE__,__LINE__,
"Unable to obtain the size of the hdf5 attribute name " );
197 attr_name.resize(name_size+1);
200 if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0)
201 throw InternalErr(__FILE__,__LINE__,
"unable to obtain the hdf5 attribute name ");
203 string swathheader(GPM_SWATH_ATTR2_NAME);
204 if(attr_name.rfind(swathheader) !=string::npos) {
212 if(
true == ret_flag){
238 bool check_gpms_l3(hid_t s_root_id) {
240 htri_t has_gpm_l3_attr1 = -1;
241 bool ret_flag =
false;
244 has_gpm_l3_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
246 if(has_gpm_l3_attr1 >0) {
248 htri_t has_gpm_grid_group = -1;
250 has_gpm_grid_group = H5Lexists(s_root_id,GPM_GRID_GROUP_NAME1,H5P_DEFAULT);
252 hid_t s_group_id = -1;
253 if (has_gpm_grid_group >0){
256 if ((s_group_id = H5Gopen(s_root_id, GPM_GRID_GROUP_NAME1,H5P_DEFAULT))<0) {
257 string msg =
"Cannot open the HDF5 Group ";
258 msg += string(GPM_GRID_GROUP_NAME1);
260 throw InternalErr(__FILE__, __LINE__, msg);
265 if(H5Lexists(s_root_id,GPM_GRID_GROUP_NAME2,H5P_DEFAULT) >0) {
267 if ((s_group_id = H5Gopen(s_root_id, GPM_GRID_GROUP_NAME2,H5P_DEFAULT))<0) {
268 string msg =
"Cannot open the HDF5 Group ";
269 msg += string(GPM_GRID_GROUP_NAME2);
271 throw InternalErr(__FILE__, __LINE__, msg);
278 htri_t has_gpm_l3_attr2 = -1;
279 has_gpm_l3_attr2 = H5Aexists(s_group_id,GPM_ATTR2_NAME);
280 if (has_gpm_l3_attr2 >0)
283 H5Gclose(s_group_id);
294 bool check_gpmm_l3(hid_t s_root_id) {
296 htri_t has_gpm_l3_attr1 = -1;
297 bool ret_flag =
false;
301 has_gpm_l3_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
303 if(has_gpm_l3_attr1 >0) {
305 if(H5Lexists(s_root_id,GPM_GRID_MULTI_GROUP_NAME,H5P_DEFAULT) >0) {
306 hid_t cgroup_id = -1;
308 if ((cgroup_id = H5Gopen(s_root_id, GPM_GRID_MULTI_GROUP_NAME,H5P_DEFAULT))<0) {
309 string msg =
"Cannot open the HDF5 Group ";
310 msg += string(GPM_GRID_MULTI_GROUP_NAME);
312 throw InternalErr(__FILE__, __LINE__, msg);
318 if(H5Gget_info(cgroup_id,&g_info) <0) {
321 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully");
324 nelms = g_info.nlinks;
326 hid_t cgroup2_id = -1;
329 for (
unsigned int i = 0; i<nelms; i++) {
333 size_t dummy_name_len = 1;
337 H5Lget_name_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
338 dummy_name_len, H5P_DEFAULT);
340 throw InternalErr(__FILE__,__LINE__,
"Error getting the size of the hdf5 object from the grid group. ");
344 oname.resize((
size_t)oname_size+1);
346 if (H5Lget_name_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
347 (
size_t)(oname_size+1), H5P_DEFAULT) < 0)
348 throw InternalErr(__FILE__,__LINE__,
"Error getting the hdf5 object name from the root group. ");
352 if (H5Lget_info(cgroup_id,&oname[0],&linfo,H5P_DEFAULT)<0)
353 throw InternalErr (__FILE__,__LINE__,
"HDF5 link name error from the root group. ");
356 if(H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type)
361 if(H5Oget_info_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE, (hsize_t)i,&soinfo,H5P_DEFAULT)<0)
362 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully. ");
364 H5O_type_t obj_type = soinfo.type;
367 if(obj_type == H5O_TYPE_GROUP) {
370 cgroup2_id = H5Gopen(cgroup_id,&oname[0],H5P_DEFAULT);
372 throw InternalErr(__FILE__,__LINE__,
"Cannot open the group.");
374 htri_t has_gpm_l3_attr2;
375 has_gpm_l3_attr2 = H5Aexists(cgroup2_id,GPM_ATTR2_NAME);
376 if (has_gpm_l3_attr2 >0) {
378 H5Gclose(cgroup2_id);
383 int num_attrs = soinfo.num_attrs;
386 for (
int j = 0; j < num_attrs; j++) {
389 if ((attrid = H5Aopen_by_idx(cgroup2_id,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
390 throw InternalErr(__FILE__,__LINE__,
"Unable to open attribute by index " );
393 ssize_t name_size = H5Aget_name(attrid, 0, NULL);
395 throw InternalErr(__FILE__,__LINE__,
"Unable to obtain the size of the hdf5 attribute name " );
398 attr_name.resize(name_size+1);
401 if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0)
402 throw InternalErr(__FILE__,__LINE__,
"unable to obtain the hdf5 attribute name ");
404 string gridheader(GPM_ATTR2_NAME);
405 if(attr_name.find(gridheader) !=string::npos) {
416 H5Gclose(cgroup2_id);
426 H5Gclose(cgroup2_id);
437 bool check_measure_seawifs(hid_t s_root_id,
int & s_lflag) {
439 htri_t has_seawifs_attr1 = -1;
440 bool ret_flag =
false;
445 has_seawifs_attr1 = H5Aexists(s_root_id,SeaWiFS_ATTR1_NAME);
447 if (has_seawifs_attr1 >0) {
449 string attr1_value=
"";
450 obtain_gm_attr_value(s_root_id, SeaWiFS_ATTR1_NAME, attr1_value);
451 if (0 == attr1_value.compare(SeaWiFS_ATTR1_VALUE)) {
452 htri_t has_seawifs_attr2 = -1;
453 htri_t has_seawifs_attr3 = -1;
454 has_seawifs_attr2 = H5Aexists(s_root_id,SeaWiFS_ATTR2_NAME);
455 has_seawifs_attr3 = H5Aexists(s_root_id,SeaWiFS_ATTR3_NAME);
457 if ((has_seawifs_attr2 >0) && (has_seawifs_attr3 > 0)){
458 string attr2_value =
"";
459 string attr3_value =
"";
460 obtain_gm_attr_value(s_root_id,SeaWiFS_ATTR2_NAME, attr2_value);
461 obtain_gm_attr_value(s_root_id,SeaWiFS_ATTR3_NAME, attr3_value);
467 if (((0 == attr2_value.find(SeaWiFS_ATTR2_FPVALUE)) &&
468 (attr2_value.find(SeaWiFS_ATTR2_L2PVALUE)!=string::npos))
469 ||(0 == attr3_value.find(SeaWiFS_ATTR3_L2FPVALUE))) {
474 else if (((0 == attr2_value.find(SeaWiFS_ATTR2_FPVALUE)) &&
475 (attr2_value.find(SeaWiFS_ATTR2_L3PVALUE)!=string::npos))
476 ||(0 == attr3_value.find(SeaWiFS_ATTR3_L3FPVALUE))) {
482 else if ((0 == has_seawifs_attr2 ) || (0 == has_seawifs_attr3))
485 string msg =
"Fail to determine if the HDF5 attribute ";
486 msg += string(SeaWiFS_ATTR2_NAME);
487 msg +=
"or the HDF5 attribute ";
488 msg += string(SeaWiFS_ATTR3_NAME);
491 throw InternalErr(__FILE__, __LINE__, msg);
495 else if (0 == has_seawifs_attr1)
498 string msg =
"Fail to determine if the HDF5 attribute ";
499 msg += string(SeaWiFS_ATTR1_NAME);
502 throw InternalErr(__FILE__, __LINE__, msg);
508 bool check_measure_ozone(hid_t s_root_id) {
510 htri_t has_ozone_attr1 = -1;
511 bool ret_flag =
false;
516 has_ozone_attr1 = H5Aexists(s_root_id,Ozone_ATTR1_NAME);
518 if (has_ozone_attr1 >0) {
519 string attr1_value =
"";
520 obtain_gm_attr_value(s_root_id, Ozone_ATTR1_NAME, attr1_value);
521 if ((0 == attr1_value.compare(Ozone_ATTR1_VALUE1)) ||
522 (0 == attr1_value.compare(Ozone_ATTR1_VALUE2))) {
523 htri_t has_ozone_attr2 = -1;
524 has_ozone_attr2 = H5Aexists(s_root_id,Ozone_ATTR2_NAME);
525 if (has_ozone_attr2 >0) {
526 string attr2_value =
"";
527 obtain_gm_attr_value(s_root_id,Ozone_ATTR2_NAME, attr2_value);
528 if(0 == attr2_value.compare(Ozone_ATTR2_VALUE))
532 else if (0 == has_ozone_attr2)
535 string msg =
"Fail to determine if the HDF5 attribute ";
536 msg += string(Ozone_ATTR2_NAME);
539 throw InternalErr(__FILE__, __LINE__, msg);
543 else if (0 == has_ozone_attr1 )
546 string msg =
"Fail to determine if the HDF5 attribute ";
547 msg += string(Ozone_ATTR1_NAME);
550 throw InternalErr(__FILE__, __LINE__, msg);
559 bool check_aquarius(hid_t s_root_id,
int & s_level) {
561 htri_t has_aquarius_attr1 = -1;
562 bool ret_flag =
false;
567 has_aquarius_attr1 = H5Aexists(s_root_id,Aquarius_ATTR1_NAME);
568 if (has_aquarius_attr1 >0) {
569 string attr1_value =
"";
570 obtain_gm_attr_value(s_root_id, Aquarius_ATTR1_NAME, attr1_value);
571 if (0 == attr1_value.compare(Aquarius_ATTR1_VALUE)) {
572 htri_t has_aquarius_attr2 = -1;
573 has_aquarius_attr2 = H5Aexists(s_root_id,Aquarius_ATTR2_NAME);
574 if (has_aquarius_attr2 >0) {
575 string attr2_value =
"";
576 obtain_gm_attr_value(s_root_id,Aquarius_ATTR2_NAME, attr2_value);
579 if (attr2_value.find(Aquarius_ATTR2_PVALUE)!=string::npos){
586 else if (0 == has_aquarius_attr2)
589 string msg =
"Fail to determine if the HDF5 attribute ";
590 msg += string(Aquarius_ATTR2_NAME);
593 throw InternalErr(__FILE__, __LINE__, msg);
597 else if (0 == has_aquarius_attr1)
600 string msg =
"Fail to determine if the HDF5 attribute ";
601 msg += string(Aquarius_ATTR1_NAME);
604 throw InternalErr(__FILE__, __LINE__, msg);
612 bool check_obpg(hid_t s_root_id,
int & s_level) {
614 htri_t has_obpg_attr1 = -1;
615 bool ret_flag =
false;
620 has_obpg_attr1 = H5Aexists(s_root_id,Obpgl3_ATTR1_NAME);
621 if (has_obpg_attr1 >0) {
622 string attr1_value =
"";
623 obtain_gm_attr_value(s_root_id, Obpgl3_ATTR1_NAME, attr1_value);
624 htri_t has_obpg_attr2 = -1;
625 has_obpg_attr2 = H5Aexists(s_root_id,Obpgl3_ATTR2_NAME);
626 if (has_obpg_attr2 >0) {
627 string attr2_value =
"";
628 obtain_gm_attr_value(s_root_id,Obpgl3_ATTR2_NAME, attr2_value);
629 if ((0 == attr1_value.compare(Obpgl3_ATTR1_VALUE)) &&
630 (0 == attr2_value.compare(Obpgl3_ATTR2_VALUE))) {
637 else if (0 == has_obpg_attr2)
640 string msg =
"Fail to determine if the HDF5 attribute ";
641 msg += string(Obpgl3_ATTR2_NAME);
644 throw InternalErr(__FILE__, __LINE__, msg);
647 else if (0 == has_obpg_attr1)
650 string msg =
"Fail to determine if the HDF5 attribute ";
651 msg += string(Obpgl3_ATTR1_NAME);
654 throw InternalErr(__FILE__, __LINE__, msg);
659 bool check_osmapl2s_acosl2s_oco2l1b(hid_t s_root_id,
int which_pro) {
661 htri_t has_smac_group;
662 bool return_flag =
false;
663 has_smac_group = H5Lexists(s_root_id,SMAC2S_META_GROUP_NAME,H5P_DEFAULT);
665 if (has_smac_group >0){
666 hid_t s_group_id = -1;
669 if ((s_group_id = H5Gopen(s_root_id, SMAC2S_META_GROUP_NAME,H5P_DEFAULT))<0) {
670 string msg =
"Cannot open the HDF5 Group ";
671 msg += string(SMAC2S_META_GROUP_NAME);
673 throw InternalErr(__FILE__, __LINE__, msg);
677 if (1 == which_pro) {
679 htri_t has_osmapl2s_attr = -1;
681 has_osmapl2s_attr = H5Aexists(s_group_id,OSMAPL2S_ATTR_NAME);
682 if (has_osmapl2s_attr >0) {
683 string attr_value =
"";
684 obtain_gm_attr_value(s_group_id, OSMAPL2S_ATTR_NAME, attr_value);
685 if (attr_value.compare(OSMAPL2S_ATTR_VALUE) == 0)
689 H5Gclose(s_group_id);
691 else if (0 == has_osmapl2s_attr) {
692 H5Gclose(s_group_id);
696 string msg =
"Fail to determine if the HDF5 link ";
697 msg += string(OSMAPL2S_ATTR_NAME);
699 H5Gclose(s_group_id);
701 throw InternalErr(__FILE__, __LINE__, msg);
704 else if (2 == which_pro) {
706 htri_t has_acos_dset = -1;
709 has_acos_dset = H5Lexists(s_group_id,ACOS_L2S_OCO2_L1B_DSET_NAME,H5P_DEFAULT);
710 if (has_acos_dset > 0) {
712 hid_t s_dset_id = -1;
713 if ((s_dset_id = H5Dopen(s_group_id, ACOS_L2S_OCO2_L1B_DSET_NAME,H5P_DEFAULT)) < 0) {
714 string msg =
"cannot open the HDF5 dataset ";
715 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
716 H5Gclose(s_group_id);
718 throw InternalErr(__FILE__, __LINE__, msg);
723 if ((dtype = H5Dget_type(s_dset_id)) < 0) {
725 H5Gclose(s_group_id);
727 string msg =
"cannot get the datatype of HDF5 dataset ";
728 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
729 throw InternalErr(__FILE__, __LINE__, msg);
733 H5T_class_t ty_class = H5Tget_class(dtype);
737 H5Gclose(s_group_id);
739 string msg =
"cannot get the datatype class of HDF5 dataset ";
740 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
741 throw InternalErr(__FILE__, __LINE__, msg);
744 if (ty_class != H5T_STRING) {
747 H5Gclose(s_group_id);
749 string msg =
"This dataset must be a H5T_STRING class ";
750 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
751 throw InternalErr(__FILE__, __LINE__, msg);
756 if ((dspace = H5Dget_space(s_dset_id)) < 0) {
759 H5Gclose(s_group_id);
761 string msg =
"cannot get the the dataspace of HDF5 dataset ";
762 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
763 throw InternalErr(__FILE__, __LINE__, msg);
766 hssize_t num_elem = 0;
767 if ((num_elem = H5Sget_simple_extent_npoints(dspace))<=0) {
771 H5Gclose(s_group_id);
773 string msg =
"cannot get the the number of points of HDF5 dataset ";
774 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
775 throw InternalErr(__FILE__, __LINE__, msg);
778 size_t dtype_size = H5Tget_size(dtype);
779 if (dtype_size <= 0) {
783 H5Gclose(s_group_id);
785 string msg =
"cannot get the the dataspace of HDF5 dataset ";
786 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
787 throw InternalErr(__FILE__, __LINE__, msg);
790 size_t total_data_size = num_elem * H5Tget_size(dtype);
792 if (H5Tis_variable_str(dtype)) {
794 vector<char>temp_buf;
795 temp_buf.resize(total_data_size);
797 if (H5Dread(s_dset_id,dtype,H5S_ALL,H5S_ALL,H5P_DEFAULT, &temp_buf[0])<0){
801 H5Gclose(s_group_id);
803 string msg =
"cannot get the the dataspace of HDF5 dataset ";
804 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
805 throw InternalErr(__FILE__, __LINE__, msg);
808 char *temp_bp = &temp_buf[0];
809 char *onestring = NULL;
810 string total_string=
"";
812 for (
int temp_i = 0; temp_i <num_elem; temp_i++) {
815 onestring =*(
char **)temp_bp;
818 if (onestring !=NULL) {
819 string tempstring(onestring);
820 total_string+=tempstring;
823 temp_bp += dtype_size;
827 herr_t ret_vlen_claim;
828 ret_vlen_claim = H5Dvlen_reclaim(dtype,dspace,H5P_DEFAULT,&temp_buf[0]);
829 if(ret_vlen_claim < 0) {
833 H5Gclose(s_group_id);
834 throw InternalErr(__FILE__, __LINE__,
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
839 H5Gclose(s_group_id);
841 if (total_string.compare(ACOS_L2S_ATTR_VALUE) ==0 ||
842 total_string.compare(OCO2_L1B_ATTR_VALUE) ==0 ||
843 total_string.compare(OCO2_L1B_ATTR_VALUE2)==0)
847 vector<char> temp_buf(total_data_size+1);
848 if (H5Dread(s_dset_id,dtype,H5S_ALL,H5S_ALL,H5P_DEFAULT, &temp_buf[0])<0){
852 H5Gclose(s_group_id);
854 string msg =
"cannot data of HDF5 dataset ";
855 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
856 throw InternalErr(__FILE__, __LINE__, msg);
859 string total_string(temp_buf.begin(),temp_buf.end()-1);
863 H5Gclose(s_group_id);
865 if (0 == total_string.compare(ACOS_L2S_ATTR_VALUE) ||
866 0 == total_string.compare(OCO2_L1B_ATTR_VALUE))
872 else if (0 == has_acos_dset) {
873 H5Gclose(s_group_id);
877 string msg =
"Fail to determine if the HDF5 link ";
878 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
880 H5Gclose(s_group_id);
882 throw InternalErr(__FILE__, __LINE__, msg);
887 else if (0 == has_smac_group)
890 string msg =
"Fail to determine if the link ";
891 msg += string(SMAC2S_META_GROUP_NAME);
892 msg +=
" exists or not ";
894 throw InternalErr(__FILE__, __LINE__, msg);
899 void obtain_gm_attr_value(hid_t s_root_id,
const char* s_attr_name,
string & s_attr_value) {
901 hid_t s_attr_id = -1;
902 if ((s_attr_id = H5Aopen_by_name(s_root_id,
".",s_attr_name,
903 H5P_DEFAULT, H5P_DEFAULT)) <0) {
904 string msg =
"Cannot open the HDF5 attribute ";
905 msg += string(s_attr_name);
907 throw InternalErr(__FILE__, __LINE__, msg);
910 hid_t attr_type = -1;
911 if ((attr_type = H5Aget_type(s_attr_id)) < 0) {
912 string msg =
"cannot get the attribute datatype for the attribute ";
913 msg += string(s_attr_name);
918 hid_t attr_space = -1;
919 if ((attr_space = H5Aget_space(s_attr_id)) < 0) {
920 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
921 msg += string(s_attr_name);
925 throw InternalErr(__FILE__, __LINE__, msg);
928 int num_elm = H5Sget_simple_extent_npoints(attr_space);
930 string msg =
"cannot get the number for the attribute ";
931 msg += string(s_attr_name);
934 H5Sclose(attr_space);
936 throw InternalErr(__FILE__, __LINE__, msg);
939 size_t atype_size = H5Tget_size(attr_type);
940 if (atype_size <= 0) {
941 string msg =
"cannot obtain the datatype size of the attribute ";
942 msg += string(s_attr_name);
945 H5Sclose(attr_space);
947 throw InternalErr(__FILE__, __LINE__, msg);
950 if(H5Tis_variable_str(attr_type)) {
952 vector<char> temp_buf;
954 temp_buf.resize(atype_size*num_elm);
955 if (H5Aread(s_attr_id, attr_type, &temp_buf[0]) < 0) {
956 string msg =
"cannot retrieve the value of the attribute ";
957 msg += string(s_attr_name);
960 H5Sclose(attr_space);
962 throw InternalErr(__FILE__, __LINE__, msg);
966 temp_bp = &temp_buf[0];
968 for (
unsigned int temp_i = 0; temp_i <num_elm; temp_i++) {
971 onestring =*(
char **)temp_bp;
974 if (onestring !=NULL)
975 string tempstring(onestring);
978 temp_bp +=H5Tget_size(attr_type);
980 if (temp_buf.empty() !=
true) {
983 herr_t ret_vlen_claim;
984 ret_vlen_claim = H5Dvlen_reclaim(attr_type,attr_space,H5P_DEFAULT,&temp_buf[0]);
985 if(ret_vlen_claim < 0){
988 H5Sclose(attr_space);
989 throw InternalErr(__FILE__, __LINE__,
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
996 vector<char> temp_buf(atype_size*num_elm+1);
997 if (H5Aread(s_attr_id,attr_type, &temp_buf[0])<0){
998 string msg =
"cannot retrieve the value of the attribute ";
999 msg += string(s_attr_name);
1000 H5Tclose(attr_type);
1001 H5Aclose(s_attr_id);
1002 H5Sclose(attr_space);
1003 H5Gclose(s_root_id);
1004 throw InternalErr(__FILE__, __LINE__, msg);
1008 string temp_attr_value(temp_buf.begin(),temp_buf.end());
1009 size_t temp_null_pos = temp_attr_value.find_first_of(
'\0');
1010 s_attr_value = temp_attr_value.substr(0,temp_null_pos);
1012 H5Tclose(attr_type);
1013 H5Sclose(attr_space);
1014 H5Aclose(s_attr_id);