56 if (
false == is_dap4())
57 throw InternalErr(__FILE__,__LINE__,
"HDF5 ENUM only maps to DAP4 ENUM.");
59 hid_t file_id = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
61 throw InternalErr(__FILE__,__LINE__,
"Fail to obtain the HDF5 file ID .");
65 dset_id = H5Dopen2(file_id,var_path.c_str(),H5P_DEFAULT);
69 throw InternalErr(__FILE__,__LINE__,
"Fail to obtain the dataset .");
72 hid_t dtypeid = H5Dget_type(dset_id);
76 throw InternalErr(__FILE__,__LINE__,
"Fail to obtain the datatype .");
79 if (H5T_ENUM != H5Tget_class(dtypeid)) {
82 throw InternalErr(__FILE__,__LINE__,
"Fail to obtain the datatype .");
85 hid_t base_type = H5Tget_super(dtypeid);
87 hid_t memtype = H5Tget_native_type(base_type, H5T_DIR_ASCEND);
89 close_objids(-1,base_type,dtypeid,dset_id,file_id);
90 throw InternalErr(__FILE__, __LINE__,
"Cannot obtain the native datatype.");
93 if (H5Tget_class(base_type) != H5T_INTEGER) {
94 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
95 throw InternalErr(__FILE__, __LINE__,
"We currently only support the case when the enum's base type is an integer.");
98 size_t dsize = H5Tget_size(base_type);
100 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
101 throw InternalErr(__FILE__, __LINE__,
102 "size of enum base data type is invalid");
105 H5T_sign_t sign = H5Tget_sign(base_type);
107 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
108 throw InternalErr(__FILE__, __LINE__,
109 "sign of enum base data type is invalid");
115 if (sign == H5T_SGN_NONE) {
117 if (H5Dread(dset_id,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
118 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
119 throw InternalErr(__FILE__, __LINE__,
120 "Cannot read the enum data for the unsigned char base type. ");
126 if (H5Dread(dset_id,H5T_NATIVE_SCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
127 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
128 throw InternalErr(__FILE__, __LINE__,
129 "Cannot read the enum data for the signed char base type. ");
136 if (sign == H5T_SGN_NONE) {
138 if (H5Dread(dset_id,H5T_NATIVE_USHORT,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
139 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
140 throw InternalErr(__FILE__, __LINE__,
141 "Cannot read the enum data for the 16-bit signed integer base type. ");
147 if (H5Dread(dset_id,H5T_NATIVE_SHORT,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
148 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
149 throw InternalErr(__FILE__, __LINE__,
150 "Cannot read the enum data for the 16-bit signed integer base type. ");
158 if (sign == H5T_SGN_NONE) {
160 if (H5Dread(dset_id,H5T_NATIVE_UINT,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
161 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
162 throw InternalErr(__FILE__, __LINE__,
163 "Cannot read the enum data for the 32-bit signed integer base type. ");
170 if (H5Dread(dset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
171 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
172 throw InternalErr(__FILE__, __LINE__,
173 "Cannot read the enum data for the 32-bit signed integer base type. ");
181 if (sign == H5T_SGN_NONE) {
183 if (H5Dread(dset_id,H5T_NATIVE_ULLONG,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
184 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
185 throw InternalErr(__FILE__, __LINE__,
186 "Cannot read the enum data for the 64-bit unsigned integer base type. ");
193 if (H5Dread(dset_id,H5T_NATIVE_LLONG,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val)<0) {
194 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
195 throw InternalErr(__FILE__, __LINE__,
196 "Cannot read the enum data for the 64-bit signed integer base type. ");
203 close_objids(memtype,base_type,dtypeid,dset_id,file_id);
204 throw InternalErr(__FILE__, __LINE__,
"The enum base type size is not within the currently supported values.");
207 close_objids(memtype,base_type,dtypeid,dset_id,file_id);