00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef IMPEM_MRC_READER_WRITER_H
00010 #define IMPEM_MRC_READER_WRITER_H
00011
00012 #include "em_config.h"
00013 #include "MapReaderWriter.h"
00014 #include <string>
00015
00016 IMPEM_BEGIN_NAMESPACE
00017
00018 #define IMP_MRC_LABEL_SIZE 80
00019 #define IMP_MRC_USER 25
00020 #define IMP_MRC_NUM_LABELS 10
00021
00022
00023
00024
00025 class IMPEMEXPORT MRCHeader
00026 {
00027 public:
00028
00029 int nx;
00030
00031 int ny;
00032
00033 int nz;
00034
00035
00036
00037
00038
00039
00040
00041
00042 int mode;
00043
00044 int nxstart,nystart,nzstart;
00045
00046 int mx;
00047
00048 int my;
00049
00050 int mz;
00051
00052 float xlen;
00053
00054 float ylen;
00055
00056 float zlen;
00057
00058 float alpha;
00059
00060 float beta;
00061
00062 float gamma;
00063
00064
00065 int mapc, mapr, maps;
00066
00067 float dmin;
00068
00069 float dmax;
00070
00071 float dmean;
00072
00073 int ispg;
00074 int nsymbt;
00075
00076 int user[IMP_MRC_USER];
00077
00078
00079 float xorigin;
00080
00081 float yorigin;
00082
00083 float zorigin;
00084
00085 char map[4];
00086
00087 int machinestamp;
00088
00089 float rms;
00090
00091 int nlabl;
00092
00093 char labels[IMP_MRC_NUM_LABELS][IMP_MRC_LABEL_SIZE];
00094 public:
00095
00096 void FromDensityHeader(const DensityHeader &h);
00097
00098 void ToDensityHeader(DensityHeader &h);
00099
00100 friend std::ostream& operator<<(std::ostream& s, const MRCHeader &v) {
00101 s<< "nx: " << v.nx << " ny: " << v.ny << " nz: " << v.nz << std::endl;
00102 s<<"mode: " << v.mode << std::endl;
00103 s <<"nxstart: " << v.nxstart << " nystart: " << v.nystart <<" nzstart: "
00104 << v.nzstart << std::endl;
00105 s<<"mx: "<< v.mx <<" my:" << v.my << " mz: " << v.mz << std::endl;
00106 s << "xlen: " << v.xlen <<" ylen: " << v.ylen <<" zlen: " << v.zlen
00107 << std::endl;
00108 s <<"alpha : " << v.alpha << " beta: " << v.beta <<" gamma: "<< v.gamma
00109 << std::endl;
00110 s << "mapc : " << v.mapc << " mapr: " << v.mapr <<" maps: " << v.maps
00111 << std::endl;
00112 s << "dmin: " << v.dmin << " dmax: " << v.dmax << " dmean: " << v.dmean
00113 << std::endl;
00114 s <<"ispg: " << v.ispg << std::endl;
00115 s <<"nsymbt: " << v.nsymbt << std::endl;
00116 s << "user: " << v.user << std::endl;
00117 s << "xorigin: " << v.xorigin << " yorigin: "<< v.yorigin
00118 << " zorigin: "<< v.zorigin << std::endl;
00119 s <<"map: " << v.map << std::endl;
00120 s<< "machinestamp: " << v.machinestamp << std::endl;
00121 s <<"rms: " << v.rms << std::endl;
00122 s<<"nlabl: " << v.nlabl << std::endl;
00123 s <<"labels : " << v.labels << std::endl;
00124 for(int i=0;i<v.nlabl;i++)
00125 s <<"labels[" << i << "] = ->" << v.labels[i] << "<-" << std::endl;
00126 return s;
00127 }
00128 };
00129
00130
00131 class IMPEMEXPORT MRCReaderWriter : public MapReaderWriter
00132 {
00133 public:
00134
00135 MRCReaderWriter() {}
00136
00137
00138
00139
00140 MRCReaderWriter(char *fn) {
00141 filename=fn;
00142 }
00143
00144 void Read(const char *fn_in, float **data, DensityHeader &head);
00145
00146 void Write(const char *fn_out, const float *data, const DensityHeader &head);
00147
00148
00149 private:
00150
00151
00152
00153
00154 void read() {
00155 read(&grid);
00156 }
00157
00158 void read(float **pt);
00159
00160 void read_header();
00161
00162 void read_data(float *pt);
00163
00164 void read_8_data(float *pt);
00165
00166 void read_32_data(float *pt);
00167 void read_grid(void *pt,size_t size,size_t n);
00168 void seek_to_data();
00169
00170
00171
00172
00173 void write(const char *fn) {
00174 return write(fn,grid);
00175 }
00176
00177
00178
00179
00180
00181
00182 void write(const char *fn,const float *pt);
00183
00184
00185
00186
00187 void write_header(std::ofstream &s);
00188
00189
00190
00191
00192
00193 void write_data(std::ofstream &s, const float *pt);
00194
00195
00196 std::string filename;
00197
00198 std::fstream fs;
00199
00200 MRCHeader header;
00201
00202
00203 float *grid;
00204
00205 };
00206
00207
00208
00209 IMPEMEXPORT
00210
00211
00212 int get_machine_stamp();
00213
00214 IMPEMEXPORT
00215
00216 int is_bigendian();
00217
00218 IMPEMEXPORT
00219
00220 void byte_swap(unsigned char *ch, int n_array);
00221
00222 IMPEM_END_NAMESPACE
00223
00224 #endif