EMAN2
emio.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__emio_h__
00037 #define eman__emio_h__ 1
00038 
00039 #include "imageio.h"
00040 
00041 namespace EMAN
00042 {
00048         class EmIO:public ImageIO
00049         {
00050           public:
00051                 explicit EmIO(const string & filename, IOMode rw_mode = READ_ONLY);
00052                 ~EmIO();
00053 
00054                 DEFINE_IMAGEIO_FUNC;
00055                 static bool is_valid(const void *first_block, off_t file_size = 0);
00056                 static size_t get_mode_size(char data_type);
00057                 static int get_machine_type();
00058                 static int to_em_datatype(char t);
00059 
00060           private:
00061                 struct EMHeader
00062                 {
00063                         char machine;           // 0=OS-8, 1=VAX; 2=Convex; 3=SGI; 5=Mac; 6=PC
00064                         char is_new_ver;        // OS-9 only
00065                         char not_used1;
00066                         char data_type;         // 1=byte, 2=short; 4=int; 5=float; 8=complex; 9=double
00067                         int nx;
00068                         int ny;
00069                         int nz;
00070                         char comment[80];
00071                         int parameters[40];
00072                         char username[20];
00073                         char date[8];
00074                         char userdata[228];
00075                 };
00076 
00077                 enum DataType
00078                 {
00079                         EM_EM_CHAR = 1,
00080                         EM_EM_SHORT = 2,
00081                         EM_EM_INT = 4,
00082                         EM_EM_FLOAT = 5,
00083                         EM_EM_COMPLEX = 8,
00084                         EM_EM_DOUBLE = 9,
00085                         EM_EM_UNKNOWN
00086                 };
00087 
00088                 enum MachineType
00089                 {
00090                         EM_OS8 = 0,
00091                         EM_VAX = 1,
00092                         EM_CONVEX = 2,
00093                         EM_SGI = 3,
00094                         EM_MAC = 5,
00095                         EM_PC = 6,
00096                         EM_UNKNOWN_MACHINE
00097                 };
00098 
00099           private:
00100                 string filename;
00101                 IOMode rw_mode;
00102                 FILE *em_file;
00103                 EMHeader emh;
00104 
00105                 size_t mode_size;
00106                 DataType mode;
00107                 bool is_big_endian;
00108                 bool initialized;
00109                 bool is_new_file;
00110         };
00111 
00112 }
00113 
00114 
00115 #endif  //eman__emio_h__