36#include <libdap/InternalErr.h>
44BaseType *HDFEOS5CFSpecialCVArray::ptr_duplicate()
46 auto HDFEOS5CFSpecialCVArray_unique = make_unique<HDFEOS5CFSpecialCVArray>(*
this);
47 return HDFEOS5CFSpecialCVArray_unique.release();
50bool HDFEOS5CFSpecialCVArray::read(){
52 BESDEBUG(
"h5",
"Coming to HDFEOS5CFSpecialCVArray read "<<endl);
54 read_data_NOT_from_mem_cache(
false,
nullptr);
59void HDFEOS5CFSpecialCVArray::read_data_NOT_from_mem_cache(
bool ,
void*) {
61 BESDEBUG(
"h5",
"Coming to HDFEOS5CFSpecialCVArray: read_data_NOT_from_mem_cache "<<endl);
63 bool check_pass_fileid_key = HDF5RequestHandler::get_pass_fileid();
65 vector<int64_t> offset;
66 vector<int64_t> count;
71 throw InternalErr (__FILE__, __LINE__,
72 "The number of dimension of the variable is <=0 for this array.");
79 nelms = format_constraint (offset.data(), step.data(), count.data());
83 if(
false == check_pass_fileid_key) {
84 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
87 eherr <<
"HDF5 File " << filename
88 <<
" cannot be opened. "<<endl;
89 throw InternalErr (__FILE__, __LINE__, eherr.str ());
92 string cv_name = HDF5CFUtil::obtain_string_after_lastslash(varname);
94 throw InternalErr (__FILE__, __LINE__,
"Cannot obtain TES CV attribute");
97 string group_name = varname.substr(0,varname.size()-cv_name.size());
99 size_t cv_name_sep_pos = cv_name.find_first_of(
'_',0);
101 if (string::npos == cv_name_sep_pos) {
102 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
103 throw InternalErr (__FILE__, __LINE__,
"Cannot obtain TES CV attribute");
105 string cv_attr_name = cv_name.substr(0,cv_name_sep_pos);
107 htri_t swath_link_exist = H5Lexists(fileid,group_name.c_str(),H5P_DEFAULT);
109 if (swath_link_exist <= 0) {
110 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
111 throw InternalErr (__FILE__, __LINE__,
"The TES swath link doesn't exist");
114 htri_t swath_exist = H5Oexists_by_name(fileid,group_name.c_str(),H5P_DEFAULT);
115 if (swath_exist <= 0) {
116 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
117 throw InternalErr (__FILE__, __LINE__,
"The TES swath doesn't exist");
120 htri_t cv_attr_exist = H5Aexists_by_name(fileid,group_name.c_str(),cv_attr_name.c_str(),H5P_DEFAULT);
121 if (cv_attr_exist <= 0) {
122 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
123 throw InternalErr (__FILE__, __LINE__,
"The TES swath CV attribute doesn't exist");
126 hid_t cv_attr_id = H5Aopen_by_name(fileid,group_name.c_str(),cv_attr_name.c_str(),H5P_DEFAULT,H5P_DEFAULT);
128 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
129 throw InternalErr (__FILE__, __LINE__,
"Cannot obtain the TES CV attribute id");
132 hid_t attr_type = -1;
133 if ((attr_type = H5Aget_type(cv_attr_id)) < 0) {
134 string msg =
"cannot get the attribute datatype for the attribute ";
136 H5Aclose(cv_attr_id);
137 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
138 throw InternalErr(__FILE__, __LINE__, msg);
141 hid_t attr_space = -1;
142 if ((attr_space = H5Aget_space(cv_attr_id)) < 0) {
143 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
146 H5Aclose(cv_attr_id);
147 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
148 throw InternalErr(__FILE__, __LINE__, msg);
151 auto attr_num_elm = (int)(H5Sget_simple_extent_npoints(attr_space));
152 if (0 == attr_num_elm ) {
153 string msg =
"cannot get the number for the attribute ";
156 H5Aclose(cv_attr_id);
157 H5Sclose(attr_space);
158 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
159 throw InternalErr(__FILE__, __LINE__, msg);
162 if (attr_num_elm != (total_num_elm -1)) {
163 string msg =
"cannot get the number for the attribute ";
166 H5Aclose(cv_attr_id);
167 H5Sclose(attr_space);
168 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
169 throw InternalErr(__FILE__, __LINE__, msg);
173 string msg =
"cannot get the number for the attribute ";
176 H5Aclose(cv_attr_id);
177 H5Sclose(attr_space);
178 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
179 throw InternalErr(__FILE__, __LINE__, msg);
182 hid_t attr_mem_type = -1;
183 if ((attr_mem_type = H5Tget_native_type(attr_type,H5T_DIR_ASCEND)) < 0) {
184 string msg =
"cannot get the attribute datatype for the attribute ";
187 H5Aclose(cv_attr_id);
188 H5Sclose(attr_space);
189 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
190 throw InternalErr(__FILE__, __LINE__, msg);
193 if (nelms <= 0 || (total_num_elm -1) <=0 ||total_num_elm < 0) {
194 H5Tclose(attr_mem_type);
196 H5Aclose(cv_attr_id);
197 H5Sclose(attr_space);
198 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
199 throw InternalErr(__FILE__,__LINE__,
200 "Number of elements must be greater than 0");
206 vector<float>orig_val;
207 orig_val.resize(total_num_elm-1);
209 vector<float>total_val;
210 total_val.resize(total_num_elm);
213 if (H5Aread(cv_attr_id,attr_mem_type, (
void*)orig_val.data())<0){
214 string msg =
"cannot retrieve the value of the attribute ";
216 H5Tclose(attr_mem_type);
218 H5Aclose(cv_attr_id);
219 H5Sclose(attr_space);
220 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
221 throw InternalErr(__FILE__, __LINE__, msg);
239 total_val[0] = 1.1F*orig_val[0] - 0.1F*orig_val[1];
240 for (
int i = 1; i < total_num_elm; i++)
241 total_val[i] = orig_val[i-1];
246 for (
int i = 0; i <nelms; i++)
247 val[i] = total_val[offset[0]+i*step[0]];
249 set_value_ll(val.data(), nelms);
251 H5Tclose(attr_mem_type);
252 H5Aclose(cv_attr_id);
253 H5Sclose(attr_space);
254 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
include the entry functions to execute the handlers
This class specifies the retrieval of special coordinate variable values for HDF-EOS5 products.
static H5DataType H5type_to_H5DAPtype(hid_t h5_type_id)
Map HDF5 Datatype to the intermediate H5DAPtype for the future use.