EMAN2
hdfio.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__hdfio_h__
33#define eman__hdfio_h__ 1
34
35#ifdef USE_HDF5
36
37#define H5_USE_16_API
38
39#include "imageio.h"
40
41#include <hdf5.h>
42#include <vector>
43
44using std::vector;
45
46namespace EMAN
47{
58 class HdfIO : public ImageIO
59 {
60 public:
61 enum DataType
62 { INT, FLOAT, STRING };
63
64 public:
65 explicit HdfIO(const string & fname, IOMode rw_mode = READ_ONLY);
66 ~HdfIO();
67
69 static bool is_valid(const void *first_block);
70
71 int read_ctf(Ctf & ctf, int image_index = 0);
72 void write_ctf(const Ctf & ctf, int image_index = 0);
73
74 int read_euler_angles(Dict & euler_angles, int image_index = 0);
75 void write_euler_angles(const Dict & euler_angles, int image_index = 0);
76
77 int read_array_attr(int image_index, const string & attr_name, void *value);
78 int write_array_attr(int image_index, const string & attr_name,
79 int nitems, void *data, DataType type);
80
81 bool is_single_image_format() const
82 {
83 return false;
84 }
85
86 int get_nimg();
87
88
89 int read_int_attr(int image_index, const string & attr_name);
90 float read_float_attr(int image_index, const string & attr_name);
91 string read_string_attr(int image_index, const string & attr_name);
92 int read_global_int_attr(const string & attr_name);
93 float read_global_float_attr(const string & attr_name);
94
95 int read_mapinfo_attr(int image_index, const string & attr_name);
96
97 int write_int_attr(int image_index, const string & attr_name, int value);
98 int write_float_attr(int image_index, const string & attr_name, float value);
99 int write_string_attr(int image_index, const string & attr_name,
100 const string & value);
101
102 int write_float_attr_from_dict(int image_index, const string & attr_name,
103 const Dict & dict);
104
105 int write_global_int_attr(const string & attr_name, int value);
106
107 int write_mapinfo_attr(int image_index, const string & attr_name, int value);
108
109 int delete_attr(int image_index, const string & attr_name);
110
111 int get_num_dataset();
112 vector < int >get_image_indices();
113
114 private:
115 enum Nametype
116 { ROOT_GROUP, CTFIT, NUMDATASET, COMPOUND_DATA_MAGIC, EULER };
117
118 void create_cur_dataset(int image_index, int nx, int ny, int nz);
119
120 int *read_dims(int image_index, int *p_ndim);
121
122 int read_compound_dict(Nametype compound_type,
123 Dict & values, int image_index);
124
125 void write_compound_dict(Nametype compound_type,
126 const Dict & values, int image_index);
127
128
129 static const char *HDF5_SIGNATURE;
130
131
132 bool is_new_file;
133
134 hid_t file;
135 hid_t group;
136 hid_t cur_dataset;
137 int cur_image_index;
138
139 herr_t(*old_func) (void *);
140 void *old_client_data;
141
142 static hid_t mapinfo_type;
143
144 vector < int >image_indices;
145
146 void hdf_err_off();
147 void hdf_err_on();
148
149 int delete_attr(const string & attr_name);
150
151 void set_dataset(int image_index);
152 int create_compound_attr(int image_index, const string & attr_name);
153 void close_cur_dataset();
154 static string get_item_name(Nametype type);
155 void increase_num_dataset();
156
157 static void create_enum_types();
158 string get_compound_name(int id, const string & name);
159
160 float read_float_attr(const string & attr_name);
161 int write_int_attr(const string & attr_name, int value);
162 int write_float_attr(const string & attr_name, float value);
163
164 int get_hdf_dims(int image_index, int *p_nx, int *p_ny, int *p_nz);
165
166 static herr_t file_info(hid_t loc_id, const char *name, void *opdata);
167 int create_region_space(hid_t * p_dataspace_id, hid_t * p_memspace_id,
168 const Region * area, int nx, int ny, int nz,
169 int image_index);
170
171
172 };
173}
174
175#endif
176
177#endif
#define DEFINE_IMAGEIO_FUNC
DEFINE_IMAGEIO_FUNC declares the functions that needs to be implemented by any subclass of ImageIO.
Definition: imageio.h:361
E2Exception class.
Definition: aligner.h:40