27 #ifdef USE_HDFEOS2_LIB
28 #include "HdfEosDef.h"
33 #include <TheBESKeys.h>
37 #include <InternalErr.h>
42 const int MAX_NON_SCALE_SPECIAL_VALUE=65535;
45 const int MIN_NON_SCALE_SPECIAL_VALUE=65500;
69 static void close_fileid(int32 sdfd,int32 file_id,int32 gridfd,int32 swathfd,
bool pass_fileid_key);
78 static std::string
escattr(std::string s);
83 static void Split (
const char *s,
int len,
char sep,
84 std::vector < std::string > &names);
87 static void Split (
const char *sz,
char sep,
88 std::vector < std::string > &names);
93 static bool insert_map(std::map<std::string,std::string>& m, std::string key, std::string val);
99 static void gen_unique_name(std::string &str,std::set<std::string>& namelist,
int&clash_index);
103 static void Handle_NameClashing(std::vector<std::string>&newobjnamelist,std::set<std::string>&objnameset);
106 static std::string
print_attr(int32,
int,
void*);
116 template <
typename T>
static void LatLon2DSubset (T* outlatlon,
int ydim,
int xdim, T* latlon, int32 * offset, int32 * count, int32 * step);
129 #ifdef USE_HDFEOS2_LIB
142 static bool change_data_type(libdap::DAS & das, SOType scaletype,
const std::string & new_field_name);
148 static bool is_special_value(int32 dtype,
float fillvalue,
float realvalue);
151 static int check_geofile_dimmap(
const std::string & geofilename);
156 static bool is_modis_dimmap_nonll_field(std::string & fieldname);
159 static void obtain_dimmap_info(
const std::string& filename, HDFEOS2::Dataset*dataset,std::vector<struct dimmap_entry>& dimmaps, std::string & modis_geofilename,
bool &geofile_nas_dimmap);
164 static void add_scale_offset_attrs(libdap::AttrTable* at,
const std::string& s_type,
float svalue_f,
double svalue_d,
bool add_offset_found,
165 const std::string& o_type,
float ovalue_f,
double ovalue_d);
167 static void add_scale_str_offset_attrs(libdap::AttrTable* at,
const std::string& s_type,
const std::string& s_value_str,
bool add_offset_found,
168 const std::string& o_type,
float ovalue_f,
double ovalue_d);
173 static void handle_modis_special_attrs_disable_scale_comp(libdap::AttrTable *at,
const string &filename,
bool is_grid,
const std::string &newfname, SOType scaletype);
178 static void handle_modis_special_attrs(libdap::AttrTable *at,
const std::string &filename,
bool is_grid,
const std::string & newfname, SOType scaletype,
bool gridname_change_valid_range,
bool changedtype,
bool &change_fvtype);
181 static void handle_modis_vip_special_attrs(
const std::string& valid_range_value,
const std::string& scale_factor_value,
float& valid_min,
float & valid_max);
184 static void handle_amsr_attrs(libdap::AttrTable *at);
188 static void obtain_grid_latlon_dim_info(HDFEOS2::GridDataset*,
string &,int32 &,
string &,int32 &);
192 static void add_cf_grid_mapping_attr(libdap::DAS &das, HDFEOS2::GridDataset*gdset,
const string& cf_projection,
193 const string & dim0name,int32 dim0size,
const string &dim1name,int32 dim1size);
196 static void add_cf_grid_cvs(libdap::DDS & dds, HDFEOS2::GridDataset *gdset);
199 static void add_cf_grid_cv_attrs(libdap::DAS &das, HDFEOS2::GridDataset *gdset);
205 static void check_obpg_global_attrs(
HDFSP::File*f,std::string & scaling,
float & slope,
bool &global_slope_flag,
float & intercept,
bool & global_intercept_flag);
210 static void add_obpg_special_attrs(
HDFSP::File*f,libdap::DAS &das,
HDFSP::SDField* spsds,std::string & scaling,
float&slope,
bool &global_slope_flag,
float& intercept,
bool &global_intercept_flag);
214 static void handle_otherhdf_special_attrs(
HDFSP::File *f, libdap::DAS &das);
217 static void add_missing_cf_attrs(
HDFSP::File*f,libdap::DAS &das);
220 static void handle_merra_ceres_attrs_with_bes_keys(
HDFSP::File*f, libdap::DAS &das,
const std::string& filename);
223 static void handle_vdata_attrs_with_desc_key(
HDFSP::File*f,libdap::DAS &das);
226 static void map_eos2_objects_attrs(libdap::DAS &das,
const string &filename);
227 static void map_eos2_one_object_attrs_wrapper(libdap::DAS &das,int32 file_id,int32 vgroup_id,
const string &vgroup_name,
bool is_grid);
228 static void map_eos2_one_object_attrs(libdap::DAS &das,int32 file_id,int32 obj_attr_group_id,
const string &vgroup_name);
231 static void parser_trmm_v7_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);
235 static void rev_str(
char *str,
int len);
238 static int int_to_str(
int,
char str[],
int);
241 static void dtoa(
double,
char *,
int);
244 static std::string get_double_str(
double,
int,
int);
247 static std::string get_int_str(
int);
251 static size_t write_vector_to_file(
const std::string &,
const vector<double> &,
size_t);
252 static ssize_t write_vector_to_file2(
const std::string &,
const vector<double> &,
size_t);
255 static ssize_t read_vector_from_file(
int fd,vector<double> &,
size_t);
258 static ssize_t read_buffer_from_file(
int fd,
void*buf,
size_t);
259 static std::string obtain_cache_fname(
const std::string & fprefix,
const std::string & fname,
const std::string &vname);
261 static void write_sp_sds_dds_cache(
HDFSP::File*,FILE*,
size_t,
const std::string & fname);
262 static void read_sp_sds_dds_cache(FILE*,libdap::DDS * dds_ptr,
const std::string &filename,
const std::string &hdf_filename);
268 INDEX_nD_TO_1D (
const std::vector < int32 > &dims,
269 const std::vector < int32 > &pos)
275 assert (dims.size () == pos.size ());
279 for (
unsigned int p = 0; p < pos.size (); p++) {
282 for (
unsigned int j = start; j < dims.size (); j++)
291 static inline struct flock *lock(
int type) {
292 static struct flock lock;
294 lock.l_whence = SEEK_SET;
297 lock.l_pid = getpid();
302 static inline string get_errno() {
303 char *s_err = strerror(errno);
307 return "Unknown error.";
328 vector<int> & stride,
330 std::vector<T> *poutput,
334 for(
int k=0; k<edge[index]; k++)
336 pos[index] = start[index] + k*stride[index];
338 subset(input, rank, dim, start, stride, edge, poutput,pos,index+1);
341 poutput->push_back(input[INDEX_nD_TO_1D( dim, pos)]);