36 #include<InternalErr.h>
46 switch (H5Tget_class(h5_type_id)) {
49 size = H5Tget_size(h5_type_id);
50 sign = H5Tget_sign(h5_type_id);
53 if (sign == H5T_SGN_2)
59 if (sign == H5T_SGN_2)
65 if (sign == H5T_SGN_2)
71 if (sign == H5T_SGN_2)
79 size = H5Tget_size(h5_type_id);
86 if (H5Tis_variable_str(h5_type_id))
118 size_t last_fslash_pos = s.find_last_of(
"/");
119 if (string::npos != last_fslash_pos &&
120 last_fslash_pos != (s.size()-1))
121 ret_str=s.substr(last_fslash_pos+1);
127 string temp_sect_str =
"";
128 string temp_sect_newstr =
"";
131 for (
int i = 0; i < num_sect; i++) {
133 if (i != (num_sect-1))
134 temp_sect_str = s.substr(i*sect_size,sect_size);
136 temp_sect_str = s.substr((num_sect-1)*sect_size,s.size()-(num_sect-1)*sect_size);
140 if (H5T_STR_NULLTERM == H5Tget_strpad(ty_id))
141 temp_pos = temp_sect_str.find_first_of(
'\0');
142 else if (H5T_STR_SPACEPAD == H5Tget_strpad(ty_id))
143 temp_pos = temp_sect_str.find_last_not_of(
' ')+1;
144 else temp_pos = temp_sect_str.find_last_not_of(
'0')+1;
146 if (temp_pos != string::npos) {
152 if (H5T_STR_SPACEPAD == H5Tget_strpad(ty_id)) {
154 if (temp_pos == temp_sect_str.size())
155 temp_sect_newstr = temp_sect_str +
" ";
157 temp_sect_newstr = temp_sect_str.substr(0,temp_pos+1);
159 sect_newsize[i] = temp_pos +1;
162 temp_sect_newstr = temp_sect_str.substr(0,temp_pos);
163 sect_newsize[i] = temp_pos ;
170 temp_sect_newstr = temp_sect_str;
175 if (H5T_STR_SPACEPAD == H5Tget_strpad(ty_id)) {
176 temp_sect_newstr.resize(temp_sect_str.size()+1);
177 temp_sect_newstr.append(1,
' ');
178 sect_newsize[i] = sect_size + 1;
181 sect_newsize[i] = sect_size;
183 final_str+=temp_sect_newstr;
193 pair<set<string>::iterator,
bool> ret;
195 stringstream sclash_index;
196 sclash_index << clash_index;
197 newstr = str + sclash_index.str();
199 ret = namelist.insert(newstr);
200 if (
false == ret.second) {
202 gen_unique_name(str,namelist,clash_index);
215 for (
int i = 0, j = 0; j <= len; ++j) {
216 if ((j == len && len) || s[j] == sep) {
217 string elem(s + i, j - i);
218 names.push_back(elem);
230 Split(sz, (
int)strlen(sz), sep, names);
234 int& latsize,
int&lonsize,
235 float& lat_start,
float& lon_start,
236 float& lat_res,
float& lon_res,
237 bool check_reg_orig ){
243 float lat_north = 0.;
244 float lat_south = 0.;
248 vector<string> ind_elems;
253 if(ind_elems.size()!=10)
254 throw InternalErr(__FILE__,__LINE__,
"The number of elements in the TRMM level 3 GridHeader is not right.");
256 if(
false == check_reg_orig) {
257 if (0 != ind_elems[1].find(
"Registration=CENTER"))
258 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid registration is not center.");
261 if (0 == ind_elems[2].find(
"LatitudeResolution")){
263 size_t equal_pos = ind_elems[2].find_first_of(
'=');
264 if(string::npos == equal_pos)
265 throw InternalErr(__FILE__,__LINE__,
"Cannot find latitude resolution for TRMM level 3 products");
267 size_t scolon_pos = ind_elems[2].find_first_of(
';');
268 if(string::npos == scolon_pos)
269 throw InternalErr(__FILE__,__LINE__,
"Cannot find latitude resolution for TRMM level 3 products");
270 if (equal_pos < scolon_pos){
272 string latres_str = ind_elems[2].substr(equal_pos+1,scolon_pos-equal_pos-1);
273 lat_res = strtof(latres_str.c_str(),
NULL);
276 throw InternalErr(__FILE__,__LINE__,
"latitude resolution is not right for TRMM level 3 products");
279 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid LatitudeResolution doesn't exist.");
281 if (0 == ind_elems[3].find(
"LongitudeResolution")){
283 size_t equal_pos = ind_elems[3].find_first_of(
'=');
284 if(string::npos == equal_pos)
285 throw InternalErr(__FILE__,__LINE__,
"Cannot find longitude resolution for TRMM level 3 products");
287 size_t scolon_pos = ind_elems[3].find_first_of(
';');
288 if(string::npos == scolon_pos)
289 throw InternalErr(__FILE__,__LINE__,
"Cannot find longitude resolution for TRMM level 3 products");
290 if (equal_pos < scolon_pos){
291 string lonres_str = ind_elems[3].substr(equal_pos+1,scolon_pos-equal_pos-1);
292 lon_res = strtof(lonres_str.c_str(),
NULL);
295 throw InternalErr(__FILE__,__LINE__,
"longitude resolution is not right for TRMM level 3 products");
298 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid LongitudeResolution doesn't exist.");
300 if (0 == ind_elems[4].find(
"NorthBoundingCoordinate")){
302 size_t equal_pos = ind_elems[4].find_first_of(
'=');
303 if(string::npos == equal_pos)
304 throw InternalErr(__FILE__,__LINE__,
"Cannot find latitude resolution for TRMM level 3 products");
306 size_t scolon_pos = ind_elems[4].find_first_of(
';');
307 if(string::npos == scolon_pos)
308 throw InternalErr(__FILE__,__LINE__,
"Cannot find latitude resolution for TRMM level 3 products");
309 if (equal_pos < scolon_pos){
310 string north_bounding_str = ind_elems[4].substr(equal_pos+1,scolon_pos-equal_pos-1);
311 lat_north = strtof(north_bounding_str.c_str(),
NULL);
314 throw InternalErr(__FILE__,__LINE__,
"NorthBoundingCoordinate is not right for TRMM level 3 products");
318 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid NorthBoundingCoordinate doesn't exist.");
320 if (0 == ind_elems[5].find(
"SouthBoundingCoordinate")){
322 size_t equal_pos = ind_elems[5].find_first_of(
'=');
323 if(string::npos == equal_pos)
324 throw InternalErr(__FILE__,__LINE__,
"Cannot find south bound coordinate for TRMM level 3 products");
326 size_t scolon_pos = ind_elems[5].find_first_of(
';');
327 if(string::npos == scolon_pos)
328 throw InternalErr(__FILE__,__LINE__,
"Cannot find south bound coordinate for TRMM level 3 products");
329 if (equal_pos < scolon_pos){
330 string lat_south_str = ind_elems[5].substr(equal_pos+1,scolon_pos-equal_pos-1);
331 lat_south = strtof(lat_south_str.c_str(),
NULL);
334 throw InternalErr(__FILE__,__LINE__,
"south bound coordinate is not right for TRMM level 3 products");
338 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid SouthBoundingCoordinate doesn't exist.");
340 if (0 == ind_elems[6].find(
"EastBoundingCoordinate")){
342 size_t equal_pos = ind_elems[6].find_first_of(
'=');
343 if(string::npos == equal_pos)
344 throw InternalErr(__FILE__,__LINE__,
"Cannot find south bound coordinate for TRMM level 3 products");
346 size_t scolon_pos = ind_elems[6].find_first_of(
';');
347 if(string::npos == scolon_pos)
348 throw InternalErr(__FILE__,__LINE__,
"Cannot find south bound coordinate for TRMM level 3 products");
349 if (equal_pos < scolon_pos){
350 string lon_east_str = ind_elems[6].substr(equal_pos+1,scolon_pos-equal_pos-1);
351 lon_east = strtof(lon_east_str.c_str(),
NULL);
354 throw InternalErr(__FILE__,__LINE__,
"south bound coordinate is not right for TRMM level 3 products");
358 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid EastBoundingCoordinate doesn't exist.");
360 if (0 == ind_elems[7].find(
"WestBoundingCoordinate")){
362 size_t equal_pos = ind_elems[7].find_first_of(
'=');
363 if(string::npos == equal_pos)
364 throw InternalErr(__FILE__,__LINE__,
"Cannot find south bound coordinate for TRMM level 3 products");
366 size_t scolon_pos = ind_elems[7].find_first_of(
';');
367 if(string::npos == scolon_pos)
368 throw InternalErr(__FILE__,__LINE__,
"Cannot find south bound coordinate for TRMM level 3 products");
369 if (equal_pos < scolon_pos){
370 string lon_west_str = ind_elems[7].substr(equal_pos+1,scolon_pos-equal_pos-1);
371 lon_west = strtof(lon_west_str.c_str(),
NULL);
376 throw InternalErr(__FILE__,__LINE__,
"south bound coordinate is not right for TRMM level 3 products");
380 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid WestBoundingCoordinate doesn't exist.");
382 if (
false == check_reg_orig) {
383 if (0 != ind_elems[8].find(
"Origin=SOUTHWEST"))
384 throw InternalErr(__FILE__,__LINE__,
"The TRMM grid origin is not SOUTHWEST.");
389 latsize =(int)((lat_north-lat_south)/lat_res);
390 lonsize =(int)((lon_east-lon_west)/lon_res);
391 lat_start = lat_south;
392 lon_start = lon_west;
396 if(
false == pass_fileid) {
static void close_fileid(hid_t, bool)
static void parser_gpm_l3_gridheader(const std::vector< char > &value, int &latsize, int &lonsize, float &lat_start, float &lon_start, float &lat_res, float &lon_res, bool check_reg_orig)
static class NCMLUtil overview
static void gen_unique_name(std::string &str, std::set< std::string > &namelist, int &clash_index)
static std::string obtain_string_after_lastslash(const std::string s)
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
From a string separated by a separator to a list of string, for example, split "ab,c" to {"ab","c"}.
This file includes several helper functions for translating HDF5 to CF-compliant. ...
static bool cf_strict_support_type(H5DataType dtype)
static std::string trim_string(hid_t dtypeid, const std::string s, int num_sect, size_t section_size, std::vector< size_t > §_newsize)
Trim the string with many NULL terms or garbage characters to simply a string with a NULL terminator...
static H5DataType H5type_to_H5DAPtype(hid_t h5_type_id)
Map HDF5 Datatype to the intermediate H5DAPtype for the future use.