37 #include "InternalErr.h"
49 BESDEBUG(
"h5",
"Coming to HDFEOS5CFSpecialCVArray read "<<endl);
50 string check_pass_fileid_key_str=
"H5.EnablePassFileID";
51 bool check_pass_fileid_key =
false;
60 throw InternalErr (__FILE__, __LINE__,
61 "The number of dimension of the variable is negative.");
75 if(
false == check_pass_fileid_key) {
76 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
79 eherr <<
"HDF5 File " << filename
80 <<
" cannot be opened. "<<endl;
81 throw InternalErr (__FILE__, __LINE__, eherr.str ());
87 throw InternalErr (__FILE__, __LINE__,
"Cannot obtain TES CV attribute");
90 string group_name = varname.substr(0,varname.size()-cv_name.size());
92 size_t cv_name_sep_pos = cv_name.find_first_of(
'_',0);
94 if (string::npos == cv_name_sep_pos) {
97 throw InternalErr (__FILE__, __LINE__,
"Cannot obtain TES CV attribute");
99 string cv_attr_name = cv_name.substr(0,cv_name_sep_pos);
101 htri_t swath_link_exist = H5Lexists(fileid,group_name.c_str(),H5P_DEFAULT);
103 if (swath_link_exist <= 0) {
106 throw InternalErr (__FILE__, __LINE__,
"The TES swath link doesn't exist");
109 htri_t swath_exist = H5Oexists_by_name(fileid,group_name.c_str(),H5P_DEFAULT);
110 if (swath_exist <= 0) {
113 throw InternalErr (__FILE__, __LINE__,
"The TES swath doesn't exist");
116 htri_t cv_attr_exist = H5Aexists_by_name(fileid,group_name.c_str(),cv_attr_name.c_str(),H5P_DEFAULT);
117 if (cv_attr_exist <= 0) {
120 throw InternalErr (__FILE__, __LINE__,
"The TES swath CV attribute doesn't exist");
123 hid_t cv_attr_id = H5Aopen_by_name(fileid,group_name.c_str(),cv_attr_name.c_str(),H5P_DEFAULT,H5P_DEFAULT);
127 throw InternalErr (__FILE__, __LINE__,
"Cannot obtain the TES CV attribute id");
130 hid_t attr_type = -1;
131 if ((attr_type = H5Aget_type(cv_attr_id)) < 0) {
132 string msg =
"cannot get the attribute datatype for the attribute ";
134 H5Aclose(cv_attr_id);
137 throw InternalErr(__FILE__, __LINE__, msg);
140 hid_t attr_space = -1;
141 if ((attr_space = H5Aget_space(cv_attr_id)) < 0) {
142 string msg =
"cannot get the hdf5 dataspace id for the attribute ";
145 H5Aclose(cv_attr_id);
148 throw InternalErr(__FILE__, __LINE__, msg);
151 int attr_num_elm = 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);
160 throw InternalErr(__FILE__, __LINE__, msg);
163 if (attr_num_elm != (total_num_elm -1)) {
164 string msg =
"cannot get the number for the attribute ";
167 H5Aclose(cv_attr_id);
168 H5Sclose(attr_space);
171 throw InternalErr(__FILE__, __LINE__, msg);
175 string msg =
"cannot get the number for the attribute ";
178 H5Aclose(cv_attr_id);
179 H5Sclose(attr_space);
182 throw InternalErr(__FILE__, __LINE__, msg);
185 hid_t attr_mem_type = -1;
186 if ((attr_mem_type = H5Tget_native_type(attr_type,H5T_DIR_ASCEND)) < 0) {
187 string msg =
"cannot get the attribute datatype for the attribute ";
190 H5Aclose(cv_attr_id);
191 H5Sclose(attr_space);
194 throw InternalErr(__FILE__, __LINE__, msg);
197 if (nelms <= 0 || (total_num_elm -1) <=0 ||total_num_elm < 0) {
198 H5Tclose(attr_mem_type);
200 H5Aclose(cv_attr_id);
201 H5Sclose(attr_space);
204 throw InternalErr(__FILE__,__LINE__,
205 "Number of elements must be greater than 0");
211 vector<float>orig_val;
212 orig_val.resize(total_num_elm-1);
214 vector<float>total_val;
215 total_val.resize(total_num_elm);
218 if (H5Aread(cv_attr_id,attr_mem_type, (
void*)&orig_val[0])<0){
219 string msg =
"cannot retrieve the value of the attribute ";
221 H5Tclose(attr_mem_type);
223 H5Aclose(cv_attr_id);
224 H5Sclose(attr_space);
245 total_val[0] = 1.1*orig_val[0] - 0.1*orig_val[1];
246 for (
int i = 1; i < total_num_elm; i++)
247 total_val[i] = orig_val[i-1];
252 for (
int i = 0; i <nelms; i++)
253 val[i] = total_val[offset[0]+i*step[0]];
255 set_value((dods_float32*)&val[0], nelms);
257 H5Tclose(attr_mem_type);
258 H5Aclose(cv_attr_id);
259 H5Sclose(attr_space);
static void close_fileid(hid_t, bool)
This class specifies the retrieval of special coordinate variable values for HDF-EOS5 products...
HDFEOS5CFSpecialCVArray(int rank, const string &filename, const hid_t fileid, H5DataType dtype, int num_elm, const string &varfullpath, const string &n="", BaseType *v=0)
static bool check_beskeys(const string key)
int format_constraint(int *cor, int *step, int *edg)
static std::string obtain_string_after_lastslash(const std::string s)
virtual BaseType * ptr_duplicate()
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static H5DataType H5type_to_H5DAPtype(hid_t h5_type_id)
Map HDF5 Datatype to the intermediate H5DAPtype for the future use.