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__mrcio_h__ 00037 #define eman__mrcio_h__ 1 00038 00039 #include "imageio.h" 00040 00041 namespace EMAN 00042 { 00048 class MrcIO:public ImageIO 00049 { 00050 public: 00051 explicit MrcIO(const string & filename, IOMode rw_mode = READ_ONLY); 00052 ~MrcIO(); 00053 00054 DEFINE_IMAGEIO_FUNC; 00055 00056 int read_ctf(Ctf & ctf, int image_index = 0); 00057 void write_ctf(const Ctf & ctf, int image_index = 0); 00058 00059 static bool is_valid(const void *first_block, off_t file_size = 0); 00060 static int get_mode_size(int mm); 00061 static int to_em_datatype(int mrcmode); 00062 static int to_mrcmode(int em_datatype, int is_complex); 00063 00064 private: 00065 enum MrcMode { 00066 MRC_UCHAR = 0, 00067 MRC_SHORT, 00068 MRC_FLOAT, 00069 MRC_SHORT_COMPLEX, 00070 MRC_FLOAT_COMPLEX, 00071 MRC_USHORT = 6, //non-standard 00072 MRC_UCHAR3 = 16, //unsigned char * 3, for rgb data, non-standard 00073 MRC_UNKNOWN 00074 }; 00075 00076 enum { 00077 MRC_NUM_LABELS = 10, 00078 MRC_LABEL_SIZE = 80, 00079 NUM_4BYTES_PRE_MAP = 52, 00080 NUM_4BYTES_AFTER_MAP = 3 00081 }; 00082 00083 /* updated to MRC Image2000 format which is compatible with CCP4 format */ 00084 struct MrcHeader 00085 { 00086 int nx; /* number of columns */ 00087 int ny; /* number of rows */ 00088 int nz; /* number of sections */ 00089 00090 int mode; /* See modes above. */ 00091 00092 int nxstart; /* No. of first column in map, default 0. */ 00093 int nystart; /* No. of first row in map, default 0. */ 00094 int nzstart; /* No. of first section in map,default 0. */ 00095 00096 int mx; /* Number of intervals along X. */ 00097 int my; /* Number of intervals along Y. */ 00098 int mz; /* Number of intervals along Z. */ 00099 00100 /* Cell: treat a whole 2D image as a cell */ 00101 float xlen; /* Cell dimensions (Angstroms). */ 00102 float ylen; /* Cell dimensions (Angstroms). */ 00103 float zlen; /* Cell dimensions (Angstroms). */ 00104 00105 float alpha; /* Cell angles (Degrees). */ 00106 float beta; /* Cell angles (Degrees). */ 00107 float gamma; /* Cell angles (Degrees). */ 00108 00109 /* axis X => 1, Y => 2, Z => 3 */ 00110 int mapc; /* Which axis corresponds to Columns. */ 00111 int mapr; /* Which axis corresponds to Rows. */ 00112 int maps; /* Which axis corresponds to Sections. */ 00113 00114 float amin; /* Minimum density value. */ 00115 float amax; /* Maximum density value. */ 00116 float amean; /* Mean density value. */ 00117 00118 int ispg; /* Space group number (0 for images). */ 00119 00120 int nsymbt; /* Number of chars used for storing symmetry operators. */ 00121 00122 int user[25]; 00123 00124 float xorigin; /* X origin. */ 00125 float yorigin; /* Y origin. */ 00126 float zorigin; /* Z origin. */ 00127 00128 char map[4]; /* constant string "MAP " */ 00129 int machinestamp; /* machine stamp in CCP4 convention: 00130 big endian=0x11110000 little endian=0x44440000 */ 00131 /* There is an ambiguity in the specification, using 0x11111111 & 4 instead */ 00132 00133 float rms; /* rms deviation of map from mean density */ 00134 00135 int nlabels; /* Number of labels being used. */ 00136 char labels[MRC_NUM_LABELS][MRC_LABEL_SIZE]; 00137 }; 00138 00139 static const char *CTF_MAGIC; 00140 static const char *SHORT_CTF_MAGIC; 00141 00142 00143 private: 00144 string filename; 00145 IOMode rw_mode; 00146 FILE *mrcfile; 00147 MrcHeader mrch; 00148 int mode_size; 00149 00150 int is_ri; 00151 bool is_big_endian; 00152 bool is_new_file; 00153 bool initialized; 00154 00156 static int generate_machine_stamp(); 00157 void swap_header(MrcHeader& mrch); 00158 00163 void update_stat(void* data); 00164 }; 00165 } 00166 00167 #endif //eman__mrcio_h__