33#include <libdap/InternalErr.h>
35#include "h5apicompatible.h"
39H5CFModule check_module(hid_t fileid) {
41 if (
true == check_eos5(fileid))
43 else if(
true == check_jpss(fileid))
50bool check_eos5(hid_t file_id) {
53 string eos5_check_group =
"/HDFEOS INFORMATION";
54 string eos5_check_attr =
"HDFEOSVersion";
55 string eos5_dataset =
"StructMetadata.0";
56 htri_t has_eos_group = -1;
57 bool eos5_module_fields =
true;
60 has_eos_group = H5Lexists(file_id,eos5_check_group.c_str(),H5P_DEFAULT);
62 if (has_eos_group > 0){
64 hid_t eos_group_id = -1;
65 htri_t has_eos_attr = -1;
68 if((eos_group_id = H5Gopen(file_id, eos5_check_group.c_str(),H5P_DEFAULT))<0) {
70 string msg =
"cannot open the HDF5 group ";
71 msg += eos5_check_group;
72 throw InternalErr(__FILE__, __LINE__, msg);
76 has_eos_attr = H5Aexists(eos_group_id, eos5_check_attr.c_str());
78 if (has_eos_attr >0) {
82 htri_t has_eos_dset = -1;
85 has_eos_dset = H5Lexists(eos_group_id,eos5_dataset.c_str(),H5P_DEFAULT);
86 if (has_eos_dset >0) {
92 eos5_module_fields = check_eos5_module_fields(file_id);
93 return eos5_module_fields;
95 else if(0 == has_eos_dset)
98 string msg =
"Fail to determine if the HDF5 dataset ";
101 H5Gclose(eos_group_id);
102 throw InternalErr(__FILE__, __LINE__, msg);
105 else if(0 == has_eos_attr)
108 string msg =
"Fail to determine if the HDF5 attribute ";
109 msg += eos5_check_attr;
111 H5Gclose(eos_group_id);
112 throw InternalErr(__FILE__, __LINE__, msg);
115 else if( 0 == has_eos_group) {
119 string msg =
"Fail to determine if the HDF5 group ";
120 msg += eos5_check_group;
125 throw InternalErr(__FILE__, __LINE__, msg);
129bool check_jpss(hid_t fileid) {
134bool check_eos5_module_fields(hid_t fileid){
136 bool ret_value =
true;
137 string eos5_swath_group =
"/HDFEOS/SWATHS";
138 string eos5_grid_group =
"/HDFEOS/GRIDS";
139 string eos5_zas_group =
"/HDFEOS/ZAS";
140 bool swath_unsupported_dset =
false;
141 bool grid_unsupported_dset =
false;
142 bool zas_unsupported_dset =
false;
143 if(H5Lexists(fileid,eos5_swath_group.c_str(),H5P_DEFAULT)>0)
144 swath_unsupported_dset = grp_has_dset(fileid,eos5_swath_group);
145 if(swath_unsupported_dset ==
true)
148 if(H5Lexists(fileid,eos5_grid_group.c_str(),H5P_DEFAULT)>0)
149 grid_unsupported_dset = grp_has_dset(fileid,eos5_grid_group);
150 if(grid_unsupported_dset ==
true)
153 if(H5Lexists(fileid,eos5_zas_group.c_str(),H5P_DEFAULT)>0)
154 zas_unsupported_dset = grp_has_dset(fileid,eos5_zas_group);
155 if(zas_unsupported_dset ==
true)
163bool grp_has_dset(hid_t fileid,
const string & grp_path ) {
165 bool ret_value =
false;
167 if((pid = H5Gopen(fileid,grp_path.c_str(),H5P_DEFAULT))<0){
168 string msg =
"Unable to open the HDF5 group ";
170 throw InternalErr(__FILE__, __LINE__, msg);
175 if (H5Gget_info(pid, &g_info) < 0) {
177 string msg =
"Unable to obtain the HDF5 group info. for ";
179 throw InternalErr(__FILE__, __LINE__, msg);
182 hsize_t nelems = g_info.nlinks;
184 for (hsize_t i = 0; i < nelems; i++) {
188 if (H5OGET_INFO_BY_IDX(pid,
".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT) < 0) {
189 string msg =
"Cannot obtain the object info for the group";
191 throw InternalErr(__FILE__, __LINE__, msg);
194 if(oinfo.type == H5O_TYPE_DATASET) {
This class describes the different categories of HDF5 products for the CF option.