00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman__hdfio_h__
00037 #define eman__hdfio_h__ 1
00038
00039 #ifdef EM_HDF5
00040
00041 #define H5_USE_16_API
00042
00043 #include "imageio.h"
00044
00045 #include <hdf5.h>
00046 #include <vector>
00047
00048 using std::vector;
00049
00050 namespace EMAN
00051 {
00062 class HdfIO:public ImageIO
00063 {
00064 public:
00065 enum DataType
00066 { INT, FLOAT, STRING };
00067
00068 public:
00069 explicit HdfIO(const string & filename, IOMode rw_mode = READ_ONLY);
00070 ~HdfIO();
00071
00072 DEFINE_IMAGEIO_FUNC;
00073 static bool is_valid(const void *first_block);
00074
00075 int read_ctf(Ctf & ctf, int image_index = 0);
00076 void write_ctf(const Ctf & ctf, int image_index = 0);
00077
00078 int read_euler_angles(Dict & euler_angles, int image_index = 0);
00079 void write_euler_angles(const Dict & euler_angles, int image_index = 0);
00080
00081 int read_array_attr(int image_index, const string & attr_name, void *value);
00082 int write_array_attr(int image_index, const string & attr_name,
00083 int nitems, void *data, DataType type);
00084
00085 bool is_single_image_format() const
00086 {
00087 return false;
00088 }
00089
00090 int get_nimg();
00091
00092
00093 int read_int_attr(int image_index, const string & attr_name);
00094 float read_float_attr(int image_index, const string & attr_name);
00095 string read_string_attr(int image_index, const string & attr_name);
00096 int read_global_int_attr(const string & attr_name);
00097 float read_global_float_attr(const string & attr_name);
00098
00099 int read_mapinfo_attr(int image_index, const string & attr_name);
00100
00101 int write_int_attr(int image_index, const string & attr_name, int value);
00102 int write_float_attr(int image_index, const string & attr_name, float value);
00103 int write_string_attr(int image_index, const string & attr_name,
00104 const string & value);
00105
00106 int write_float_attr_from_dict(int image_index, const string & attr_name,
00107 const Dict & dict);
00108
00109 int write_global_int_attr(const string & attr_name, int value);
00110
00111 int write_mapinfo_attr(int image_index, const string & attr_name, int value);
00112
00113 int delete_attr(int image_index, const string & attr_name);
00114
00115 int get_num_dataset();
00116 vector < int >get_image_indices();
00117
00118 private:
00119 enum Nametype
00120 { ROOT_GROUP, CTFIT, NUMDATASET, COMPOUND_DATA_MAGIC, EULER };
00121
00122 void create_cur_dataset(int image_index, int nx, int ny, int nz);
00123
00124 int *read_dims(int image_index, int *p_ndim);
00125
00126 int read_compound_dict(Nametype compound_type,
00127 Dict & values, int image_index);
00128
00129 void write_compound_dict(Nametype compound_type,
00130 const Dict & values, int image_index);
00131
00132
00133 static const char *HDF5_SIGNATURE;
00134
00135
00136 string filename;
00137 IOMode rw_mode;
00138 bool initialized;
00139 bool is_new_file;
00140
00141 hid_t file;
00142 hid_t group;
00143 hid_t cur_dataset;
00144 int cur_image_index;
00145
00146 herr_t(*old_func) (void *);
00147 void *old_client_data;
00148
00149 static hid_t mapinfo_type;
00150
00151 vector < int >image_indices;
00152
00153 void hdf_err_off();
00154 void hdf_err_on();
00155
00156 int delete_attr(const string & attr_name);
00157
00158 void set_dataset(int image_index);
00159 int create_compound_attr(int image_index, const string & attr_name);
00160 void close_cur_dataset();
00161 static string get_item_name(Nametype type);
00162 void increase_num_dataset();
00163
00164 static void create_enum_types();
00165 string get_compound_name(int id, const string & name);
00166
00167 float read_float_attr(const string & attr_name);
00168 int write_int_attr(const string & attr_name, int value);
00169 int write_float_attr(const string & attr_name, float value);
00170
00171 int get_hdf_dims(int image_index, int *p_nx, int *p_ny, int *p_nz);
00172
00173 static herr_t file_info(hid_t loc_id, const char *name, void *opdata);
00174 int create_region_space(hid_t * p_dataspace_id, hid_t * p_memspace_id,
00175 const Region * area, int nx, int ny, int nz,
00176 int image_index);
00177
00178
00179 };
00180 }
00181
00182 #endif
00183
00184 #endif