33 #include <InternalErr.h>
47 if ((root_id = H5Gopen(file_id,ROOT_NAME,H5P_DEFAULT))<0){
48 string msg =
"cannot open the HDF5 root group ";
49 msg += string(ROOT_NAME);
51 throw InternalErr(__FILE__, __LINE__, msg);
87 if (3 == a_level) product_type =
Aqu_L3;
91 if (3 == a_level) product_type =
OBPG_L3;
106 int acosl2s_flag = 2;
122 htri_t has_gpm_l1_attr1 = -1;
123 bool ret_flag =
false;
128 has_gpm_l1_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
130 if(has_gpm_l1_attr1 >0) {
135 if(H5Gget_info(s_root_id,&g_info) <0) {
137 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully");
140 nelms = g_info.nlinks;
145 for (
unsigned int i = 0; i<nelms; i++) {
149 size_t dummy_name_len = 1;
153 H5Lget_name_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
NULL,
154 dummy_name_len, H5P_DEFAULT);
156 throw InternalErr(__FILE__,__LINE__,
"Error getting the size of the hdf5 object from the root group. ");
160 oname.resize((
size_t)oname_size+1);
162 if (H5Lget_name_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
163 (
size_t)(oname_size+1), H5P_DEFAULT) < 0)
164 throw InternalErr(__FILE__,__LINE__,
"Error getting the hdf5 object name from the root group. ");
168 if (H5Lget_info(s_root_id,&oname[0],&linfo,H5P_DEFAULT)<0)
169 throw InternalErr (__FILE__,__LINE__,
"HDF5 link name error from the root group. ");
172 if(H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type)
177 if(H5Oget_info_by_idx(s_root_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE, (hsize_t)i,&soinfo,H5P_DEFAULT)<0)
178 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully. ");
180 H5O_type_t obj_type = soinfo.type;
183 if(obj_type == H5O_TYPE_GROUP) {
186 cgroup = H5Gopen(s_root_id,&oname[0],H5P_DEFAULT);
188 throw InternalErr(__FILE__,__LINE__,
"Cannot open the group.");
190 int num_attrs = soinfo.num_attrs;
193 for (
int j = 0; j < num_attrs; j++) {
196 if ((attrid = H5Aopen_by_idx(cgroup,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
197 throw InternalErr(__FILE__,__LINE__,
"Unable to open attribute by index " );
200 ssize_t name_size = H5Aget_name(attrid, 0,
NULL);
202 throw InternalErr(__FILE__,__LINE__,
"Unable to obtain the size of the hdf5 attribute name " );
205 attr_name.resize(name_size+1);
208 if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0)
209 throw InternalErr(__FILE__,__LINE__,
"unable to obtain the hdf5 attribute name ");
211 string swathheader(GPM_SWATH_ATTR2_NAME);
212 if(attr_name.rfind(swathheader) !=string::npos) {
220 if(
true == ret_flag){
248 htri_t has_gpm_l3_attr1 = -1;
249 bool ret_flag =
false;
254 has_gpm_l3_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
256 if(has_gpm_l3_attr1 >0) {
258 htri_t has_gpm_grid_group = -1;
261 has_gpm_grid_group = H5Lexists(s_root_id,GPM_GRID_GROUP_NAME1,H5P_DEFAULT);
263 hid_t s_group_id = -1;
264 if (has_gpm_grid_group >0){
267 if ((s_group_id = H5Gopen(s_root_id, GPM_GRID_GROUP_NAME1,H5P_DEFAULT))<0) {
268 string msg =
"Cannot open the HDF5 Group ";
269 msg += string(GPM_GRID_GROUP_NAME1);
271 throw InternalErr(__FILE__, __LINE__, msg);
276 if(H5Lexists(s_root_id,GPM_GRID_GROUP_NAME2,H5P_DEFAULT) >0) {
278 if ((s_group_id = H5Gopen(s_root_id, GPM_GRID_GROUP_NAME2,H5P_DEFAULT))<0) {
279 string msg =
"Cannot open the HDF5 Group ";
280 msg += string(GPM_GRID_GROUP_NAME2);
282 throw InternalErr(__FILE__, __LINE__, msg);
289 htri_t has_gpm_l3_attr2 = -1;
290 has_gpm_l3_attr2 = H5Aexists(s_group_id,GPM_ATTR2_NAME);
291 if (has_gpm_l3_attr2 >0)
294 H5Gclose(s_group_id);
307 htri_t has_gpm_l3_attr1 = -1;
308 bool ret_flag =
false;
313 has_gpm_l3_attr1 = H5Aexists(s_root_id,GPM_ATTR1_NAME);
315 if(has_gpm_l3_attr1 >0) {
317 if(H5Lexists(s_root_id,GPM_GRID_MULTI_GROUP_NAME,H5P_DEFAULT) >0) {
318 hid_t cgroup_id = -1;
321 if ((cgroup_id = H5Gopen(s_root_id, GPM_GRID_MULTI_GROUP_NAME,H5P_DEFAULT))<0) {
322 string msg =
"Cannot open the HDF5 Group ";
323 msg += string(GPM_GRID_MULTI_GROUP_NAME);
325 throw InternalErr(__FILE__, __LINE__, msg);
331 if(H5Gget_info(cgroup_id,&g_info) <0) {
334 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully");
337 nelms = g_info.nlinks;
340 hid_t cgroup2_id = -1;
343 for (
unsigned int i = 0; i<nelms; i++) {
347 size_t dummy_name_len = 1;
351 H5Lget_name_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
NULL,
352 dummy_name_len, H5P_DEFAULT);
354 throw InternalErr(__FILE__,__LINE__,
"Error getting the size of the hdf5 object from the grid group. ");
358 oname.resize((
size_t)oname_size+1);
360 if (H5Lget_name_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
361 (
size_t)(oname_size+1), H5P_DEFAULT) < 0)
362 throw InternalErr(__FILE__,__LINE__,
"Error getting the hdf5 object name from the root group. ");
366 if (H5Lget_info(cgroup_id,&oname[0],&linfo,H5P_DEFAULT)<0)
367 throw InternalErr (__FILE__,__LINE__,
"HDF5 link name error from the root group. ");
370 if(H5L_TYPE_SOFT == linfo.type || H5L_TYPE_EXTERNAL == linfo.type)
375 if(H5Oget_info_by_idx(cgroup_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE, (hsize_t)i,&soinfo,H5P_DEFAULT)<0)
376 throw InternalErr(__FILE__,__LINE__,
"Cannot get the HDF5 object info. successfully. ");
378 H5O_type_t obj_type = soinfo.type;
381 if(obj_type == H5O_TYPE_GROUP) {
384 cgroup2_id = H5Gopen(cgroup_id,&oname[0],H5P_DEFAULT);
386 throw InternalErr(__FILE__,__LINE__,
"Cannot open the group.");
391 htri_t has_gpm_l3_attr2;
392 has_gpm_l3_attr2 = H5Aexists(cgroup2_id,GPM_ATTR2_NAME);
393 if (has_gpm_l3_attr2 >0) {
395 H5Gclose(cgroup2_id);
400 int num_attrs = soinfo.num_attrs;
403 for (
int j = 0; j < num_attrs; j++) {
406 if ((attrid = H5Aopen_by_idx(cgroup2_id,
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,(hsize_t)j, H5P_DEFAULT, H5P_DEFAULT)) < 0)
407 throw InternalErr(__FILE__,__LINE__,
"Unable to open attribute by index " );
410 ssize_t name_size = H5Aget_name(attrid, 0,
NULL);
412 throw InternalErr(__FILE__,__LINE__,
"Unable to obtain the size of the hdf5 attribute name " );
415 attr_name.resize(name_size+1);
418 if ((H5Aget_name(attrid, name_size+1, &attr_name[0])) < 0)
419 throw InternalErr(__FILE__,__LINE__,
"unable to obtain the hdf5 attribute name ");
422 string gridheader(GPM_ATTR2_NAME);
423 if(attr_name.find(gridheader) !=string::npos) {
434 H5Gclose(cgroup2_id);
444 H5Gclose(cgroup2_id);
459 htri_t has_seawifs_attr1 = -1;
460 bool ret_flag =
false;
466 has_seawifs_attr1 = H5Aexists(s_root_id,SeaWiFS_ATTR1_NAME);
468 if (has_seawifs_attr1 >0) {
470 string attr1_value=
"";
474 if (0 == attr1_value.compare(SeaWiFS_ATTR1_VALUE)) {
476 htri_t has_seawifs_attr2 = -1;
477 htri_t has_seawifs_attr3 = -1;
478 has_seawifs_attr2 = H5Aexists(s_root_id,SeaWiFS_ATTR2_NAME);
479 has_seawifs_attr3 = H5Aexists(s_root_id,SeaWiFS_ATTR3_NAME);
481 if ((has_seawifs_attr2 >0) && (has_seawifs_attr3 > 0)){
483 string attr2_value =
"";
484 string attr3_value =
"";
492 if (((0 == attr2_value.find(SeaWiFS_ATTR2_FPVALUE)) &&
493 (attr2_value.find(SeaWiFS_ATTR2_L2PVALUE)!=string::npos))
494 ||(0 == attr3_value.find(SeaWiFS_ATTR3_L2FPVALUE))) {
499 else if (((0 == attr2_value.find(SeaWiFS_ATTR2_FPVALUE)) &&
500 (attr2_value.find(SeaWiFS_ATTR2_L3PVALUE)!=string::npos))
501 ||(0 == attr3_value.find(SeaWiFS_ATTR3_L3FPVALUE))) {
507 else if ((0 == has_seawifs_attr2 ) || (0 == has_seawifs_attr3))
510 string msg =
"Fail to determine if the HDF5 attribute ";
511 msg += string(SeaWiFS_ATTR2_NAME);
512 msg +=
"or the HDF5 attribute ";
513 msg += string(SeaWiFS_ATTR3_NAME);
516 throw InternalErr(__FILE__, __LINE__, msg);
520 else if (0 == has_seawifs_attr1)
523 string msg =
"Fail to determine if the HDF5 attribute ";
524 msg += string(SeaWiFS_ATTR1_NAME);
527 throw InternalErr(__FILE__, __LINE__, msg);
535 htri_t has_ozone_attr1 = -1;
536 bool ret_flag =
false;
542 has_ozone_attr1 = H5Aexists(s_root_id,Ozone_ATTR1_NAME);
544 if (has_ozone_attr1 >0) {
545 string attr1_value =
"";
549 if ((0 == attr1_value.compare(Ozone_ATTR1_VALUE1)) ||
550 (0 == attr1_value.compare(Ozone_ATTR1_VALUE2))) {
551 htri_t has_ozone_attr2 = -1;
552 has_ozone_attr2 = H5Aexists(s_root_id,Ozone_ATTR2_NAME);
553 if (has_ozone_attr2 >0) {
554 string attr2_value =
"";
556 if(0 == attr2_value.compare(Ozone_ATTR2_VALUE))
560 else if (0 == has_ozone_attr2)
563 string msg =
"Fail to determine if the HDF5 attribute ";
564 msg += string(Ozone_ATTR2_NAME);
567 throw InternalErr(__FILE__, __LINE__, msg);
571 else if (0 == has_ozone_attr1 )
574 string msg =
"Fail to determine if the HDF5 attribute ";
575 msg += string(Ozone_ATTR1_NAME);
578 throw InternalErr(__FILE__, __LINE__, msg);
589 htri_t has_aquarius_attr1 = -1;
590 bool ret_flag =
false;
596 has_aquarius_attr1 = H5Aexists(s_root_id,Aquarius_ATTR1_NAME);
597 if (has_aquarius_attr1 >0) {
598 string attr1_value =
"";
600 if (0 == attr1_value.compare(Aquarius_ATTR1_VALUE)) {
601 htri_t has_aquarius_attr2 = -1;
602 has_aquarius_attr2 = H5Aexists(s_root_id,Aquarius_ATTR2_NAME);
603 if (has_aquarius_attr2 >0) {
604 string attr2_value =
"";
608 if (attr2_value.find(Aquarius_ATTR2_PVALUE)!=string::npos){
615 else if (0 == has_aquarius_attr2)
618 string msg =
"Fail to determine if the HDF5 attribute ";
619 msg += string(Aquarius_ATTR2_NAME);
622 throw InternalErr(__FILE__, __LINE__, msg);
626 else if (0 == has_aquarius_attr1)
629 string msg =
"Fail to determine if the HDF5 attribute ";
630 msg += string(Aquarius_ATTR1_NAME);
633 throw InternalErr(__FILE__, __LINE__, msg);
643 htri_t has_obpg_attr1 = -1;
644 bool ret_flag =
false;
650 has_obpg_attr1 = H5Aexists(s_root_id,Obpgl3_ATTR1_NAME);
651 if (has_obpg_attr1 >0) {
652 string attr1_value =
"";
654 htri_t has_obpg_attr2 = -1;
655 has_obpg_attr2 = H5Aexists(s_root_id,Obpgl3_ATTR2_NAME);
656 if (has_obpg_attr2 >0) {
657 string attr2_value =
"";
659 if ((0 == attr1_value.compare(Obpgl3_ATTR1_VALUE)) &&
660 (0 == attr2_value.compare(Obpgl3_ATTR2_VALUE))) {
668 else if (0 == has_obpg_attr2)
671 string msg =
"Fail to determine if the HDF5 attribute ";
672 msg += string(Obpgl3_ATTR2_NAME);
675 throw InternalErr(__FILE__, __LINE__, msg);
679 else if (0 == has_obpg_attr1)
682 string msg =
"Fail to determine if the HDF5 attribute ";
683 msg += string(Obpgl3_ATTR1_NAME);
686 throw InternalErr(__FILE__, __LINE__, msg);
693 htri_t has_smac_group;
695 bool return_flag =
false;
696 has_smac_group = H5Lexists(s_root_id,SMAC2S_META_GROUP_NAME,H5P_DEFAULT);
698 if (has_smac_group >0){
699 hid_t s_group_id = -1;
702 if ((s_group_id = H5Gopen(s_root_id, SMAC2S_META_GROUP_NAME,H5P_DEFAULT))<0) {
703 string msg =
"Cannot open the HDF5 Group ";
704 msg += string(SMAC2S_META_GROUP_NAME);
706 throw InternalErr(__FILE__, __LINE__, msg);
710 if (1 == which_pro) {
712 htri_t has_smap_attr = -1;
714 has_smap_attr = H5Aexists(s_group_id,SMAP_ATTR_NAME);
715 if (has_smap_attr >0) {
716 string attr_value =
"";
718 if (attr_value.compare(SMAP_ATTR_VALUE) == 0)
722 H5Gclose(s_group_id);
724 else if (0 == has_smap_attr) {
725 H5Gclose(s_group_id);
729 string msg =
"Fail to determine if the HDF5 link ";
730 msg += string(SMAP_ATTR_NAME);
732 H5Gclose(s_group_id);
734 throw InternalErr(__FILE__, __LINE__, msg);
737 else if (2 == which_pro) {
740 htri_t has_acos_dset = -1;
743 has_acos_dset = H5Lexists(s_group_id,ACOS_L2S_DSET_NAME,H5P_DEFAULT);
744 if (has_acos_dset > 0) {
747 hid_t s_dset_id = -1;
748 if ((s_dset_id = H5Dopen(s_group_id, ACOS_L2S_DSET_NAME,H5P_DEFAULT)) < 0) {
749 string msg =
"cannot open the HDF5 dataset ";
750 msg += string(ACOS_L2S_DSET_NAME);
751 H5Gclose(s_group_id);
753 throw InternalErr(__FILE__, __LINE__, msg);
758 if ((dtype = H5Dget_type(s_dset_id)) < 0) {
760 H5Gclose(s_group_id);
762 string msg =
"cannot get the datatype of HDF5 dataset ";
763 msg += string(ACOS_L2S_DSET_NAME);
764 throw InternalErr(__FILE__, __LINE__, msg);
768 H5T_class_t ty_class = H5Tget_class(dtype);
772 H5Gclose(s_group_id);
774 string msg =
"cannot get the datatype class of HDF5 dataset ";
775 msg += string(ACOS_L2S_DSET_NAME);
776 throw InternalErr(__FILE__, __LINE__, msg);
779 if (ty_class != H5T_STRING) {
782 H5Gclose(s_group_id);
784 string msg =
"This dataset must be a H5T_STRING class ";
785 msg += string(ACOS_L2S_DSET_NAME);
786 throw InternalErr(__FILE__, __LINE__, msg);
791 if ((dspace = H5Dget_space(s_dset_id)) < 0) {
794 H5Gclose(s_group_id);
796 string msg =
"cannot get the the dataspace of HDF5 dataset ";
797 msg += string(ACOS_L2S_DSET_NAME);
798 throw InternalErr(__FILE__, __LINE__, msg);
801 hssize_t num_elem = 0;
802 if ((num_elem = H5Sget_simple_extent_npoints(dspace))<=0) {
806 H5Gclose(s_group_id);
808 string msg =
"cannot get the the number of points of HDF5 dataset ";
809 msg += string(ACOS_L2S_DSET_NAME);
810 throw InternalErr(__FILE__, __LINE__, msg);
813 size_t dtype_size = H5Tget_size(dtype);
814 if (dtype_size <= 0) {
818 H5Gclose(s_group_id);
820 string msg =
"cannot get the the dataspace of HDF5 dataset ";
821 msg += string(ACOS_L2S_DSET_NAME);
822 throw InternalErr(__FILE__, __LINE__, msg);
825 size_t total_data_size = num_elem * H5Tget_size(dtype);
827 if (H5Tis_variable_str(dtype)) {
830 vector<char>temp_buf;
831 temp_buf.resize(total_data_size);
834 if (H5Dread(s_dset_id,dtype,H5S_ALL,H5S_ALL,H5P_DEFAULT, &temp_buf[0])<0){
838 H5Gclose(s_group_id);
840 string msg =
"cannot get the the dataspace of HDF5 dataset ";
841 msg += string(ACOS_L2S_DSET_NAME);
842 throw InternalErr(__FILE__, __LINE__, msg);
845 char *temp_bp = &temp_buf[0];
846 char *onestring =
NULL;
847 string total_string=
"";
849 for (
int temp_i = 0; temp_i <num_elem; temp_i++) {
852 onestring =*(
char **)temp_bp;
855 if (onestring !=
NULL) {
856 string tempstring(onestring);
857 total_string+=tempstring;
861 temp_bp += dtype_size;
865 H5Dvlen_reclaim(dtype,dspace,H5P_DEFAULT,&temp_buf[0]);
871 H5Gclose(s_group_id);
873 if (total_string.compare(ACOS_L2S_ATTR_VALUE) ==0)
877 vector<char> temp_buf(total_data_size+1);
878 if (H5Dread(s_dset_id,dtype,H5S_ALL,H5S_ALL,H5P_DEFAULT, &temp_buf[0])<0){
882 H5Gclose(s_group_id);
884 string msg =
"cannot data of HDF5 dataset ";
885 msg += string(ACOS_L2S_DSET_NAME);
886 throw InternalErr(__FILE__, __LINE__, msg);
889 string total_string(temp_buf.begin(),temp_buf.end()-1);
893 H5Gclose(s_group_id);
896 if (0 == total_string.compare(ACOS_L2S_ATTR_VALUE))
902 else if (0 == has_acos_dset) {
903 H5Gclose(s_group_id);
907 string msg =
"Fail to determine if the HDF5 link ";
908 msg += string(ACOS_L2S_DSET_NAME);
910 H5Gclose(s_group_id);
912 throw InternalErr(__FILE__, __LINE__, msg);
917 else if (0 == has_smac_group)
920 string msg =
"Fail to determine if the link ";
921 msg += string(SMAC2S_META_GROUP_NAME);
922 msg +=
" exists or not ";
924 throw InternalErr(__FILE__, __LINE__, msg);
931 hid_t s_attr_id = -1;
932 if ((s_attr_id = H5Aopen_by_name(s_root_id,
".",s_attr_name,
933 H5P_DEFAULT, H5P_DEFAULT)) <0) {
934 string msg =
"Cannot open the HDF5 attribute ";
935 msg += string(s_attr_name);
937 throw InternalErr(__FILE__, __LINE__, msg);
940 hid_t attr_type = -1;
941 if ((attr_type = H5Aget_type(s_attr_id)) < 0) {
942 string msg =
"cannot get the attribute datatype for the attribute ";
943 msg += string(s_attr_name);
948 hid_t attr_space = -1;
949 if ((attr_space = H5Aget_space(s_attr_id)) < 0) {
950 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
951 msg += string(s_attr_name);
955 throw InternalErr(__FILE__, __LINE__, msg);
958 int num_elm = H5Sget_simple_extent_npoints(attr_space);
960 string msg =
"cannot get the number for the attribute ";
961 msg += string(s_attr_name);
964 H5Sclose(attr_space);
966 throw InternalErr(__FILE__, __LINE__, msg);
969 size_t atype_size = H5Tget_size(attr_type);
970 if (atype_size <= 0) {
971 string msg =
"cannot obtain the datatype size of the attribute ";
972 msg += string(s_attr_name);
975 H5Sclose(attr_space);
977 throw InternalErr(__FILE__, __LINE__, msg);
980 vector<char> temp_buf(atype_size*num_elm+1);
982 if (H5Aread(s_attr_id,attr_type, &temp_buf[0])<0){
983 string msg =
"cannot retrieve the value of the attribute ";
984 msg += string(s_attr_name);
987 H5Sclose(attr_space);
989 throw InternalErr(__FILE__, __LINE__, msg);
993 string temp_attr_value(temp_buf.begin(),temp_buf.end());
995 size_t temp_null_pos = temp_attr_value.find_first_of(
'\0');
996 s_attr_value = temp_attr_value.substr(0,temp_null_pos);
999 H5Sclose(attr_space);
1000 H5Aclose(s_attr_id);
bool check_aquarius(hid_t s_root_id, int &s_level)
bool check_measure_ozone(hid_t s_root_id)
static class NCMLUtil overview
This file includes functions to identify different NASA HDF5 products. Current supported products inc...
bool check_gpm_l1(hid_t s_root_id)
bool check_gpms_l3(hid_t s_root_id)
void obtain_gm_attr_value(hid_t s_root_id, const char *s_attr_name, string &s_attr_value)
bool check_gpmm_l3(hid_t s_root_id)
bool check_obpg(hid_t s_root_id, int &s_level)
bool check_smap_acosl2s(hid_t s_root_id, int which_pro)
H5GCFProduct check_product(hid_t file_id)
bool check_measure_seawifs(hid_t s_root_id, int &s_lflag)