33#include <libdap/InternalErr.h>
36#include "h5apicompatible.h"
44H5GCFProduct check_product(hid_t file_id) {
47 H5GCFProduct product_type = General_Product;
50 if ((root_id = H5Gopen(file_id,ROOT_NAME,H5P_DEFAULT))<0){
51 string msg =
"cannot open the HDF5 root group ";
52 msg += string(ROOT_NAME);
53 throw InternalErr(__FILE__, __LINE__, msg);
66 if (
true == check_gpm_l1(root_id)){
67 product_type = GPM_L1;
71 else if (
true == check_gpms_l3(root_id)){
72 product_type = GPMS_L3;
75 else if (
true == check_gpmm_l3(root_id)) {
76 product_type = GPMM_L3;
80 else if (
true == check_measure_seawifs(root_id,s_level)) {
81 if (2 == s_level) product_type = Mea_SeaWiFS_L2;
82 if (3 == s_level) product_type = Mea_SeaWiFS_L3;
85 else if (
true == check_aquarius(root_id,a_level)){
86 if (3 == a_level) product_type = Aqu_L3;
88 else if (
true == check_obpg(root_id,a_level)){
89 if (3 == a_level) product_type = OBPG_L3;
92 else if (
true == check_measure_ozone(root_id)) {
93 product_type = Mea_Ozone;
96 int osmapl2s_flag = 1;
97 if (
true == check_osmapl2s_acosl2s_oco2l1b(root_id,osmapl2s_flag))
98 product_type = OSMAPL2S;
100 if (General_Product == product_type) {
102 int acosl2s_oco2l1b_flag = 2;
103 if (
true == check_osmapl2s_acosl2s_oco2l1b(root_id,acosl2s_oco2l1b_flag))
104 product_type = ACOS_L2S_OR_OCO2_L1B;
114bool check_gpm_l1(hid_t s_root_id) {
116 htri_t has_gpm_l1_attr1 = -1;
117 bool ret_flag =
false;
121 has_gpm_l1_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
123 if(has_gpm_l1_attr1 >0) {
128 if(H5Gget_info(s_root_id,&g_info) <0) {
130 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully");
133 nelms = g_info.nlinks;
138 for (
unsigned int i = 0; i<nelms; i++) {
142 size_t dummy_name_len = 1;
146 H5Lget_name_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
nullptr,
147 dummy_name_len, H5P_DEFAULT);
149 throw InternalErr(__FILE__,__LINE__,
"Error getting the size of the hdf5 object from the root group. ");
153 oname.resize((
size_t)oname_size+1);
155 if (H5Lget_name_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,oname.data(),
156 (
size_t)(oname_size+1), H5P_DEFAULT) < 0)
157 throw InternalErr(__FILE__,__LINE__,
"Error getting the hdf5 object name from the root group. ");
161 if (H5Lget_info(s_root_id,oname.data(),&linfo,H5P_DEFAULT)<0)
162 throw InternalErr (__FILE__,__LINE__,
"HDF5 link name error from the root group. ");
165 if(H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type)
170 if(H5OGET_INFO_BY_IDX(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE, (hsize_t)i,&soinfo,H5P_DEFAULT)<0)
171 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully. ");
173 H5O_type_t obj_type = soinfo.type;
176 if(obj_type == H5O_TYPE_GROUP) {
179 cgroup = H5Gopen(s_root_id,oname.data(),H5P_DEFAULT);
181 throw InternalErr(__FILE__,__LINE__,
"Cannot open the group.");
183 int num_attrs = soinfo.num_attrs;
186 for (
int j = 0; j < num_attrs; j++) {
189 if ((attrid = H5Aopen_by_idx(cgroup,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
190 throw InternalErr(__FILE__,__LINE__,
"Unable to open attribute by index " );
193 ssize_t name_size = H5Aget_name(attrid, 0,
nullptr);
195 throw InternalErr(__FILE__,__LINE__,
"Unable to obtain the size of the hdf5 attribute name " );
198 attr_name.resize(name_size+1);
201 if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0)
202 throw InternalErr(__FILE__,__LINE__,
"unable to obtain the hdf5 attribute name ");
204 string swathheader(GPM_SWATH_ATTR2_NAME);
205 if(attr_name.rfind(swathheader) !=string::npos) {
213 if(
true == ret_flag){
239bool check_gpms_l3(hid_t s_root_id) {
241 htri_t has_gpm_l3_attr1 = -1;
242 bool ret_flag =
false;
245 has_gpm_l3_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
247 if(has_gpm_l3_attr1 >0) {
249 htri_t has_gpm_grid_group = -1;
251 has_gpm_grid_group = H5Lexists(s_root_id,GPM_GRID_GROUP_NAME1,H5P_DEFAULT);
253 hid_t s_group_id = -1;
254 if (has_gpm_grid_group >0){
257 if ((s_group_id = H5Gopen(s_root_id, GPM_GRID_GROUP_NAME1,H5P_DEFAULT))<0) {
258 string msg =
"Cannot open the HDF5 Group ";
259 msg += string(GPM_GRID_GROUP_NAME1);
261 throw InternalErr(__FILE__, __LINE__, msg);
266 if(H5Lexists(s_root_id,GPM_GRID_GROUP_NAME2,H5P_DEFAULT) >0) {
268 if ((s_group_id = H5Gopen(s_root_id, GPM_GRID_GROUP_NAME2,H5P_DEFAULT))<0) {
269 string msg =
"Cannot open the HDF5 Group ";
270 msg += string(GPM_GRID_GROUP_NAME2);
272 throw InternalErr(__FILE__, __LINE__, msg);
279 htri_t has_gpm_l3_attr2 = -1;
280 has_gpm_l3_attr2 = H5Aexists(s_group_id,GPM_ATTR2_NAME);
281 if (has_gpm_l3_attr2 >0)
284 H5Gclose(s_group_id);
295bool check_gpmm_l3(hid_t s_root_id) {
297 htri_t has_gpm_l3_attr1 = -1;
298 bool ret_flag =
false;
302 has_gpm_l3_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
304 if(has_gpm_l3_attr1 >0) {
306 if(H5Lexists(s_root_id,GPM_GRID_MULTI_GROUP_NAME,H5P_DEFAULT) >0) {
307 hid_t cgroup_id = -1;
309 if ((cgroup_id = H5Gopen(s_root_id, GPM_GRID_MULTI_GROUP_NAME,H5P_DEFAULT))<0) {
310 string msg =
"Cannot open the HDF5 Group ";
311 msg += string(GPM_GRID_MULTI_GROUP_NAME);
313 throw InternalErr(__FILE__, __LINE__, msg);
319 if(H5Gget_info(cgroup_id,&g_info) <0) {
322 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully");
325 nelms = g_info.nlinks;
327 hid_t cgroup2_id = -1;
330 for (
unsigned int i = 0; i<nelms; i++) {
334 size_t dummy_name_len = 1;
338 H5Lget_name_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
nullptr,
339 dummy_name_len, H5P_DEFAULT);
341 throw InternalErr(__FILE__,__LINE__,
"Error getting the size of the hdf5 object from the grid group. ");
345 oname.resize((
size_t)oname_size+1);
347 if (H5Lget_name_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,oname.data(),
348 (
size_t)(oname_size+1), H5P_DEFAULT) < 0)
349 throw InternalErr(__FILE__,__LINE__,
"Error getting the hdf5 object name from the root group. ");
353 if (H5Lget_info(cgroup_id,oname.data(),&linfo,H5P_DEFAULT)<0)
354 throw InternalErr (__FILE__,__LINE__,
"HDF5 link name error from the root group. ");
357 if(H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type)
362 if(H5OGET_INFO_BY_IDX(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE, (hsize_t)i,&soinfo,H5P_DEFAULT)<0)
363 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully. ");
365 H5O_type_t obj_type = soinfo.type;
368 if(obj_type == H5O_TYPE_GROUP) {
371 cgroup2_id = H5Gopen(cgroup_id,oname.data(),H5P_DEFAULT);
373 throw InternalErr(__FILE__,__LINE__,
"Cannot open the group.");
375 htri_t has_gpm_l3_attr2;
376 has_gpm_l3_attr2 = H5Aexists(cgroup2_id,GPM_ATTR2_NAME);
377 if (has_gpm_l3_attr2 >0) {
379 H5Gclose(cgroup2_id);
384 int num_attrs = (
int)(soinfo.num_attrs);
387 for (
int j = 0; j < num_attrs; j++) {
390 if ((attrid = H5Aopen_by_idx(cgroup2_id,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
391 throw InternalErr(__FILE__,__LINE__,
"Unable to open attribute by index " );
394 ssize_t name_size = H5Aget_name(attrid, 0,
nullptr);
396 throw InternalErr(__FILE__,__LINE__,
"Unable to obtain the size of the hdf5 attribute name " );
399 attr_name.resize(name_size+1);
402 if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0)
403 throw InternalErr(__FILE__,__LINE__,
"unable to obtain the hdf5 attribute name ");
405 string gridheader(GPM_ATTR2_NAME);
406 if(attr_name.find(gridheader) !=string::npos) {
417 H5Gclose(cgroup2_id);
427 H5Gclose(cgroup2_id);
438bool check_measure_seawifs(hid_t s_root_id,
int & s_lflag) {
440 htri_t has_seawifs_attr1 = -1;
441 bool ret_flag =
false;
446 has_seawifs_attr1 = H5Aexists(s_root_id,SeaWiFS_ATTR1_NAME);
448 if (has_seawifs_attr1 >0) {
450 string attr1_value=
"";
451 obtain_gm_attr_value(s_root_id, SeaWiFS_ATTR1_NAME, attr1_value);
452 if (0 == attr1_value.compare(SeaWiFS_ATTR1_VALUE)) {
453 htri_t has_seawifs_attr2 = -1;
454 htri_t has_seawifs_attr3 = -1;
455 has_seawifs_attr2 = H5Aexists(s_root_id,SeaWiFS_ATTR2_NAME);
456 has_seawifs_attr3 = H5Aexists(s_root_id,SeaWiFS_ATTR3_NAME);
458 if ((has_seawifs_attr2 >0) && (has_seawifs_attr3 > 0)){
459 string attr2_value =
"";
460 string attr3_value =
"";
461 obtain_gm_attr_value(s_root_id,SeaWiFS_ATTR2_NAME, attr2_value);
462 obtain_gm_attr_value(s_root_id,SeaWiFS_ATTR3_NAME, attr3_value);
468 if (((0 == attr2_value.find(SeaWiFS_ATTR2_FPVALUE)) &&
469 (attr2_value.find(SeaWiFS_ATTR2_L2PVALUE)!=string::npos))
470 ||(0 == attr3_value.find(SeaWiFS_ATTR3_L2FPVALUE))) {
475 else if (((0 == attr2_value.find(SeaWiFS_ATTR2_FPVALUE)) &&
476 (attr2_value.find(SeaWiFS_ATTR2_L3PVALUE)!=string::npos))
477 ||(0 == attr3_value.find(SeaWiFS_ATTR3_L3FPVALUE))) {
483 else if ((0 == has_seawifs_attr2 ) || (0 == has_seawifs_attr3))
486 string msg =
"Fail to determine if the HDF5 attribute ";
487 msg += string(SeaWiFS_ATTR2_NAME);
488 msg +=
"or the HDF5 attribute ";
489 msg += string(SeaWiFS_ATTR3_NAME);
492 throw InternalErr(__FILE__, __LINE__, msg);
496 else if (0 == has_seawifs_attr1)
499 string msg =
"Fail to determine if the HDF5 attribute ";
500 msg += string(SeaWiFS_ATTR1_NAME);
503 throw InternalErr(__FILE__, __LINE__, msg);
509bool check_measure_ozone(hid_t s_root_id) {
511 htri_t has_ozone_attr1 = -1;
512 bool ret_flag =
false;
517 has_ozone_attr1 = H5Aexists(s_root_id,Ozone_ATTR1_NAME);
519 if (has_ozone_attr1 >0) {
520 string attr1_value =
"";
521 obtain_gm_attr_value(s_root_id, Ozone_ATTR1_NAME, attr1_value);
522 if ((0 == attr1_value.compare(Ozone_ATTR1_VALUE1)) ||
523 (0 == attr1_value.compare(Ozone_ATTR1_VALUE2))) {
524 htri_t has_ozone_attr2 = -1;
525 has_ozone_attr2 = H5Aexists(s_root_id,Ozone_ATTR2_NAME);
526 if (has_ozone_attr2 >0) {
527 string attr2_value =
"";
528 obtain_gm_attr_value(s_root_id,Ozone_ATTR2_NAME, attr2_value);
529 if(0 == attr2_value.compare(Ozone_ATTR2_VALUE))
533 else if (0 == has_ozone_attr2)
536 string msg =
"Fail to determine if the HDF5 attribute ";
537 msg += string(Ozone_ATTR2_NAME);
540 throw InternalErr(__FILE__, __LINE__, msg);
544 else if (0 == has_ozone_attr1 )
547 string msg =
"Fail to determine if the HDF5 attribute ";
548 msg += string(Ozone_ATTR1_NAME);
551 throw InternalErr(__FILE__, __LINE__, msg);
560bool check_aquarius(hid_t s_root_id,
int & s_level) {
562 htri_t has_aquarius_attr1 = -1;
563 bool ret_flag =
false;
568 has_aquarius_attr1 = H5Aexists(s_root_id,Aquarius_ATTR1_NAME);
569 if (has_aquarius_attr1 >0) {
570 string attr1_value =
"";
571 obtain_gm_attr_value(s_root_id, Aquarius_ATTR1_NAME, attr1_value);
572 if (0 == attr1_value.compare(Aquarius_ATTR1_VALUE)) {
573 htri_t has_aquarius_attr2 = -1;
574 has_aquarius_attr2 = H5Aexists(s_root_id,Aquarius_ATTR2_NAME);
575 if (has_aquarius_attr2 >0) {
576 string attr2_value =
"";
577 obtain_gm_attr_value(s_root_id,Aquarius_ATTR2_NAME, attr2_value);
580 if (attr2_value.find(Aquarius_ATTR2_PVALUE)!=string::npos){
587 else if (0 == has_aquarius_attr2)
590 string msg =
"Fail to determine if the HDF5 attribute ";
591 msg += string(Aquarius_ATTR2_NAME);
594 throw InternalErr(__FILE__, __LINE__, msg);
598 else if (0 == has_aquarius_attr1)
601 string msg =
"Fail to determine if the HDF5 attribute ";
602 msg += string(Aquarius_ATTR1_NAME);
605 throw InternalErr(__FILE__, __LINE__, msg);
613bool check_obpg(hid_t s_root_id,
int & s_level) {
615 htri_t has_obpg_attr1 = -1;
616 bool ret_flag =
false;
621 has_obpg_attr1 = H5Aexists(s_root_id,Obpgl3_ATTR1_NAME);
622 if (has_obpg_attr1 >0) {
623 string attr1_value =
"";
624 obtain_gm_attr_value(s_root_id, Obpgl3_ATTR1_NAME, attr1_value);
625 htri_t has_obpg_attr2 = -1;
626 has_obpg_attr2 = H5Aexists(s_root_id,Obpgl3_ATTR2_NAME);
627 if (has_obpg_attr2 >0) {
628 string attr2_value =
"";
629 obtain_gm_attr_value(s_root_id,Obpgl3_ATTR2_NAME, attr2_value);
630 if ((0 == attr1_value.compare(Obpgl3_ATTR1_VALUE)) &&
631 (0 == attr2_value.compare(Obpgl3_ATTR2_VALUE))) {
638 else if (0 == has_obpg_attr2)
641 string msg =
"Fail to determine if the HDF5 attribute ";
642 msg += string(Obpgl3_ATTR2_NAME);
645 throw InternalErr(__FILE__, __LINE__, msg);
648 else if (0 == has_obpg_attr1)
651 string msg =
"Fail to determine if the HDF5 attribute ";
652 msg += string(Obpgl3_ATTR1_NAME);
655 throw InternalErr(__FILE__, __LINE__, msg);
660bool check_osmapl2s_acosl2s_oco2l1b(hid_t s_root_id,
int which_pro) {
662 htri_t has_smac_group;
663 bool return_flag =
false;
664 has_smac_group = H5Lexists(s_root_id,SMAC2S_META_GROUP_NAME,H5P_DEFAULT);
666 if (has_smac_group >0){
667 hid_t s_group_id = -1;
670 if ((s_group_id = H5Gopen(s_root_id, SMAC2S_META_GROUP_NAME,H5P_DEFAULT))<0) {
671 string msg =
"Cannot open the HDF5 Group ";
672 msg += string(SMAC2S_META_GROUP_NAME);
674 throw InternalErr(__FILE__, __LINE__, msg);
678 if (1 == which_pro) {
680 htri_t has_osmapl2s_attr = -1;
682 has_osmapl2s_attr = H5Aexists(s_group_id,OSMAPL2S_ATTR_NAME);
683 if (has_osmapl2s_attr >0) {
684 string attr_value =
"";
685 obtain_gm_attr_value(s_group_id, OSMAPL2S_ATTR_NAME, attr_value);
686 if (attr_value.compare(OSMAPL2S_ATTR_VALUE) == 0)
690 H5Gclose(s_group_id);
692 else if (0 == has_osmapl2s_attr) {
693 H5Gclose(s_group_id);
697 string msg =
"Fail to determine if the HDF5 link ";
698 msg += string(OSMAPL2S_ATTR_NAME);
700 H5Gclose(s_group_id);
702 throw InternalErr(__FILE__, __LINE__, msg);
705 else if (2 == which_pro) {
707 htri_t has_acos_dset = -1;
710 has_acos_dset = H5Lexists(s_group_id,ACOS_L2S_OCO2_L1B_DSET_NAME,H5P_DEFAULT);
711 if (has_acos_dset > 0) {
713 hid_t s_dset_id = -1;
714 if ((s_dset_id = H5Dopen(s_group_id, ACOS_L2S_OCO2_L1B_DSET_NAME,H5P_DEFAULT)) < 0) {
715 string msg =
"cannot open the HDF5 dataset ";
716 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
717 H5Gclose(s_group_id);
719 throw InternalErr(__FILE__, __LINE__, msg);
724 if ((dtype = H5Dget_type(s_dset_id)) < 0) {
726 H5Gclose(s_group_id);
728 string msg =
"cannot get the datatype of HDF5 dataset ";
729 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
730 throw InternalErr(__FILE__, __LINE__, msg);
734 H5T_class_t ty_class = H5Tget_class(dtype);
738 H5Gclose(s_group_id);
740 string msg =
"cannot get the datatype class of HDF5 dataset ";
741 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
742 throw InternalErr(__FILE__, __LINE__, msg);
745 if (ty_class != H5T_STRING) {
748 H5Gclose(s_group_id);
750 string msg =
"This dataset must be a H5T_STRING class ";
751 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
752 throw InternalErr(__FILE__, __LINE__, msg);
757 if ((dspace = H5Dget_space(s_dset_id)) < 0) {
760 H5Gclose(s_group_id);
762 string msg =
"cannot get the the dataspace of HDF5 dataset ";
763 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
764 throw InternalErr(__FILE__, __LINE__, msg);
767 hssize_t num_elem = 0;
768 if ((num_elem = H5Sget_simple_extent_npoints(dspace))<=0) {
772 H5Gclose(s_group_id);
774 string msg =
"cannot get the the number of points of HDF5 dataset ";
775 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
776 throw InternalErr(__FILE__, __LINE__, msg);
779 size_t dtype_size = H5Tget_size(dtype);
780 if (dtype_size <= 0) {
784 H5Gclose(s_group_id);
786 string msg =
"cannot get the the dataspace of HDF5 dataset ";
787 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
788 throw InternalErr(__FILE__, __LINE__, msg);
791 size_t total_data_size = num_elem * H5Tget_size(dtype);
793 if (H5Tis_variable_str(dtype)) {
795 vector<char>temp_buf;
796 temp_buf.resize(total_data_size);
798 if (H5Dread(s_dset_id,dtype,H5S_ALL,H5S_ALL,H5P_DEFAULT, temp_buf.data())<0){
802 H5Gclose(s_group_id);
804 string msg =
"cannot get the the dataspace of HDF5 dataset ";
805 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
806 throw InternalErr(__FILE__, __LINE__, msg);
809 char *temp_bp = temp_buf.data();
810 char *onestring =
nullptr;
811 string total_string=
"";
813 for (
int temp_i = 0; temp_i <num_elem; temp_i++) {
816 onestring =*(
char **)temp_bp;
819 if (onestring !=
nullptr) {
820 string tempstring(onestring);
821 total_string+=tempstring;
824 temp_bp += dtype_size;
828 herr_t ret_vlen_claim;
829 ret_vlen_claim = H5Dvlen_reclaim(dtype,dspace,H5P_DEFAULT,temp_buf.data());
830 if(ret_vlen_claim < 0) {
834 H5Gclose(s_group_id);
835 throw InternalErr(__FILE__, __LINE__,
"Cannot reclaim the memory buffer of the HDF5 variable length string.");
840 H5Gclose(s_group_id);
842 if (total_string.compare(ACOS_L2S_ATTR_VALUE) ==0 ||
843 total_string.compare(OCO2_L1B_ATTR_VALUE) ==0 ||
844 total_string.compare(OCO2_L1B_ATTR_VALUE2)==0)
848 vector<char> temp_buf(total_data_size+1);
849 if (H5Dread(s_dset_id,dtype,H5S_ALL,H5S_ALL,H5P_DEFAULT, temp_buf.data())<0){
853 H5Gclose(s_group_id);
855 string msg =
"cannot data of HDF5 dataset ";
856 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
857 throw InternalErr(__FILE__, __LINE__, msg);
860 string total_string(temp_buf.begin(),temp_buf.end()-1);
864 H5Gclose(s_group_id);
866 if (0 == total_string.compare(ACOS_L2S_ATTR_VALUE) ||
867 0 == total_string.compare(OCO2_L1B_ATTR_VALUE))
873 else if (0 == has_acos_dset) {
874 H5Gclose(s_group_id);
878 string msg =
"Fail to determine if the HDF5 link ";
879 msg += string(ACOS_L2S_OCO2_L1B_DSET_NAME);
881 H5Gclose(s_group_id);
883 throw InternalErr(__FILE__, __LINE__, msg);
888 else if (0 == has_smac_group)
891 string msg =
"Fail to determine if the link ";
892 msg += string(SMAC2S_META_GROUP_NAME);
893 msg +=
" exists or not ";
895 throw InternalErr(__FILE__, __LINE__, msg);
900void obtain_gm_attr_value(hid_t s_root_id,
const char* s_attr_name,
string & s_attr_value) {
902 hid_t s_attr_id = -1;
903 if ((s_attr_id = H5Aopen_by_name(s_root_id,
".",s_attr_name,
904 H5P_DEFAULT, H5P_DEFAULT)) <0) {
905 string msg =
"Cannot open the HDF5 attribute ";
906 msg += string(s_attr_name);
908 throw InternalErr(__FILE__, __LINE__, msg);
911 hid_t attr_type = -1;
912 if ((attr_type = H5Aget_type(s_attr_id)) < 0) {
913 string msg =
"cannot get the attribute datatype for the attribute ";
914 msg += string(s_attr_name);
919 hid_t attr_space = -1;
920 if ((attr_space = H5Aget_space(s_attr_id)) < 0) {
921 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
922 msg += string(s_attr_name);
926 throw InternalErr(__FILE__, __LINE__, msg);
929 int num_elm = (
int)(H5Sget_simple_extent_npoints(attr_space));
931 string msg =
"cannot get the number for the attribute ";
932 msg += string(s_attr_name);
935 H5Sclose(attr_space);
937 throw InternalErr(__FILE__, __LINE__, msg);
940 size_t atype_size = H5Tget_size(attr_type);
941 if (atype_size <= 0) {
942 string msg =
"cannot obtain the datatype size of the attribute ";
943 msg += string(s_attr_name);
946 H5Sclose(attr_space);
948 throw InternalErr(__FILE__, __LINE__, msg);
951 if(H5Tis_variable_str(attr_type)) {
953 vector<char> temp_buf;
955 temp_buf.resize(atype_size*num_elm);
956 if (H5Aread(s_attr_id, attr_type, temp_buf.data()) < 0) {
957 string msg =
"cannot retrieve the value of the attribute ";
958 msg += string(s_attr_name);
961 H5Sclose(attr_space);
963 throw InternalErr(__FILE__, __LINE__, msg);
967 temp_bp = temp_buf.data();
969 for (
int temp_i = 0; temp_i <num_elm; temp_i++) {
972 onestring =*(
char **)temp_bp;
975 if (onestring !=
nullptr)
976 string tempstring(onestring);
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.data());
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.data())<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);
This file includes functions to identify different NASA HDF5 products. Current supported products inc...