// // // C++ Implementation: %{MODULE} // // Description: // // // Author: %{AUTHOR} <%{EMAIL}>, (C) %{YEAR} // // Copyright: See COPYING file that comes with this distribution // // #include "hdf5filedata.h" #include "H5Fpublic.h" #include "H5public.h" #include "H5Spublic.h" #include "H5Apublic.h" #include "H5LTpublic.h" #include "Hdf_sds.hpp" HDF5FileData::HDF5FileData(const string &filename, const string &mode) :FileData(filename,mode),FileDataReader(filename,mode) { name = filename; file_id=-1; read_dataset_done = false; read_all_dataset(); string date = get_values_attr("RANGEBEGINNINGDATE"); int year = MyTools::to_num(date.substr(0,4)); int month = MyTools::to_num(date.substr(5,2)); int day = MyTools::to_num(date.substr(8,2)); string time = get_values_attr("RANGEBEGINNINGTIME"); int hour = MyTools::to_num(time.substr(0,2)); int minut = MyTools::to_num(time.substr(3,2)); int seconds = MyTools::to_num(time.substr(6,2)); Date bdate(year,month,day,hour,minut,seconds); date = get_values_attr("RANGEENDINGDATE"); year = MyTools::to_num(date.substr(0,4)); month = MyTools::to_num(date.substr(5,2)); day = MyTools::to_num(date.substr(8,2)); time = get_values_attr("RANGEENDINGTIME"); hour = MyTools::to_num(time.substr(0,2)); minut = MyTools::to_num(time.substr(3,2)); seconds = MyTools::to_num(time.substr(6,2)); Date edate(year,month,day,hour,minut,seconds); this->set_date(bdate); this->time_coverage= edate.get_epoch_time()-bdate.get_epoch_time(); } HDF5FileData::~HDF5FileData() { for(uint i=0; i dim=this->get_dataset_dimension(sds_name); for ( int i = 0 ; i (dim[i]-1)) { bad_index e(start[i],(dim[i]-1)); throw e; return false; } // test the selection length int stride_val; if ( stride!=NULL ) stride_val=stride[i]; else stride_val=1; if ( (start[i]+(edges[i]*stride_val))> dim[i] ) { bad_index e(start[i]+(edges[i]*stride_val),dim[i]-1); throw e; return false; } } return true; }; void HDF5FileData::init_read_write_null_input_param(const char* sds_name, int *&start, int *&stride, int *&edges, int &rank, bool * initialized_values) { initialized_values[0] = false; initialized_values[1] = false; initialized_values[2] = false; vector dim=this->get_dataset_dimension(sds_name); // if rank is not defined, set to the sds one if (rank==-1) rank = dim.size(); // if start is not defined, allocate it with a rank size, and set its values to 0 if ( start == NULL ) { start = new int[rank]; initialized_values[0] = true; for ( int i = 0;i vdim=this->get_dataset_dimension(sds_name); hsize_t *dim = new hsize_t[rank]; for (int i = 0 ; i size=this->get_dataset_dimension(sds_name); if(!read_dataset_done) read_all_dataset(); hid_t dataset_id = dataset_map[sds_name]; hid_t type_id=H5Dget_type(dataset_id); // hid_t dsp_id = H5Screate(H5S_SIMPLE); // H5Sset_extent_simple(dsp_id, rank, dim, dim ); hsize_t *start_t= new hsize_t[rank]; hsize_t *stride_t= new hsize_t[rank]; hsize_t *edges_t= new hsize_t[rank]; hsize_t *dim_t= new hsize_t[rank]; for(int i=0; i1 ? (edges[i]+1)/stride[i] : edges[i]/stride[i]; } hid_t dsp_id = H5Dget_space(dataset_id); H5Sselect_hyperslab(dsp_id, H5S_SELECT_SET, start_t, stride_t, edges_t, NULL ); hid_t memspace_id = H5Screate_simple (rank, dim_t, NULL); delete start_t; delete stride_t; delete edges_t; // data allocation hasn't been done by the caller if (data==NULL) { // read the size of the sds data size_t data_type_size = H5Tget_size( type_id ); data = static_cast(malloc(data_type_size*data_size)); } H5Dread(dataset_id, type_id, memspace_id, dsp_id, H5P_DEFAULT, data ); // free the ressources allocated by this method free_read_write_allocations(are_limits_initialized, start, stride, edges); // if (!hdf_file_already_loaded) // free_hdf_file(); return data; } vector HDF5FileData::get_dataset_dimension(const string &sds_name) { if(!read_dataset_done) read_all_dataset(); hid_t dataset = dataset_map[sds_name]; hid_t dsp_id = H5Dget_space(dataset); int n = H5Sget_simple_extent_ndims(dsp_id); hsize_t *dims = new hsize_t[n]; hsize_t *maxdims = new hsize_t[n]; vector v; H5Sget_simple_extent_dims(dsp_id, dims, maxdims); for(int i=0; i=0; if(!opened) open_data_file(); if(read_dataset_done) return; char *gp_name = new char[100]; hsize_t* num_obj= new hsize_t(); hid_t gp_id; hid_t gp_id1; hid_t dsp_id; vector v; v.push_back(file_id); while(!v.empty()){ gp_id = v.back(); v.pop_back(); H5Gget_num_objs(gp_id, num_obj); n = *num_obj; for(int i=0; i0) { dataset_map[string(gp_name)]=gp_id1; dataset_vect.push_back(string(gp_name)); }else{ attributes.push_back(gp_id1); } } } if(gp_id != file_id) H5Gclose(gp_id); } read_metadata(); read_dataset_done = true; if(!opened) close_data_file(); } void HDF5FileData::read_metadata(){ for(uint i=0; i lines; split(text, lines, "\n"); string tag; string value; string object; for(uint j=0; j& tokens, const string& delimiters) { int pos1=0; int pos2=str.find_first_of(delimiters,pos1+1); string line; while(pos2!=-1){ line = str.substr(pos1+1,pos2-1-pos1); tokens.push_back(line); pos1=pos2; pos2=str.find_first_of(delimiters,pos1+1); } line = str.substr(pos1+1,str.length()-pos1); tokens.push_back(line); } void HDF5FileData::get_fillValue(const string &sds_name, void *fillValue) { if(!read_dataset_done) read_all_dataset(); hid_t dataset_id = dataset_map[sds_name]; hid_t type_id=H5Dget_type(dataset_id); hid_t plist = H5Dget_create_plist(dataset_id); H5Pget_fill_value(plist, type_id, fillValue ); }; void HDF5FileData::get_scaling(const string &sds_name, float64 &scale, float64 &offset) { if(!read_dataset_done) read_all_dataset(); // hid_t dataset_id = dataset_map[sds_name]; // hid_t type_id=H5Dget_type(dataset_id); // hid_t plist = H5Dget_create_plist(dataset_id); //TODO adapte code scale=1.0; offset=0.0; };