/* Hdf_file.hpp */ #ifndef HDF_FILE_HPP #define HDF_FILE_HPP #include #include #include "hdf.h" #include "mfhdf.h" #include "Hdf_attr.hpp" #include "Hdf_sds.hpp" #include "Hdf_vd.hpp" #include "Hdf_common.hpp" #define SDS_MAX_RANK 32 #define SDS_NAME_MAX_LEN 256 #define DEFAULT_COMP_LEVEL 4 /** * @warning the VData and VData fields read attributes capabilities haven't been fully tested because of the lack of files using it. */ class Hdf_file { std::string filename; int32 sd_id; /** * the id of the vs interface. If this interface is open, it is different than -1 */ int32 file_id; int32 n_sds; int32 n_file_attrs; Hdf_attr *file_attrs; Hdf_sds *sds; vector vd; // Vdatas void Hdf_file_init(const char *filename, int32 access); void init_vd_interface(); int32 get_vd_idx( const char * vd_name ) const; Hdf_vd_field read_vdata_field(const int32 &vd_idx=-1, const char *vd_field_name="", void* data = NULL, int32 start=0, int32 edges=-1); public: typedef Hdf_sds::sds_infos_type sds_infos_type; Hdf_file(const char *filename, int32 access, std::vector sds_infos = std::vector(), int32 fill_mode = SD_FILL, int32 compression_type = COMP_CODE_NONE, int32 compression_level = DEFAULT_COMP_LEVEL); Hdf_file(const char *filename, int32 access, Hdf_file::sds_infos_type *sds_infos, const size_t nsds, int32 fill_mode = SD_FILL, int32 compression_type = COMP_CODE_NONE, int32 compression_level = DEFAULT_COMP_LEVEL); Hdf_file(const char *filename, int32 access, int32 n_sds_array, Hdf_sds *sds_array, int32 fill_mode = SD_FILL, int32 compression_type = COMP_CODE_NONE, int32 compression_level = DEFAULT_COMP_LEVEL); Hdf_file(const Hdf_file &hdf_file); ~Hdf_file(); Hdf_file &operator= (const Hdf_file &hdf_file); std::string to_string() const; friend std::ostream &operator<< (std::ostream &stream, const Hdf_file &hdf_file); int32 get_n_file_attrs() const { return n_file_attrs; } bool has_attr(const char *file_attr) const; Hdf_attr get_attr(const char *file_attr) const; std::string list_of_attributes(const int32 chars_to_display = 80, const int32 numbers_to_display = 10) const; void set_file_attr(const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val); std::string get_filename() const { return filename; } /*********************************************************/ /********************* SDS INTERFACE ********************/ /*********************************************************/ int32 get_sd_id() const { return sd_id; } int32 get_n_sds() const { return n_sds; } Hdf_sds get_sds(const char *sds_name) const; Hdf_sds get_sds(const int32 &sds_index) const; std::string get_sds_name( const int32 &sds_index); const int32 get_sds_id(const char *sds_name); const int32 get_sds_index(const char *sds_name); /** * @brief write an sds to the file * @param sds_infos structure describing the SDS and its attributes * @param sds_data data buffer to write * @return FAIL if an error occured, SUCCESS else */ const intn append_sds ( const sds_infos_type & sds_infos, const void * sds_data ); /** * @brief create an sds and return its id * @param sds_infos structure describing the SDS * @return FAIL if an error occured, the SDS ID else */ const int32 create_sds ( const sds_infos_type & sds_infos ); /** * @brief access to the type of datas of a sds * @param sds_name the name of the sds * @return the HDF type code of the sds datas */ const int32 get_sds_data_type(const char *sds_name); /** * @brief access to the memory size of the type of an sds' datas * It returns the memory size in bytes using sizeof convention * @param sds_name the name of the sds * @return the size of one element of this sds */ const size_t get_sds_sizeof(const char *sds_name); void get_sds_array(Hdf_sds *sds_array); void get_fill_value(const char * sds_name,void* fill_value); void set_fill_value(const char * sds_name,void* fill_value); void set_sds(int32 sds_index, Hdf_sds sds); Hdf_sds read_sds(const char *sds_name, void *sds_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL); Hdf_sds read_sds(const int32 sds_index, void *sds_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL); void write_sds(const char *sds_name, const void *sds_data, int32 *start, int32 *stride, int32 *edges, float64 cal = 0., float64 offset = 0., float64 cal_err = 0., float64 off_err = 0.); void write_sds(const int32 sds_index, const void *sds_data, int32 *start, int32 *stride, int32 *edges, float64 cal = 0., float64 offset = 0., float64 cal_err = 0., float64 off_err = 0.); std::string list_of_sds() const; void set_sds_attr(const int32 sds_index, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val ); void set_sds_attr(const char* sds_name, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val ); void get_sds_attr(const char* sds_name, const char *attr_name, void* value, const int32 ival=0) const ; void get_calibration(const char* sds_name, float64 &cal, float64 &cal_error, float64 &offset, float64 &offset_err, int32 &data_type); /*********************************************************/ /********************* VD INTERFACE ********************/ /*********************************************************/ //int32 get_file_id() const { return file_id; } /** * @brief retrieve the number of VData in the file * @return the number of VData */ int32 get_n_vd() const { return vd.size(); } Hdf_vd get_vd(const char *vd_name) const; Hdf_vd get_vd(const int32 &vd_index) const; /** * @brief test the existence of the vd * @param vd_name the name of the vd * @return true if the vd has been found */ const bool has_vd( const char * vd_name ) const; // std::string get_vd_name( const int32 &vd_index); // const int32 get_vd_id(const char *vd_name); // const int32 get_vd_index(const char *vd_name); /** * @brief read the data type of a VData field * @param vd_name name of the VData * @param vd_field_name name of the VData Field * @return the VDATA field datatype, using the HDF typecode convention */ const int32 get_vd_field_data_type( const char *vd_name, const char *vd_field_name ); // const size_t get_vd_sizeof(const char *vd_name); // void get_vd_array(Hdf_vd *vd_array); // void set_vd(int32 vd_index, Hdf_vd vd); // // Hdf_vd read_vd(const char *vd_name, void *vd_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL); // Hdf_vd read_vd(const int32 vd_index, void *vd_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL); void set_vd_attr(const int32 vd_index, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val ); void set_vd_attr(const char* vd_name, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val ); void get_vd_attr(const char* vd_name, const char *attr_name, void* value, const int32 ival=0) const ; std::string list_of_vdata() const; /** * @brief read the datas of one VData field. * If you let the start and edge values at their default, all the datas will be read * @param vd_name the name of the VData * @param vd_field_name the name of the field to read * @param data the data's output buffer. Must be already allocated * @param start the start of reading index * @param edges the number of values to read * @return the read field * @warning Only one VData field datas can be read read at one time. * @warning The case of reading values in a multi-order field hasn't been tested yet */ Hdf_vd_field read_vdata_field(const char *vd_name="", const char *vd_field_name="", void* data=NULL, int32 start=0, int32 edges=-1); const bool is_vs_interface_opened(); int32 open_vs_interface(int32 access=DFACC_READ); void close_vs_interface(); }; #endif