EMAN2
io_template.cpp
Go to the documentation of this file.
00001 /*
00002  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00003  * Copyright (c) 2000-2006 Baylor College of Medicine
00004  * 
00005  * This software is issued under a joint BSD/GNU license. You may use the
00006  * source code in this file under either license. However, note that the
00007  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00008  * so you are responsible for compliance with the licenses of these packages
00009  * if you opt to use BSD licensing. The warranty disclaimer below holds
00010  * in either instance.
00011  * 
00012  * This complete copyright notice must be included in any revised version of the
00013  * source code. Additional authorship citations may be added, but existing
00014  * author citations must be preserved.
00015  * 
00016  * This program is free software; you can redistribute it and/or modify
00017  * it under the terms of the GNU General Public License as published by
00018  * the Free Software Foundation; either version 2 of the License, or
00019  * (at your option) any later version.
00020  * 
00021  * This program is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024  * GNU General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU General Public License
00027  * along with this program; if not, write to the Free Software
00028  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00029  * 
00030  * */
00031 
00032 #include "io_template.h"
00033 #include "portable_fileio.h"
00034 
00035 using namespace EMAN;
00036 
00037 XYZIO::XYZIO(const string & file, IOMode rw)
00038 :       filename(file), rw_mode(rw), xyz_file(0), initialized(false)
00039 {
00040         is_big_endian = ByteOrder::is_host_big_endian();
00041 }
00042 
00043 XYZIO::~XYZIO()
00044 {
00045         if (xyz_file) {
00046                 fclose(xyz_file);
00047                 xyz_file = 0;
00048         }
00049 }
00050 
00051 void XYZIO::init()
00052 {
00053         if (initialized) {
00054                 return ;
00055         }
00056 
00057         ENTERFUNC;
00058         
00059         initialized = true;
00060         bool is_new_file = false;
00061         xyz_file = sfopen(filename, rw_mode, &is_new_file);
00062 
00063         if (!is_new_file) {
00064 
00065         }
00066 
00067         EXITFUNC;
00068 }
00069 
00070 bool XYZIO::is_valid(const void *first_block)
00071 {
00072         ENTERFUNC;
00073         bool result = false;
00074         if (!first_block) {
00075                 result = false;
00076         }
00077 
00078         // check image format validality here
00079         
00080         EXITFUNC;
00081         return result;
00082 }
00083 
00084 int XYZIO::read_header(Dict & , int image_index, const Region * , bool )
00085 {
00086         ENTERFUNC;
00087         check_read_access(image_index);
00088 
00089         // read header info here
00090         
00091         EXITFUNC;
00092         return 0;
00093 }
00094 
00095 int XYZIO::write_header(const Dict & , int image_index, const Region *,
00096                                                 EMUtil::EMDataType , bool)
00097 {
00098         ENTERFUNC;
00099         check_write_access(rw_mode, image_index);
00100         // write header info here
00101         EXITFUNC;
00102         return 0;
00103 }
00104 
00105 int XYZIO::read_data(float *data, int image_index, const Region * , bool )
00106 {
00107         ENTERFUNC;
00108         check_read_access(image_index, data);
00109 
00110         // read image data here
00111 
00112         EXITFUNC;
00113         return 0;
00114 }
00115 
00116 int XYZIO::write_data(float *data, int image_index, const Region *,
00117                                           EMUtil::EMDataType , bool)
00118 {
00119         ENTERFUNC;
00120         check_write_access(rw_mode, image_index, 0, data);
00121 
00122         // write image data here
00123         
00124         EXITFUNC;
00125         return 0;
00126 }
00127 
00128 void XYZIO::flush()
00129 {
00130         if (xyz_file) {
00131                 fflush(xyz_file);
00132         }
00133 }
00134 
00135 bool XYZIO::is_complex_mode()
00136 {
00137         return false;
00138 }
00139 
00140 bool XYZIO::is_image_big_endian()
00141 {
00142         return is_big_endian;
00143 }
00144 
00145 int XYZIO::get_nimg()
00146 {
00147         init();
00148 
00149         return 1;
00150 }