EMAN2
io_template.cpp
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#include "io_template.h"
33#include "portable_fileio.h"
34
35using namespace EMAN;
36
37XYZIO::XYZIO(const string & file, IOMode rw)
38: filename(file), rw_mode(rw), xyz_file(0), initialized(false)
39{
41}
42
44{
45 if (xyz_file) {
46 fclose(xyz_file);
47 xyz_file = 0;
48 }
49}
50
51void XYZIO::init()
52{
53 if (initialized) {
54 return ;
55 }
56
58
59 initialized = true;
60 bool is_new_file = false;
61 xyz_file = sfopen(filename, rw_mode, &is_new_file);
62
63 if (!is_new_file) {
64
65 }
66
68}
69
70bool XYZIO::is_valid(const void *first_block)
71{
73 bool result = false;
74 if (!first_block) {
75 result = false;
76 }
77
78 // check image format validality here
79
81 return result;
82}
83
84int XYZIO::read_header(Dict & , int image_index, const Region * , bool )
85{
87 check_read_access(image_index);
88
89 // read header info here
90
92 return 0;
93}
94
95int XYZIO::write_header(const Dict & , int image_index, const Region *,
96 EMUtil::EMDataType , bool)
97{
99 check_write_access(rw_mode, image_index);
100 // write header info here
101 EXITFUNC;
102 return 0;
103}
104
105int XYZIO::read_data(float *data, int image_index, const Region * , bool )
106{
107 ENTERFUNC;
108 check_read_access(image_index, data);
109
110 // read image data here
111
112 EXITFUNC;
113 return 0;
114}
115
116int XYZIO::write_data(float *data, int image_index, const Region *,
117 EMUtil::EMDataType , bool)
118{
119 ENTERFUNC;
120 check_write_access(rw_mode, image_index, 0, data);
121
122 // write image data here
123
124 EXITFUNC;
125 return 0;
126}
127
128void XYZIO::flush()
129{
130 if (xyz_file) {
131 fflush(xyz_file);
132 }
133}
134
136{
137 return false;
138}
139
141{
142 return is_big_endian;
143}
144
146{
147 init();
148
149 return 1;
150}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
EMDataType
Image pixel data type used in EMAN.
Definition: emutil.h:92
virtual void flush()=0
Flush the IO buffer.
virtual int write_header(const Dict &dict, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
Write a header to an image.
virtual int write_data(float *data, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
Write data to an image.
virtual bool is_complex_mode()=0
Is this an complex image or not.
virtual int read_header(Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)=0
Read the header from an image.
FILE * sfopen(const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
Run fopen safely.
Definition: imageio.cpp:135
void check_read_access(int image_index)
Validate 'image_index' in file reading.
Definition: imageio.cpp:95
virtual int read_data(float *data, int image_index=0, const Region *area=0, bool is_3d=false)=0
Read the data from an image.
virtual void init()=0
Do some initialization before doing the read/write.
void check_write_access(IOMode rw_mode, int image_index, int max_nimg=0)
Validate rw_mode and image_index in file writing.
Definition: imageio.cpp:113
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
bool initialized
Definition: io_template.h:59
static bool is_valid(const void *first_block)
Definition: io_template.cpp:70
bool is_big_endian
Definition: io_template.h:58
IOMode rw_mode
Definition: io_template.h:55
int get_nimg()
Return the number of images in this image file.
string filename
Definition: io_template.h:54
FILE * xyz_file
Definition: io_template.h:56
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
E2Exception class.
Definition: aligner.h:40