33#include <TheBESKeys.h>
35#include <libdap/DDS.h>
36#include <libdap/DAS.h>
37#include <libdap/InternalErr.h>
39#include <libdap/escaping.h>
42const int MAX_NON_SCALE_SPECIAL_VALUE=65535;
45const int MIN_NON_SCALE_SPECIAL_VALUE=65500;
70 static void close_fileid(int32 sdfd,int32 file_id,int32 gridfd,int32 swathfd,
bool pass_fileid_key);
79 static std::string
escattr(std::string s);
84 static void Split (
const char *s,
int len,
char sep,
85 std::vector < std::string > &names);
88 static void Split (
const char *sz,
char sep,
89 std::vector < std::string > &names);
94 static bool insert_map(std::map<std::string,std::string>& m, std::string key, std::string val);
100 static void gen_unique_name(std::string &str,std::set<std::string>& namelist,
int&clash_index);
104 static void Handle_NameClashing(std::vector<std::string>&newobjnamelist,std::set<std::string>&objnameset);
107 static std::string
print_attr(int32,
int,
void*);
117 template <
typename T>
static void LatLon2DSubset (T* outlatlon,
int ydim,
int xdim, T* latlon,
const int32 * offset,
const int32 * count,
const int32 * step);
130#ifdef USE_HDFEOS2_LIB
143 static bool change_data_type(libdap::DAS & das, SOType scaletype,
const std::string & new_field_name);
149 static bool is_special_value(int32 dtype,
float fillvalue,
float realvalue);
152 static int check_geofile_dimmap(
const std::string & geofilename);
157 static bool is_modis_dimmap_nonll_field(std::string & fieldname);
160 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);
165 static void add_scale_offset_attrs(libdap::AttrTable* at,
const std::string& s_type,
float svalue_f,
double svalue_d,
bool add_offset_found,
166 const std::string& o_type,
float ovalue_f,
double ovalue_d);
168 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,
169 const std::string& o_type,
float ovalue_f,
double ovalue_d);
174 static void handle_modis_special_attrs_disable_scale_comp(libdap::AttrTable *at,
const string &filename,
bool is_grid,
const std::string &newfname, SOType scaletype);
179 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);
182 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);
185 static void handle_amsr_attrs(libdap::AttrTable *at);
189 static void obtain_grid_latlon_dim_info(
const HDFEOS2::GridDataset*,
string &,int32 &,
string &,int32 &);
193 static void add_cf_grid_mapping_attr(libdap::DAS &das,
const HDFEOS2::GridDataset*gdset,
const string& cf_projection,
194 const string & dim0name,int32 dim0size,
const string &dim1name,int32 dim1size);
197 static void add_cf_grid_cvs(libdap::DDS & dds,
const HDFEOS2::GridDataset *gdset);
200 static void add_cf_grid_cv_attrs(libdap::DAS &das,
const HDFEOS2::GridDataset *gdset);
206 static void check_obpg_global_attrs(
HDFSP::File*f,std::string & scaling,
float & slope,
bool &global_slope_flag,
float & intercept,
bool & global_intercept_flag);
211 static void add_obpg_special_attrs(
const HDFSP::File*f,libdap::DAS &das,
const HDFSP::SDField* spsds,
const std::string & scaling,
float&slope,
const bool &global_slope_flag,
float& intercept,
const bool &global_intercept_flag);
215 static void handle_otherhdf_special_attrs(
const HDFSP::File *f, libdap::DAS &das);
218 static void add_missing_cf_attrs(
const HDFSP::File*f,libdap::DAS &das);
221 static void handle_merra_ceres_attrs_with_bes_keys(
const HDFSP::File*f, libdap::DAS &das,
const std::string& filename);
224 static void handle_vdata_attrs_with_desc_key(
const HDFSP::File*f,libdap::DAS &das);
227 static void map_eos2_objects_attrs(libdap::DAS &das,
const string &filename);
228 static void map_eos2_one_object_attrs_wrapper(libdap::DAS &das,int32 file_id,int32 vgroup_id,
const string &vgroup_name,
bool is_grid);
229 static void map_eos2_one_object_attrs(libdap::DAS &das,int32 file_id,int32 obj_attr_group_id,
const string &vgroup_name);
232 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);
236 static void rev_str(
char *str,
int len);
239 static int int_to_str(
int,
char str[],
int);
242 static void dtoa(
double,
char *,
int);
245 static std::string get_double_str(
double,
int,
int);
248 static std::string get_int_str(
int);
252 static size_t write_vector_to_file(
const std::string &,
const vector<double> &,
size_t);
253 static ssize_t write_vector_to_file2(
const std::string &,
const vector<double> &,
size_t);
256 static ssize_t read_vector_from_file(
int fd,vector<double> &,
size_t);
259 static ssize_t read_buffer_from_file(
int fd,
void*buf,
size_t);
260 static std::string obtain_cache_fname(
const std::string & fprefix,
const std::string & fname,
const std::string &vname);
261 static size_t obtain_dds_cache_size(
const HDFSP::File*);
262 static void write_sp_sds_dds_cache(
const HDFSP::File*,FILE*,
size_t,
const std::string & fname);
263 static void read_sp_sds_dds_cache(FILE*,libdap::DDS * dds_ptr,
const std::string &filename,
const std::string &hdf_filename);
269INDEX_nD_TO_1D (
const std::vector < int32 > &dims,
270 const std::vector < int32 > &pos)
278 assert (dims.size () == pos.size ());
282 for (
unsigned int p = 0; p < pos.size (); p++) {
285 for (
unsigned int j = start; j < dims.size (); j++)
294static inline struct flock *lock(
int type) {
295 static struct flock lock;
296 lock.l_type = (short)type;
297 lock.l_whence = SEEK_SET;
300 lock.l_pid = getpid();
305static inline string get_errno() {
306 const char *s_err = strerror(errno);
310 return "Unknown error.";
331 vector<int> & stride,
333 std::vector<T> *poutput,
337 for(
int k=0; k<edge[index]; k++)
339 pos[index] = start[index] + k*stride[index];
341 subset(input, rank, dim, start, stride, edge, poutput,pos,index+1);
344 poutput->push_back(input[INDEX_nD_TO_1D( dim, pos)]);
One instance of this class represents one SDS object.
static short obtain_type_size(int32)
Obtain datatype size.
static bool insert_map(std::map< std::string, std::string > &m, std::string key, std::string val)
static std::string print_attr(int32, int, void *)
Print attribute values in string.
static std::string print_type(int32)
Print datatype in string.
static void gen_unique_name(std::string &str, std::set< std::string > &namelist, int &clash_index)
Obtain the unique name for the clashed names and save it to set namelist.
static void Handle_NameClashing(std::vector< std::string > &newobjnamelist)
General routines to handle name clashings.
static void correct_scale_offset_type(libdap::AttrTable *at)
static std::string get_CF_string(std::string s)
Change special characters to "_".
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
static std::string escattr(std::string s)
static void correct_fvalue_type(libdap::AttrTable *at, int32 dtype)
static void close_fileid(int32 sdfd, int32 file_id, int32 gridfd, int32 swathfd, bool pass_fileid_key)