Hdf_file.hpp

00001 /* Hdf_file.hpp */
00002 
00003 #ifndef HDF_FILE_HPP
00004 #define HDF_FILE_HPP
00005 
00006 #include <iostream>
00007 #include <vector>
00008 #include "hdf.h"
00009 #include "mfhdf.h"
00010 #include "Hdf_attr.hpp"
00011 #include "Hdf_sds.hpp"
00012 #include "Hdf_vd.hpp"
00013 #include "Hdf_common.hpp"
00014 
00015 #define SDS_MAX_RANK 32
00016 #define SDS_NAME_MAX_LEN 256
00017 #define DEFAULT_COMP_LEVEL 4
00018 
00022 class Hdf_file {
00023   std::string filename;
00024   int32 sd_id;
00028   int32 file_id;
00029   int32 n_sds;
00030   int32 n_file_attrs;
00031   Hdf_attr *file_attrs;
00032   Hdf_sds *sds;
00033   vector <Hdf_vd> vd; // Vdatas
00034   void Hdf_file_init(const char *filename, int32 access);
00035   void init_vd_interface();
00036   int32 get_vd_idx( const char * vd_name ) const;
00037   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);
00038 
00039 public:
00040   typedef Hdf_sds::sds_infos_type sds_infos_type;
00041   Hdf_file(const char *filename, int32 access, std::vector<sds_infos_type> sds_infos = std::vector<sds_infos_type>(), int32 fill_mode = SD_FILL, int32 compression_type = COMP_CODE_NONE, int32 compression_level = DEFAULT_COMP_LEVEL);
00042   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);
00043   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);
00044   Hdf_file(const Hdf_file &hdf_file);
00045   ~Hdf_file();
00046   Hdf_file &operator= (const Hdf_file &hdf_file);
00047 
00048   std::string to_string() const;
00049   friend std::ostream &operator<< (std::ostream &stream, const Hdf_file &hdf_file);
00050 
00051   int32 get_n_file_attrs() const { return n_file_attrs; }
00052   bool has_attr(const char *file_attr) const;
00053   Hdf_attr get_attr(const char *file_attr) const;
00054   std::string list_of_attributes(const int32 chars_to_display = 80, const int32 numbers_to_display = 10) const;
00055   void set_file_attr(const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val);
00056   std::string get_filename() const { return filename; }
00057   /*********************************************************/
00058   /*********************  SDS INTERFACE  ********************/
00059   /*********************************************************/
00060   int32 get_sd_id() const { return sd_id; }
00061   int32 get_n_sds() const { return n_sds; }
00062   Hdf_sds get_sds(const char *sds_name) const;
00063   Hdf_sds get_sds(const int32 &sds_index) const;
00064   std::string get_sds_name( const int32 &sds_index);
00065   const int32 get_sds_id(const char *sds_name); 
00066   const int32 get_sds_index(const char *sds_name);
00067 
00074   const intn append_sds ( const sds_infos_type & sds_infos, const void * sds_data );
00075 
00081   const int32 create_sds ( const sds_infos_type & sds_infos );
00082 
00088   const int32 get_sds_data_type(const char *sds_name);
00095   const size_t get_sds_sizeof(const char *sds_name);
00096   void get_sds_array(Hdf_sds *sds_array);
00097   void get_fill_value(const char * sds_name,void* fill_value);
00098   void set_fill_value(const char * sds_name,void* fill_value);
00099   void set_sds(int32 sds_index, Hdf_sds sds);
00100   Hdf_sds read_sds(const char *sds_name, void *sds_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL);
00101   Hdf_sds read_sds(const int32 sds_index, void *sds_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL);
00102   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.);
00103   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.);
00104   std::string list_of_sds() const;
00105   void set_sds_attr(const int32 sds_index, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val );
00106   void set_sds_attr(const char* sds_name, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val );
00107   void get_sds_attr(const char* sds_name, const char *attr_name, void* value, const int32 ival=0) const ;
00108   void get_calibration(const char* sds_name, float64 &cal, float64 &cal_error, float64 &offset, float64 &offset_err, int32 &data_type);
00109   /*********************************************************/
00110   /*********************  VD INTERFACE  ********************/
00111   /*********************************************************/
00112   //int32 get_file_id() const { return file_id; }
00117   int32 get_n_vd() const { return vd.size(); }
00118 
00119    Hdf_vd get_vd(const char *vd_name) const;
00120    Hdf_vd get_vd(const int32 &vd_index) const;
00126   const bool has_vd( const char * vd_name ) const;
00127 
00128 //   std::string get_vd_name( const int32 &vd_index);
00129 //   const int32 get_vd_id(const char *vd_name); 
00130 //   const int32 get_vd_index(const char *vd_name);
00137   const int32 get_vd_field_data_type( const char *vd_name, const char *vd_field_name );
00138 //   const size_t get_vd_sizeof(const char *vd_name);
00139 //   void get_vd_array(Hdf_vd *vd_array);
00140 //   void set_vd(int32 vd_index, Hdf_vd vd);
00141 // 
00142 //   Hdf_vd read_vd(const char *vd_name, void *vd_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL);
00143 //   Hdf_vd read_vd(const int32 vd_index, void *vd_data = NULL, int32 *start = NULL, int32 *stride = NULL, int32 *edges = NULL);
00144 
00145   void set_vd_attr(const int32 vd_index, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val );
00146   void set_vd_attr(const char* vd_name, const char *attr_name, const int val_type, const int32 val_length, VOIDP attr_val );
00147   void get_vd_attr(const char* vd_name, const char *attr_name, void* value, const int32 ival=0) const ;
00148   std::string list_of_vdata() const;
00149 
00162   Hdf_vd_field read_vdata_field(const char *vd_name="", const char *vd_field_name="", void* data=NULL, int32 start=0, int32 edges=-1);
00163 
00164   const bool is_vs_interface_opened();
00165   int32 open_vs_interface(int32 access=DFACC_READ);
00166   void close_vs_interface();
00167 };
00168 
00169 #endif