hdfio.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  * 
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  * 
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  * 
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  * 
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  * 
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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

Generated on Tue Jun 11 12:40:22 2013 for EMAN2 by  doxygen 1.4.7