33 #include <InternalErr.h>
38 H5CFModule check_module(hid_t fileid) {
40 if (
true == check_eos5(fileid))
42 else if(
true == check_jpss(fileid))
49 bool check_eos5(hid_t file_id) {
52 string eos5_check_group =
"/HDFEOS INFORMATION";
53 string eos5_check_attr =
"HDFEOSVersion";
54 string eos5_dataset =
"StructMetadata.0";
55 htri_t has_eos_group = -1;
56 bool eos5_module_fields =
true;
59 has_eos_group = H5Lexists(file_id,eos5_check_group.c_str(),H5P_DEFAULT);
61 if (has_eos_group > 0){
63 hid_t eos_group_id = -1;
64 htri_t has_eos_attr = -1;
67 if((eos_group_id = H5Gopen(file_id, eos5_check_group.c_str(),H5P_DEFAULT))<0) {
69 string msg =
"cannot open the HDF5 group ";
70 msg += eos5_check_group;
71 throw InternalErr(__FILE__, __LINE__, msg);
75 has_eos_attr = H5Aexists(eos_group_id, eos5_check_attr.c_str());
77 if (has_eos_attr >0) {
81 htri_t has_eos_dset = -1;
84 has_eos_dset = H5Lexists(eos_group_id,eos5_dataset.c_str(),H5P_DEFAULT);
85 if (has_eos_dset >0) {
91 eos5_module_fields = check_eos5_module_fields(file_id);
92 return eos5_module_fields;
94 else if(0 == has_eos_dset)
97 string msg =
"Fail to determine if the HDF5 dataset ";
100 H5Gclose(eos_group_id);
101 throw InternalErr(__FILE__, __LINE__, msg);
104 else if(0 == has_eos_attr)
107 string msg =
"Fail to determine if the HDF5 attribute ";
108 msg += eos5_check_attr;
110 H5Gclose(eos_group_id);
111 throw InternalErr(__FILE__, __LINE__, msg);
114 else if( 0 == has_eos_group) {
118 string msg =
"Fail to determine if the HDF5 group ";
119 msg += eos5_check_group;
124 throw InternalErr(__FILE__, __LINE__, msg);
128 bool check_jpss(hid_t fileid) {
133 bool check_eos5_module_fields(hid_t fileid){
135 bool ret_value =
true;
136 string eos5_swath_group =
"/HDFEOS/SWATHS";
137 string eos5_grid_group =
"/HDFEOS/GRIDS";
138 string eos5_zas_group =
"/HDFEOS/ZAS";
139 bool swath_unsupported_dset =
false;
140 bool grid_unsupported_dset =
false;
141 bool zas_unsupported_dset =
false;
142 if(H5Lexists(fileid,eos5_swath_group.c_str(),H5P_DEFAULT)>0)
143 swath_unsupported_dset = grp_has_dset(fileid,eos5_swath_group);
144 if(swath_unsupported_dset ==
true)
147 if(H5Lexists(fileid,eos5_grid_group.c_str(),H5P_DEFAULT)>0)
148 grid_unsupported_dset = grp_has_dset(fileid,eos5_grid_group);
149 if(grid_unsupported_dset ==
true)
152 if(H5Lexists(fileid,eos5_zas_group.c_str(),H5P_DEFAULT)>0)
153 zas_unsupported_dset = grp_has_dset(fileid,eos5_zas_group);
154 if(zas_unsupported_dset ==
true)
162 bool grp_has_dset(hid_t fileid,
const string & grp_path ) {
164 bool ret_value =
false;
166 if((pid = H5Gopen(fileid,grp_path.c_str(),H5P_DEFAULT))<0){
167 string msg =
"Unable to open the HDF5 group ";
169 throw InternalErr(__FILE__, __LINE__, msg);
174 if (H5Gget_info(pid, &g_info) < 0) {
176 string msg =
"Unable to obtain the HDF5 group info. for ";
178 throw InternalErr(__FILE__, __LINE__, msg);
181 hsize_t nelems = g_info.nlinks;
183 for (hsize_t i = 0; i < nelems; i++) {
187 if (H5Oget_info_by_idx(pid,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT) < 0) {
188 string msg =
"Cannot obtain the object info for the group";
190 throw InternalErr(__FILE__, __LINE__, msg);
193 if(oinfo.type == H5O_TYPE_DATASET) {