EMAN2
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EMAN::MrcIO Class Reference

MRC file = header + data (nx x ny x nz). More...

#include <mrcio.h>

Inheritance diagram for EMAN::MrcIO:
Inheritance graph
[legend]
Collaboration diagram for EMAN::MrcIO:
Collaboration graph
[legend]

Classes

struct  FeiMrcExtHeader
 The extended header used by Fei MRC image. More...
 
struct  FeiMrcHeader
 Extended MRC format for tomography As used by Fei; original definition of extended header by Dave Agard and Bram Koster Contact Dustin Morado Dusti.nosp@m.n.Mo.nosp@m.rado@.nosp@m.uth..nosp@m.tmc.e.nosp@m.du for details. More...
 
struct  MrcHeader
 

Public Member Functions

 MrcIO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~MrcIO ()
 
int read_ctf (Ctf &ctf, int image_index=0)
 Read CTF data from this image. More...
 
void write_ctf (const Ctf &ctf, int image_index=0)
 Write CTF data to this image. More...
 
int get_nimg ()
 Return the number of images in this image file. More...
 
- Public Member Functions inherited from EMAN::ImageIO
 ImageIO (const string &fname, IOMode rw)
 
virtual ~ImageIO ()
 
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. More...
 
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. More...
 
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. More...
 
virtual int read_data_8bit (unsigned char *data, int image_index=0, const Region *area=0, bool is_3d=false, float minval=0.0f, float maxval=0.0f)
 Read the data from an image as an 8 bit array, regardless of format. More...
 
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. More...
 
virtual void flush ()=0
 Flush the IO buffer. More...
 
virtual bool is_complex_mode ()=0
 Is this an complex image or not. More...
 
virtual bool is_image_big_endian ()=0
 Is this image in big endian or not. More...
 
virtual bool is_single_image_format () const
 Is this image format only storing 1 image or not. More...
 
template<class T >
void become_host_endian (T *data, size_t n=1)
 Convert data of this image into host endian format. More...
 
string get_filename () const
 

Static Public Member Functions

static bool is_valid (const void *first_block, off_t file_size=0)
 
static int get_mode_size (int mm)
 
static int to_em_datatype (int mrcmode)
 
static int to_mrcmode (int em_datatype, int is_complex)
 

Public Attributes

 DEFINE_IMAGEIO_FUNC
 
MrcHeader mrch
 
FeiMrcHeader feimrch
 

Private Types

enum  MrcMode {
  MRC_UCHAR = 0 , MRC_SHORT = 1 , MRC_FLOAT = 2 , MRC_SHORT_COMPLEX =3 ,
  MRC_FLOAT_COMPLEX =4 , MRC_USHORT = 6 , MRC_UCHAR3 = 16 , MRC_CHAR = 17 ,
  MRC_UHEX = 101 , MRC_UNKNOWN = 18
}
 
enum  { MRC_NUM_LABELS = 10 , MRC_LABEL_SIZE = 80 , NUM_4BYTES_PRE_MAP = 52 , NUM_4BYTES_AFTER_MAP = 3 }
 

Private Member Functions

void swap_header (MrcHeader &mrch)
 
void update_stats (void *data, size_t size)
 This is a utility function used to calculate new min/max/mean/sigma when write MRC file as 16 bit or 8 bit. More...
 
int read_mrc_header (Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)
 
int read_fei_header (Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)
 
int transpose (float *data, int nx, int ny, int nz) const
 

Static Private Member Functions

static int generate_machine_stamp ()
 generate the machine stamp used in MRC image format. More...
 
static void check_swap (const int *data, const char *filnam, bool show_errors, bool &do_swap, bool &have_err)
 This is a utility routine to tell whether to byte swap MRC header. More...
 

Private Attributes

int mode_size
 
union {
   MrcHeader   mrch
 
   FeiMrcHeader   feimrch
 
}; 
 
bool isFEI
 
bool is_stack
 
int stack_size
 
bool is_8_bit_packed
 
bool use_given_dimensions
 
int is_ri
 
bool is_big_endian
 
bool is_new_file
 
bool is_transpose
 
float rendermin
 
float rendermax
 
int renderbits
 

Static Private Attributes

static const char * CTF_MAGIC = "!-"
 
static const char * SHORT_CTF_MAGIC = "!$"
 

Additional Inherited Members

- Public Types inherited from EMAN::ImageIO
enum  IOMode { READ_ONLY = 1 , READ_WRITE = 2 , WRITE_ONLY = 3 }
 
- Protected Member Functions inherited from EMAN::ImageIO
virtual void init ()=0
 Do some initialization before doing the read/write. More...
 
void check_read_access (int image_index)
 Validate 'image_index' in file reading. More...
 
void check_read_access (int image_index, const float *data)
 Validate 'image_index' and 'data' in file reading. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg=0)
 Validate rw_mode and image_index in file writing. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg, const float *data)
 Validate rw_mode, image_index, and data pointer in file writing. More...
 
void check_region (const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
void check_region (const Region *area, const IntSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
FILE * sfopen (const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
 Run fopen safely. More...
 
- Protected Attributes inherited from EMAN::ImageIO
string filename
 
IOMode rw_mode
 
FILE * file = nullptr
 
bool initialized = false
 

Detailed Description

MRC file = header + data (nx x ny x nz).

A MRC image file stores 1D, 2D or 3D image. The image's dimensions and pixel type are defined in the header.

Definition at line 44 of file mrcio.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
MRC_NUM_LABELS 
MRC_LABEL_SIZE 
NUM_4BYTES_PRE_MAP 
NUM_4BYTES_AFTER_MAP 

Definition at line 76 of file mrcio.h.

76 {
77 MRC_NUM_LABELS = 10,
78 MRC_LABEL_SIZE = 80,
81 };
@ MRC_LABEL_SIZE
Definition: mrcio.h:78
@ NUM_4BYTES_AFTER_MAP
Definition: mrcio.h:80
@ NUM_4BYTES_PRE_MAP
Definition: mrcio.h:79
@ MRC_NUM_LABELS
Definition: mrcio.h:77

◆ MrcMode

enum EMAN::MrcIO::MrcMode
private
Enumerator
MRC_UCHAR 
MRC_SHORT 
MRC_FLOAT 
MRC_SHORT_COMPLEX 
MRC_FLOAT_COMPLEX 
MRC_USHORT 
MRC_UCHAR3 
MRC_CHAR 
MRC_UHEX 
MRC_UNKNOWN 

Definition at line 63 of file mrcio.h.

63 {
64 MRC_UCHAR = 0,
65 MRC_SHORT = 1,
66 MRC_FLOAT = 2,
69 MRC_USHORT = 6,
70 MRC_UCHAR3 = 16, // unsigned char * 3, for rgb data, non-standard
71 MRC_CHAR = 17, // non-standard - signed char
72 MRC_UHEX = 101, // 2 4-bit values packed into each 8-bit byte
73 MRC_UNKNOWN = 18
74 };
@ MRC_FLOAT_COMPLEX
Definition: mrcio.h:68
@ MRC_SHORT_COMPLEX
Definition: mrcio.h:67
@ MRC_CHAR
Definition: mrcio.h:71
@ MRC_UCHAR3
Definition: mrcio.h:70
@ MRC_SHORT
Definition: mrcio.h:65
@ MRC_FLOAT
Definition: mrcio.h:66
@ MRC_UNKNOWN
Definition: mrcio.h:73
@ MRC_UCHAR
Definition: mrcio.h:64
@ MRC_UHEX
Definition: mrcio.h:72
@ MRC_USHORT
Definition: mrcio.h:69

Constructor & Destructor Documentation

◆ MrcIO()

MrcIO::MrcIO ( const string &  fname,
IOMode  rw_mode = READ_ONLY 
)
explicit

Definition at line 49 of file mrcio.cpp.

50: ImageIO(fname, rw), mode_size(0),
51 isFEI(false), is_ri(0), is_new_file(false),
52 is_transpose(false), is_stack(false), stack_size(1),
54 rendermin(0.0), rendermax(0.0), renderbits(16)
55{
56 memset(&mrch, 0, sizeof(MrcHeader));
58}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
ImageIO(const string &fname, IOMode rw)
Definition: imageio.cpp:40
bool is_big_endian
Definition: mrcio.h:283
int mode_size
Definition: mrcio.h:264
float rendermin
Definition: mrcio.h:286
float rendermax
Definition: mrcio.h:287
int renderbits
Definition: mrcio.h:288
bool use_given_dimensions
Definition: mrcio.h:280
int is_ri
Definition: mrcio.h:282
bool is_stack
Definition: mrcio.h:275
bool is_transpose
Definition: mrcio.h:285
MrcHeader mrch
Definition: mrcio.h:267
bool isFEI
Definition: mrcio.h:272
bool is_8_bit_packed
Definition: mrcio.h:279
bool is_new_file
Definition: mrcio.h:284
int stack_size
Definition: mrcio.h:276

References is_big_endian, EMAN::ByteOrder::is_host_big_endian(), and mrch.

◆ ~MrcIO()

MrcIO::~MrcIO ( )

Definition at line 60 of file mrcio.cpp.

61{
62 if (file) {
63 fclose(file);
64 file = NULL;
65 }
66}
FILE * file
Definition: imageio.h:354

References EMAN::ImageIO::file.

Member Function Documentation

◆ check_swap()

void MrcIO::check_swap ( const int *  data,
const char *  filnam,
bool  show_errors,
bool &  do_swap,
bool &  have_err 
)
staticprivate

This is a utility routine to tell whether to byte swap MRC header.

Definition at line 230 of file mrcio.cpp.

232{
233 int nx = data[0];
234 int ny = data[1];
235 int nz = data[2];
236 int mrcmode = data[3];
237 int mapc = data[16]; // Which axis corresponds to Columns (X=1, Y=2, Z=3)
238 int mapr = data[17]; // Which axis corresponds to Rows (X=1, Y=2, Z=3)
239 int maps = data[18]; // Which axis corresponds to Sections (X=1, Y=2, Z=3)
240 int nsymbt = data[23]; // the extra bytes for symmetry information
241 int mach = data[44]; // Machine endian stamp
242
243 int nxw, nyw, nzw, modew, mapcw, maprw, mapsw, nsymw, machw;
244
245 nxw = nx;
246 nyw = ny;
247 nzw = nz;
248 modew = mrcmode;
249 mapcw = mapc;
250 maprw = mapr;
251 mapsw = maps;
252 nsymw = nsymbt;
253 machw = mach;
254
258 ByteOrder::swap_bytes(&modew);
259 ByteOrder::swap_bytes(&mapcw);
260 ByteOrder::swap_bytes(&maprw);
261 ByteOrder::swap_bytes(&mapsw);
262 ByteOrder::swap_bytes(&nsymw);
263 ByteOrder::swap_bytes(&machw);
264
265 const int max_dim = 1 << 20;
266
267 int actual_stamp = MrcIO::generate_machine_stamp();
268
269 bool debug = (getenv("DEBUG_MRC_SANITY"));
270
271 string errmsg;
272
273 have_err = false;
274
275 if (mach == actual_stamp) {
276 do_swap = false;
277 }
278 else if (machw == actual_stamp) {
279 do_swap = true;
280 }
281 else {
282 if (mrcmode == 0) {
283 if (1 <= mapr && mapr <= 3 &&
284 1 <= mapc && mapc <= 3 &&
285 1 <= maps && maps <= 3) {
286 do_swap = false;
287 }
288 else if (1 <= maprw && maprw <= 3 &&
289 1 <= mapcw && mapcw <= 3 &&
290 1 <= mapsw && mapsw <= 3) {
291 do_swap = true;
292 }
293 else {
294 double ave_xyz = ((double) nx + (double) ny + (double) nz) / 3.0;
295 double ave_xyzw = ((double) nxw + (double) nyw + (double) nzw) / 3.0;
296
297 if (nx > 0 && ny > 0 && nz > 0 && ave_xyz <= max_dim) {
298 do_swap = false;
299 }
300 else if (nxw > 0 && nyw > 0 && nzw > 0 && ave_xyzw <= max_dim) {
301 do_swap = true;
302 }
303 else {
304 have_err = true;
305 do_swap = false;
306 errmsg = "MRC image dimensions nonpositive or too large.";
307 }
308 }
309 }
310 else {
311 if (mrcmode > 0 && mrcmode < 128) {
312 do_swap = false;
313 }
314 else if (modew > 0 && modew < 128) {
315 do_swap = true;
316 }
317 else {
318 have_err = true;
319 do_swap = false;
320 errmsg = "MRC mode is not from 0 to 127.";
321 }
322 }
323 }
324
325 if (debug || (have_err && show_errors)) {
326 if (filnam) {
327 printf ("file name = '%s'.\n", filnam);
328 }
329
330 printf ("stamp: mach, file, swapd = %8.0x %8.0x %8.0x\n",
331 actual_stamp, mach, machw);
332 printf ("stamp: mach, file, swapd = %d %d %d\n",
333 actual_stamp, mach, machw);
334 printf ("nx, ny, nz, mode = %d %d %d %d\n", nx, ny, nz, mrcmode);
335 printf ("nx, ny, nz, mode swapped = %d %d %d %d\n", nxw, nyw, nzw, modew);
336 printf ("mapc, mapr, maps = %d %d %d\n", mapc, mapr, maps);
337 printf ("mapc, mapr, maps swapped = %d %d %d\n", mapcw, maprw, mapsw);
338 printf ("%s\n", errmsg.c_str());
339 }
340}
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
Definition: byteorder.h:131
static int generate_machine_stamp()
generate the machine stamp used in MRC image format.
Definition: mrcio.cpp:1713

References generate_machine_stamp(), and EMAN::ByteOrder::swap_bytes().

Referenced by is_valid().

◆ generate_machine_stamp()

int MrcIO::generate_machine_stamp ( )
staticprivate

generate the machine stamp used in MRC image format.

Definition at line 1713 of file mrcio.cpp.

1714{
1715 int stamp = 0;
1716 char *p = (char *) (&stamp);
1717
1719 p[0] = 0x11;
1720 p[1] = 0x11;
1721 p[2] = 0;
1722 p[3] = 0;
1723 }
1724 else {
1725 p[0] = 0x44;
1726 p[1] = 0x41;
1727 p[2] = 0;
1728 p[3] = 0;
1729 }
1730
1731 return stamp;
1732}

References EMAN::ByteOrder::is_host_big_endian().

Referenced by check_swap().

◆ get_mode_size()

int MrcIO::get_mode_size ( int  mm)
static

Definition at line 1595 of file mrcio.cpp.

1596{
1597 MrcIO::MrcMode m = static_cast < MrcMode > (mm);
1598
1599 int msize = 0;
1600 switch (m) {
1601 case MRC_CHAR:
1602 case MRC_UCHAR:
1603 msize = sizeof(char);
1604 break;
1605 case MRC_SHORT:
1606 case MRC_USHORT:
1607 case MRC_SHORT_COMPLEX:
1608 msize = sizeof(short);
1609 break;
1610 case MRC_FLOAT:
1611 case MRC_FLOAT_COMPLEX:
1612 msize = sizeof(float);
1613 break;
1614 default:
1615 msize = 0;
1616 }
1617
1618 return msize;
1619}

References MRC_CHAR, MRC_FLOAT, MRC_FLOAT_COMPLEX, MRC_SHORT, MRC_SHORT_COMPLEX, MRC_UCHAR, and MRC_USHORT.

Referenced by is_valid().

◆ get_nimg()

int MrcIO::get_nimg ( )
virtual

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 1740 of file mrcio.cpp.

1741{
1742 init();
1743
1744 return stack_size;
1745}
virtual void init()=0
Do some initialization before doing the read/write.

References EMAN::ImageIO::init(), and stack_size.

◆ is_valid()

bool MrcIO::is_valid ( const void *  first_block,
off_t  file_size = 0 
)
static

Definition at line 342 of file mrcio.cpp.

343{
344 ENTERFUNC;
345
346 if (! first_block) { // Null pointer - no data
347 return false;
348 }
349
350 const int * data = (const int *) first_block;
351
352 int nx = data[0];
353 int ny = data[1];
354 int nz = data[2];
355 int mrcmode = data[3];
356 int nsymbt = data[23]; // the extra bytes for symmetry information
357
358 const int max_dim = 1 << 20;
359
360 bool do_swap, have_err;
361
362 check_swap(data, NULL, false, do_swap, have_err);
363
364 if (have_err) {
365 return false;
366 }
367
368 if (do_swap) {
372 ByteOrder::swap_bytes(&mrcmode);
373 ByteOrder::swap_bytes(&nsymbt);
374 }
375
376 if (mrcmode == MRC_SHORT_COMPLEX || mrcmode == MRC_FLOAT_COMPLEX) {
377 nx *= 2;
378 }
379
380 if ((mrcmode >= MRC_UCHAR &&
381 (mrcmode < MRC_UNKNOWN || mrcmode == MRC_UHEX)) &&
382 (nx > 1 && nx < max_dim) && (ny > 0 && ny < max_dim)
383 && (nz > 0 && nz < max_dim)) {
384
385//#ifndef SPIDERMRC // Spider MRC files don't satisfy the following test
386
387 if (file_size > 0) {
388 off_t file_size1 = (off_t)nx * (off_t)ny * (off_t)nz *
389 (off_t)get_mode_size(mrcmode) +
390 (off_t)sizeof(MrcHeader) + nsymbt;
391
392 if (file_size == file_size1) {
393 return true;
394 }
395
396// return false;
397
398 // when size doesn't match, print error message instead of make it fail
399
400 LOGWARN("image size check fails, still try to read it...");
401 }
402 else {
403 return true;
404 }
405
406//#endif // SPIDERMRC
407
408 return true;
409 }
410
411 EXITFUNC;
412
413 return false;
414}
static void check_swap(const int *data, const char *filnam, bool show_errors, bool &do_swap, bool &have_err)
This is a utility routine to tell whether to byte swap MRC header.
Definition: mrcio.cpp:230
static int get_mode_size(int mm)
Definition: mrcio.cpp:1595
#define LOGWARN
Definition: log.h:53
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References check_swap(), ENTERFUNC, EXITFUNC, get_mode_size(), LOGWARN, MRC_FLOAT_COMPLEX, MRC_SHORT_COMPLEX, MRC_UCHAR, MRC_UHEX, MRC_UNKNOWN, and EMAN::ByteOrder::swap_bytes().

Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().

◆ read_ctf()

int MrcIO::read_ctf ( Ctf ctf,
int  image_index = 0 
)
virtual

Read CTF data from this image.

Parameters
ctfUsed to store the CTF data.
image_indexThe index of the image to read.
Returns
0 if OK; 1 if error.

Reimplemented from EMAN::ImageIO.

Definition at line 1551 of file mrcio.cpp.

1552{
1553 ENTERFUNC;
1554
1555 init();
1556
1557 size_t n = strlen(CTF_MAGIC);
1558 int err = 1;
1559
1560 if (strncmp(mrch.labels[0], CTF_MAGIC, n) == 0) {
1561 err = ctf.from_string(string(&mrch.labels[0][n]));
1562 }
1563
1564 EXITFUNC;
1565
1566 return err;
1567}
virtual int from_string(const string &ctf)=0
static const char * CTF_MAGIC
Definition: mrcio.h:260
char labels[MRC_NUM_LABELS][MRC_LABEL_SIZE]
Definition: mrcio.h:138

References CTF_MAGIC, ENTERFUNC, EXITFUNC, EMAN::Ctf::from_string(), EMAN::ImageIO::init(), EMAN::MrcIO::MrcHeader::labels, and mrch.

Referenced by read_mrc_header().

◆ read_fei_header()

int MrcIO::read_fei_header ( Dict dict,
int  image_index = 0,
const Region area = 0,
bool  is_3d = false 
)
private

Definition at line 574 of file mrcio.cpp.

575{
576 ENTERFUNC;
577
578 if(image_index < 0) {
579 image_index = 0;
580 }
581
582 init();
583
585
586 int xlen = 0, ylen = 0, zlen = 0;
587
588 EMUtil::get_region_dims(area, feimrch.nx, & xlen, feimrch.ny, & ylen, feimrch.nz, & zlen);
589
590 dict["nx"] = xlen;
591 dict["ny"] = ylen;
592 dict["nz"] = zlen;
593 dict["FEIMRC.nx"] = feimrch.nx;
594 dict["FEIMRC.ny"] = feimrch.ny;
595 dict["FEIMRC.nz"] = feimrch.nz;
596
597 dict["datatype"] = to_em_datatype(feimrch.mode); //=1, FEI-MRC file always use short for data type
598
599 dict["FEIMRC.nxstart"] = feimrch.nxstart;
600 dict["FEIMRC.nystart"] = feimrch.nystart;
601 dict["FEIMRC.nzstart"] = feimrch.nzstart;
602
603 dict["FEIMRC.mx"] = feimrch.mx;
604 dict["FEIMRC.my"] = feimrch.my;
605 dict["FEIMRC.mz"] = feimrch.mz;
606
607 dict["FEIMRC.xlen"] = feimrch.xlen;
608 dict["FEIMRC.ylen"] = feimrch.ylen;
609 dict["FEIMRC.zlen"] = feimrch.zlen;
610
611 dict["FEIMRC.alpha"] = feimrch.alpha;
612 dict["FEIMRC.beta"] = feimrch.beta;
613 dict["FEIMRC.gamma"] = feimrch.gamma;
614
615 dict["FEIMRC.mapc"] = feimrch.mapc;
616 dict["FEIMRC.mapr"] = feimrch.mapr;
617 dict["FEIMRC.maps"] = feimrch.maps;
618
619 dict["FEIMRC.minimum"] = feimrch.amin;
620 dict["FEIMRC.maximum"] = feimrch.amax;
621 dict["FEIMRC.mean"] = feimrch.amean;
622// dict["mean"] = feimrch.amean;
623
624 dict["FEIMRC.ispg"] = feimrch.ispg;
625 dict["FEIMRC.nsymbt"] = feimrch.nsymbt;
626
627 dict["apix_x"] = feimrch.xlen / feimrch.mx;
628 dict["apix_y"] = feimrch.ylen / feimrch.my;
629 dict["apix_z"] = feimrch.zlen / feimrch.mz;
630
631 dict["FEIMRC.next"] = feimrch.next; //offset from end of header to the first dataset
632 dict["FEIMRC.dvid"] = feimrch.dvid;
633 dict["FEIMRC.numintegers"] = feimrch.numintegers;
634 dict["FEIMRC.numfloats"] = feimrch.numfloats;
635 dict["FEIMRC.sub"] = feimrch.sub;
636 dict["FEIMRC.zfac"] = feimrch.zfac;
637
638 dict["FEIMRC.min2"] = feimrch.min2;
639 dict["FEIMRC.max2"] = feimrch.max2;
640 dict["FEIMRC.min3"] = feimrch.min3;
641 dict["FEIMRC.max3"] = feimrch.max3;
642 dict["FEIMRC.min4"] = feimrch.min4;
643 dict["FEIMRC.max4"] = feimrch.max4;
644
645 dict["FEIMRC.idtype"] = feimrch.idtype;
646 dict["FEIMRC.lens"] = feimrch.lens;
647 dict["FEIMRC.nd1"] = feimrch.nd1;
648 dict["FEIMRC.nd2"] = feimrch.nd2;
649 dict["FEIMRC.vd1"] = feimrch.vd1;
650 dict["FEIMRC.vd2"] = feimrch.vd2;
651
652 char label[32];
653
654 for(int i=0; i<9; i++) { // 9 tilt angles
655 sprintf(label, "MRC.tiltangles%d", i);
656 dict[string(label)] = feimrch.tiltangles[i];
657 }
658
659 dict["FEIMRC.zorg"] = feimrch.zorg;
660 dict["FEIMRC.xorg"] = feimrch.xorg;
661 dict["FEIMRC.yorg"] = feimrch.yorg;
662
663 dict["FEIMRC.nlabl"] = feimrch.nlabl;
664
665 for (int i = 0; i < feimrch.nlabl; i++) {
666 sprintf(label, "MRC.label%d", i);
667 dict[string(label)] = string(feimrch.labl[i], MRC_LABEL_SIZE);
668 }
669
670 /* Read extended image header by specified image index */
671 FeiMrcExtHeader feiexth;
672
673 portable_fseek(file, sizeof(FeiMrcHeader)+sizeof(FeiMrcExtHeader)*image_index, SEEK_SET);
674
675 if (fread(&feiexth, sizeof(FeiMrcExtHeader), 1, file) != 1) {
676 throw ImageReadException(filename, "FEI MRC extended header");
677 }
678
679 dict["FEIMRC.a_tilt"] = feiexth.a_tilt;
680 dict["FEIMRC.b_tilt"] = feiexth.b_tilt;
681
682 dict["FEIMRC.x_stage"] = feiexth.x_stage;
683 dict["FEIMRC.y_stage"] = feiexth.y_stage;
684 dict["FEIMRC.z_stage"] = feiexth.z_stage;
685
686 dict["FEIMRC.x_shift"] = feiexth.x_shift;
687 dict["FEIMRC.y_shift"] = feiexth.y_shift;
688
689 dict["FEIMRC.defocus"] = feiexth.defocus;
690 dict["FEIMRC.exp_time"] = feiexth.exp_time;
691 dict["FEIMRC.mean_int"] = feiexth.mean_int;
692 dict["FEIMRC.tilt_axis"] = feiexth.tilt_axis;
693
694 dict["FEIMRC.pixel_size"] = feiexth.pixel_size;
695 dict["apix_x"] = feiexth.pixel_size *1.0e10;
696 dict["apix_y"] = feiexth.pixel_size *1.0e10;
697 dict["apix_z"] = feiexth.pixel_size *1.0e10;
698 dict["FEIMRC.magnification"] = feiexth.magnification;
699 dict["FEIMRC.ht"] = feiexth.ht;
700 dict["FEIMRC.binning"] = feiexth.binning;
701 dict["FEIMRC.appliedDefocus"] = feiexth.appliedDefocus;
702
703 // remainder 16 4-byte floats not used
704
705 EXITFUNC;
706
707 return 0;
708}
static void get_region_dims(const Region *area, int nx, int *area_x, int ny, int *area_y, int nz=1, int *area_z=0)
Get a region's dimensions.
Definition: emutil.cpp:860
FloatSize is used to describe a 1D, 2D or 3D rectangular size in floating numbers.
Definition: geometry.h:105
string filename
Definition: imageio.h:352
void check_region(const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
Validate image I/O region.
Definition: imageio.cpp:58
static int to_em_datatype(int mrcmode)
Definition: mrcio.cpp:1621
FeiMrcHeader feimrch
Definition: mrcio.h:268
#define ImageReadException(filename, desc)
Definition: exception.h:204
int portable_fseek(FILE *fp, off_t offset, int whence)
char labl[MRC_NUM_LABELS][MRC_LABEL_SIZE]
Definition: mrcio.h:222

References EMAN::MrcIO::FeiMrcExtHeader::a_tilt, EMAN::MrcIO::FeiMrcHeader::alpha, EMAN::MrcIO::FeiMrcHeader::amax, EMAN::MrcIO::FeiMrcHeader::amean, EMAN::MrcIO::FeiMrcHeader::amin, EMAN::MrcIO::FeiMrcExtHeader::appliedDefocus, EMAN::MrcIO::FeiMrcExtHeader::b_tilt, EMAN::MrcIO::FeiMrcHeader::beta, EMAN::MrcIO::FeiMrcExtHeader::binning, EMAN::ImageIO::check_region(), EMAN::MrcIO::FeiMrcExtHeader::defocus, EMAN::MrcIO::FeiMrcHeader::dvid, ENTERFUNC, EXITFUNC, EMAN::MrcIO::FeiMrcExtHeader::exp_time, feimrch, EMAN::ImageIO::file, EMAN::ImageIO::filename, EMAN::MrcIO::FeiMrcHeader::gamma, EMAN::EMUtil::get_region_dims(), EMAN::MrcIO::FeiMrcExtHeader::ht, EMAN::MrcIO::FeiMrcHeader::idtype, ImageReadException, EMAN::ImageIO::init(), is_new_file, EMAN::MrcIO::FeiMrcHeader::ispg, EMAN::MrcIO::FeiMrcHeader::labl, EMAN::MrcIO::FeiMrcHeader::lens, EMAN::MrcIO::FeiMrcExtHeader::magnification, EMAN::MrcIO::FeiMrcHeader::mapc, EMAN::MrcIO::FeiMrcHeader::mapr, EMAN::MrcIO::FeiMrcHeader::maps, EMAN::MrcIO::FeiMrcHeader::max2, EMAN::MrcIO::FeiMrcHeader::max3, EMAN::MrcIO::FeiMrcHeader::max4, EMAN::MrcIO::FeiMrcExtHeader::mean_int, EMAN::MrcIO::FeiMrcHeader::min2, EMAN::MrcIO::FeiMrcHeader::min3, EMAN::MrcIO::FeiMrcHeader::min4, EMAN::MrcIO::FeiMrcHeader::mode, MRC_LABEL_SIZE, EMAN::MrcIO::FeiMrcHeader::mx, EMAN::MrcIO::FeiMrcHeader::my, EMAN::MrcIO::FeiMrcHeader::mz, EMAN::MrcIO::FeiMrcHeader::nd1, EMAN::MrcIO::FeiMrcHeader::nd2, EMAN::MrcIO::FeiMrcHeader::next, EMAN::MrcIO::FeiMrcHeader::nlabl, EMAN::MrcIO::FeiMrcHeader::nsymbt, EMAN::MrcIO::FeiMrcHeader::numfloats, EMAN::MrcIO::FeiMrcHeader::numintegers, EMAN::MrcIO::FeiMrcHeader::nx, EMAN::MrcIO::FeiMrcHeader::nxstart, EMAN::MrcIO::FeiMrcHeader::ny, EMAN::MrcIO::FeiMrcHeader::nystart, EMAN::MrcIO::FeiMrcHeader::nz, EMAN::MrcIO::FeiMrcHeader::nzstart, EMAN::MrcIO::FeiMrcExtHeader::pixel_size, portable_fseek(), EMAN::MrcIO::FeiMrcHeader::sub, EMAN::MrcIO::FeiMrcExtHeader::tilt_axis, EMAN::MrcIO::FeiMrcHeader::tiltangles, to_em_datatype(), EMAN::MrcIO::FeiMrcHeader::vd1, EMAN::MrcIO::FeiMrcHeader::vd2, EMAN::MrcIO::FeiMrcExtHeader::x_shift, EMAN::MrcIO::FeiMrcExtHeader::x_stage, EMAN::MrcIO::FeiMrcHeader::xlen, EMAN::MrcIO::FeiMrcHeader::xorg, EMAN::MrcIO::FeiMrcExtHeader::y_shift, EMAN::MrcIO::FeiMrcExtHeader::y_stage, EMAN::MrcIO::FeiMrcHeader::ylen, EMAN::MrcIO::FeiMrcHeader::yorg, EMAN::MrcIO::FeiMrcExtHeader::z_stage, EMAN::MrcIO::FeiMrcHeader::zfac, EMAN::MrcIO::FeiMrcHeader::zlen, and EMAN::MrcIO::FeiMrcHeader::zorg.

◆ read_mrc_header()

int MrcIO::read_mrc_header ( Dict dict,
int  image_index = 0,
const Region area = 0,
bool  is_3d = false 
)
private

Definition at line 428 of file mrcio.cpp.

429{
430 ENTERFUNC;
431
432 if (image_index < 0) {
433 image_index = 0;
434 }
435
436 if (image_index != 0 && ! is_stack) {
438 "no stack allowed for MRC image. For take 2D slice out of 3D image, "
439 "read the 3D image first, then use get_clip().");
440 }
441
443
444 int xlen = 0, ylen = 0, zlen = 0;
445
446 EMUtil::get_region_dims(area, mrch.nx, & xlen, mrch.ny, & ylen, mrch.nz, & zlen);
447
448 dict["nx"] = xlen;
449 dict["ny"] = ylen;
450 dict["nz"] = zlen;
451 dict["MRC.nx"] = mrch.nx;
452 dict["MRC.ny"] = mrch.ny;
453 dict["MRC.nz"] = mrch.nz;
454
455 dict["datatype"] = to_em_datatype(mrch.mode);
456
457 dict["MRC.nxstart"] = mrch.nxstart;
458 dict["MRC.nystart"] = mrch.nystart;
459 dict["MRC.nzstart"] = mrch.nzstart;
460
461 dict["MRC.mx"] = mrch.mx;
462 dict["MRC.my"] = mrch.my;
463 dict["MRC.mz"] = mrch.mz;
464
465 dict["MRC.xlen"] = mrch.xlen;
466 dict["MRC.ylen"] = mrch.ylen;
467 dict["MRC.zlen"] = mrch.zlen;
468
469 dict["MRC.alpha"] = mrch.alpha;
470 dict["MRC.beta"] = mrch.beta;
471 dict["MRC.gamma"] = mrch.gamma;
472
473 dict["MRC.mapc"] = mrch.mapc;
474 dict["MRC.mapr"] = mrch.mapr;
475 dict["MRC.maps"] = mrch.maps;
476
477 dict["MRC.minimum"] = mrch.amin;
478 dict["MRC.maximum"] = mrch.amax;
479 dict["MRC.mean"] = mrch.amean;
480// dict["minimum"] = mrch.amin;
481// dict["maximum"] = mrch.amax;
482// dict["mean"] = mrch.amean;
483
484 dict["MRC.ispg"] = mrch.ispg;
485 dict["MRC.nsymbt"] = mrch.nsymbt;
486
487 float apx = mrch.xlen / mrch.mx;
488 float apy = mrch.ylen / mrch.my;
489 float apz = mrch.zlen / mrch.mz;
490
491 if (apx > 1000 || apx < 0.01) {
492 dict["apix_x"] = 1.0f;
493 }
494 else {
495 dict["apix_x"] = apx;
496 }
497
498 if (apy > 1000 || apy < 0.01) {
499 dict["apix_y"] = 1.0f;
500 }
501 else {
502 dict["apix_y"] = apy;
503 }
504
505 if (apz > 1000 || apz < 0.01) {
506 dict["apix_z"] = 1.0f;
507 }
508 else {
509 dict["apix_z"] = apz;
510 }
511
512 if (area) {
513 dict["origin_x"] = mrch.xorigin + mrch.xlen * area->origin[0];
514 dict["origin_y"] = mrch.yorigin + mrch.xlen * area->origin[1];
515
516 if (area->get_ndim() == 3 && mrch.nz > 1) {
517 dict["origin_z"] = mrch.zorigin + mrch.xlen * area->origin[2];
518 }
519 else {
520 dict["origin_z"] = mrch.zorigin;
521 }
522 }
523 else {
524 dict["origin_x"] = mrch.xorigin;
525 dict["origin_y"] = mrch.yorigin;
526 dict["origin_z"] = mrch.zorigin;
527 }
528
529 if (is_complex_mode()) {
530 dict["is_complex"] = 1;
531 dict["is_complex_ri"] = 1;
532 }
533
534 dict["MRC.machinestamp"] = mrch.machinestamp;
535
536 dict["MRC.rms"] = mrch.rms;
537 dict["sigma"] = mrch.rms;
538 dict["MRC.nlabels"] = mrch.nlabels;
539
540 char label[32];
541
542 for (int i = 0; i < mrch.nlabels; i++) {
543 sprintf(label, "MRC.label%d", i);
544 dict[string(label)] = string(mrch.labels[i], MRC_LABEL_SIZE);
545 }
546
547 EMAN1Ctf ctf_;
548
549 if (read_ctf(ctf_) == 0) {
550 vector<float> vctf = ctf_.to_vector();
551 dict["ctf"] = vctf;
552 }
553
554 if (is_transpose) {
555 dict["nx"] = ylen;
556 dict["ny"] = xlen;
557 dict["MRC.nx"] = mrch.ny;
558 dict["MRC.ny"] = mrch.nx;
559 dict["MRC.mx"] = mrch.my;
560 dict["MRC.my"] = mrch.mx;
561 dict["apix_x"] = mrch.ylen / mrch.my;
562 dict["apix_y"] = mrch.xlen / mrch.mx;
563 dict["origin_x"] = mrch.yorigin;
564 dict["origin_y"] = mrch.xorigin;
565 dict["MRC.nxstart"] = mrch.nystart;
566 dict["MRC.nystart"] = mrch.nxstart;
567 }
568
569 EXITFUNC;
570
571 return 0;
572}
EMAN1Ctf is the CTF model used in EMAN1.
Definition: ctf.h:120
vector< float > to_vector() const
Definition: ctf.cpp:127
virtual bool is_complex_mode()=0
Is this an complex image or not.
int read_ctf(Ctf &ctf, int image_index=0)
Read CTF data from this image.
Definition: mrcio.cpp:1551
int get_ndim() const
Get the region's dimension.
Definition: geometry.h:644
FloatPoint origin
Definition: geometry.h:654

References EMAN::MrcIO::MrcHeader::alpha, EMAN::MrcIO::MrcHeader::amax, EMAN::MrcIO::MrcHeader::amean, EMAN::MrcIO::MrcHeader::amin, EMAN::MrcIO::MrcHeader::beta, EMAN::ImageIO::check_region(), ENTERFUNC, EXITFUNC, EMAN::ImageIO::filename, EMAN::MrcIO::MrcHeader::gamma, EMAN::Region::get_ndim(), EMAN::EMUtil::get_region_dims(), ImageReadException, EMAN::ImageIO::is_complex_mode(), is_new_file, is_stack, is_transpose, EMAN::MrcIO::MrcHeader::ispg, EMAN::MrcIO::MrcHeader::labels, EMAN::MrcIO::MrcHeader::machinestamp, EMAN::MrcIO::MrcHeader::mapc, EMAN::MrcIO::MrcHeader::mapr, EMAN::MrcIO::MrcHeader::maps, EMAN::MrcIO::MrcHeader::mode, MRC_LABEL_SIZE, mrch, EMAN::MrcIO::MrcHeader::mx, EMAN::MrcIO::MrcHeader::my, EMAN::MrcIO::MrcHeader::mz, EMAN::MrcIO::MrcHeader::nlabels, EMAN::MrcIO::MrcHeader::nsymbt, EMAN::MrcIO::MrcHeader::nx, EMAN::MrcIO::MrcHeader::nxstart, EMAN::MrcIO::MrcHeader::ny, EMAN::MrcIO::MrcHeader::nystart, EMAN::MrcIO::MrcHeader::nz, EMAN::MrcIO::MrcHeader::nzstart, EMAN::Region::origin, read_ctf(), EMAN::MrcIO::MrcHeader::rms, to_em_datatype(), EMAN::EMAN1Ctf::to_vector(), EMAN::MrcIO::MrcHeader::xlen, EMAN::MrcIO::MrcHeader::xorigin, EMAN::MrcIO::MrcHeader::ylen, EMAN::MrcIO::MrcHeader::yorigin, EMAN::MrcIO::MrcHeader::zlen, and EMAN::MrcIO::MrcHeader::zorigin.

◆ swap_header()

void MrcIO::swap_header ( MrcHeader mrch)
private

◆ to_em_datatype()

int MrcIO::to_em_datatype ( int  mrcmode)
static

Definition at line 1621 of file mrcio.cpp.

1622{
1624
1625 switch (m) {
1626 case MRC_CHAR:
1627 e = EMUtil::EM_CHAR;
1628 break;
1629 case MRC_UCHAR:
1630 e = EMUtil::EM_UCHAR;
1631 break;
1632 case MRC_SHORT:
1633 e = EMUtil::EM_SHORT;
1634 break;
1635 case MRC_USHORT:
1637 break;
1638 case MRC_SHORT_COMPLEX:
1640 break;
1641 case MRC_FLOAT:
1642 e = EMUtil::EM_FLOAT;
1643 break;
1644 case MRC_FLOAT_COMPLEX:
1646 break;
1647 default:
1649 }
1650
1651 return e;
1652}
EMDataType
Image pixel data type used in EMAN.
Definition: emutil.h:92
@ EM_UCHAR
Definition: emutil.h:95
@ EM_UNKNOWN
Definition: emutil.h:93
@ EM_USHORT
Definition: emutil.h:97
@ EM_FLOAT_COMPLEX
Definition: emutil.h:104
@ EM_SHORT_COMPLEX
Definition: emutil.h:102
@ EM_SHORT
Definition: emutil.h:96

References EMAN::EMUtil::EM_CHAR, EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_FLOAT_COMPLEX, EMAN::EMUtil::EM_SHORT, EMAN::EMUtil::EM_SHORT_COMPLEX, EMAN::EMUtil::EM_UCHAR, EMAN::EMUtil::EM_UNKNOWN, EMAN::EMUtil::EM_USHORT, MRC_CHAR, MRC_FLOAT, MRC_FLOAT_COMPLEX, MRC_SHORT, MRC_SHORT_COMPLEX, MRC_UCHAR, and MRC_USHORT.

Referenced by read_fei_header(), and read_mrc_header().

◆ to_mrcmode()

int MrcIO::to_mrcmode ( int  em_datatype,
int  is_complex 
)
static

Definition at line 1654 of file mrcio.cpp.

1655{
1656 MrcMode m = MRC_UNKNOWN;
1657 EMUtil::EMDataType em_type = static_cast < EMUtil::EMDataType > (e);
1658
1659 switch (em_type) {
1660 case EMUtil::EM_CHAR:
1661 m = MRC_CHAR;
1662
1663 break;
1664 case EMUtil::EM_UCHAR:
1665 m = MRC_UCHAR;
1666
1667 break;
1668 case EMUtil::EM_USHORT:
1669 if (is_complex) {
1671 }
1672 else {
1673 m = MRC_USHORT;
1674 }
1675
1676 break;
1677 case EMUtil::EM_SHORT:
1678 if (is_complex) {
1680 }
1681 else {
1682 m = MRC_SHORT;
1683 }
1684
1685 break;
1689
1690 break;
1691 case EMUtil::EM_INT:
1692 case EMUtil::EM_UINT:
1693 case EMUtil::EM_FLOAT:
1694 if (is_complex) {
1696 }
1697 else {
1698 m = MRC_FLOAT;
1699 }
1700
1701 break;
1704
1705 break;
1706 default:
1707 m = MRC_FLOAT;
1708 }
1709
1710 return m;
1711}
@ EM_USHORT_COMPLEX
Definition: emutil.h:103
bool is_complex() const
Is this a complex image?

References EMAN::EMUtil::EM_CHAR, EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_FLOAT_COMPLEX, EMAN::EMUtil::EM_INT, EMAN::EMUtil::EM_SHORT, EMAN::EMUtil::EM_SHORT_COMPLEX, EMAN::EMUtil::EM_UCHAR, EMAN::EMUtil::EM_UINT, EMAN::EMUtil::EM_USHORT, EMAN::EMUtil::EM_USHORT_COMPLEX, is_complex(), MRC_CHAR, MRC_FLOAT, MRC_FLOAT_COMPLEX, MRC_SHORT, MRC_SHORT_COMPLEX, MRC_UCHAR, MRC_UNKNOWN, and MRC_USHORT.

◆ transpose()

int MrcIO::transpose ( float *  data,
int  nx,
int  ny,
int  nz 
) const
private

Definition at line 1747 of file mrcio.cpp.

1748{
1749 float * tmp = new float[xlen*ylen];
1750
1751 for(size_t z=0; z<(size_t)zlen; ++z) {
1752 for(size_t y=0; y<(size_t)ylen; ++y) {
1753 for(size_t x=0; x<(size_t)xlen; ++x) {
1754 tmp[x*ylen+y] = data[z*xlen*ylen+y*xlen+x];
1755 }
1756 }
1757
1758 std::copy(tmp, tmp+xlen*ylen, data+z*xlen*ylen);
1759 }
1760
1761 delete [] tmp;
1762
1763 return 0;
1764}
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References copy(), x, and y.

◆ update_stats()

void MrcIO::update_stats ( void *  data,
size_t  size 
)
private

This is a utility function used to calculate new min/max/mean/sigma when write MRC file as 16 bit or 8 bit.

It will write new set of min/max/mean/sigma to mrch. this function needs get the output data storage type from mrch.mode.

Definition at line 1406 of file mrcio.cpp.

1407{
1408 float v; // variable to hold pixel value
1409 double sum;
1410 double square_sum;
1411 double mean;
1412 double sigma;
1413 double vv;
1414 float min, max;
1415
1416 signed char * scdata = NULL;
1417 unsigned char * cdata = NULL;
1418 short * sdata = NULL;
1419 unsigned short * usdata = NULL;
1420
1421 bool use_schar = (mrch.mode == MRC_CHAR);
1422 bool use_uchar = (mrch.mode == MRC_UCHAR);
1423 bool use_short = (mrch.mode == MRC_SHORT || mrch.mode == MRC_SHORT_COMPLEX);
1424 bool use_ushort = (mrch.mode == MRC_USHORT);
1425
1426 if (use_uchar) {
1427 max = 0.0;
1428 min = UCHAR_MAX;
1429 cdata = (unsigned char *) data;
1430 }
1431 else if (use_schar) {
1432 max = SCHAR_MIN;
1433 min = SCHAR_MAX;
1434 scdata = (signed char *) data;
1435 }
1436 else if (use_short) {
1437 max = (float) SHRT_MIN;
1438 min = (float) SHRT_MAX;
1439 sdata = (short *) data;
1440 }
1441 else if (use_ushort) {
1442 max = 0.0f;
1443 min = (float) USHRT_MAX;
1444 usdata = (unsigned short *) data;
1445 }
1446 else {
1447 throw InvalidCallException("This function is used to write 8bit/16bit mrc file only.");
1448 }
1449
1450 sum = 0.0;
1451
1452 for (size_t i = 0; i < size; i++) {
1453 if (use_uchar) {
1454 v = (float) (cdata[i]);
1455 }
1456 else if (use_schar) {
1457 v = (float) (scdata[i]);
1458 }
1459 else if (use_short) {
1460 v = (float) (sdata[i]);
1461 }
1462 else {
1463 v = (float) (usdata[i]);
1464 }
1465
1466 if (v < min) min = v;
1467 if (v > max) max = v;
1468
1469 sum = sum + v;
1470 }
1471
1472 if (size > 0) {
1473 mean = sum / (double) size;
1474 }
1475 else {
1476 mean = 0.0;
1477 }
1478
1479 square_sum = 0.0;
1480
1481 for (size_t i = 0; i < size; i++) {
1482 if (use_uchar) {
1483 v = (float) (cdata[i]);
1484 }
1485 else if (use_schar) {
1486 v = (float) (scdata[i]);
1487 }
1488 else if (use_short) {
1489 v = (float) (sdata[i]);
1490 }
1491 else {
1492 v = (float) (usdata[i]);
1493 }
1494
1495 vv = v - mean;
1496
1497 square_sum = square_sum + vv * vv;
1498 }
1499
1500 if (size > 1) {
1501 sigma = std::sqrt(square_sum / (double) (size-1));
1502 }
1503 else {
1504 sigma = 0.0;
1505 }
1506
1507 /* change mrch.amin / amax / amean / rms here */
1508
1509 mrch.amin = min;
1510 mrch.amax = max;
1511 mrch.amean = (float) mean;
1512 mrch.rms = (float) sigma;
1513
1514// MrcHeader mrch2 = mrch;
1515//
1516// endian issue, can't get use_host_endian argument
1517// bool opposite_endian = false;
1518//
1519// if (!is_new_file) {
1520// if (is_big_endian != ByteOrder::is_host_big_endian()) {
1521// opposite_endian = true;
1522// }
1523//
1524// portable_fseek(mrcfile, 0, SEEK_SET);
1525// }
1526//
1527// if (opposite_endian || !use_host_endian) {
1528// swap_header(mrch2);
1529// }
1530
1531 portable_fseek(file, 0, SEEK_SET);
1532
1533 if (fwrite(& mrch, sizeof(MrcHeader), 1, file) != 1) {
1534 throw ImageWriteException(filename, "Error writing MRC header to update statistics.");
1535 }
1536
1537 portable_fseek(file, sizeof(MrcHeader), SEEK_SET);
1538}
EMData * sqrt() const
return square root of current image
#define ImageWriteException(imagename, desc)
Definition: exception.h:223
#define InvalidCallException(desc)
Definition: exception.h:348

References EMAN::MrcIO::MrcHeader::amax, EMAN::MrcIO::MrcHeader::amean, EMAN::MrcIO::MrcHeader::amin, EMAN::ImageIO::file, EMAN::ImageIO::filename, ImageWriteException, InvalidCallException, EMAN::MrcIO::MrcHeader::mode, MRC_CHAR, MRC_SHORT, MRC_SHORT_COMPLEX, MRC_UCHAR, MRC_USHORT, mrch, portable_fseek(), EMAN::MrcIO::MrcHeader::rms, and sqrt().

◆ write_ctf()

void MrcIO::write_ctf ( const Ctf ctf,
int  image_index = 0 
)
virtual

Write CTF data to this image.

Parameters
ctfCtf instance storing the CTF data.
image_indexThe index of the image to write.
Returns
0 if OK; 1 if error.

Reimplemented from EMAN::ImageIO.

Definition at line 1569 of file mrcio.cpp.

1570{
1571 ENTERFUNC;
1572
1573 init();
1574
1575 string ctf_str = ctf.to_string();
1576
1577 strcpy (mrch.labels[0], CTF_MAGIC);
1578 strncat(mrch.labels[0], ctf_str.c_str(),
1579 MRC_LABEL_SIZE - strlen(CTF_MAGIC) - 1);
1580
1581 rewind(file);
1582
1583 if (fwrite(&mrch, sizeof(MrcHeader), 1, file) != 1) {
1584 throw ImageWriteException(filename, "write CTF info to header failed");
1585 }
1586
1587 EXITFUNC;
1588}
virtual string to_string() const =0

References CTF_MAGIC, ENTERFUNC, EXITFUNC, EMAN::ImageIO::file, EMAN::ImageIO::filename, ImageWriteException, EMAN::ImageIO::init(), EMAN::MrcIO::MrcHeader::labels, MRC_LABEL_SIZE, mrch, and EMAN::Ctf::to_string().

Member Data Documentation

◆ 

union { ... } EMAN::MrcIO::@9

◆ CTF_MAGIC

const char * MrcIO::CTF_MAGIC = "!-"
staticprivate

Definition at line 260 of file mrcio.h.

Referenced by read_ctf(), and write_ctf().

◆ DEFINE_IMAGEIO_FUNC

EMAN::MrcIO::DEFINE_IMAGEIO_FUNC

Definition at line 50 of file mrcio.h.

◆ feimrch

FeiMrcHeader EMAN::MrcIO::feimrch

Definition at line 268 of file mrcio.h.

Referenced by read_fei_header().

◆ is_8_bit_packed

bool EMAN::MrcIO::is_8_bit_packed
private

Definition at line 279 of file mrcio.h.

◆ is_big_endian

bool EMAN::MrcIO::is_big_endian
private

Definition at line 283 of file mrcio.h.

Referenced by MrcIO().

◆ is_new_file

bool EMAN::MrcIO::is_new_file
private

Definition at line 284 of file mrcio.h.

Referenced by read_fei_header(), and read_mrc_header().

◆ is_ri

int EMAN::MrcIO::is_ri
private

Definition at line 282 of file mrcio.h.

◆ is_stack

bool EMAN::MrcIO::is_stack
private

Definition at line 275 of file mrcio.h.

Referenced by read_mrc_header().

◆ is_transpose

bool EMAN::MrcIO::is_transpose
private

Definition at line 285 of file mrcio.h.

Referenced by read_mrc_header().

◆ isFEI

bool EMAN::MrcIO::isFEI
private

Definition at line 272 of file mrcio.h.

◆ mode_size

int EMAN::MrcIO::mode_size
private

Definition at line 264 of file mrcio.h.

◆ mrch

MrcHeader EMAN::MrcIO::mrch

Definition at line 267 of file mrcio.h.

Referenced by MrcIO(), read_ctf(), read_mrc_header(), swap_header(), update_stats(), and write_ctf().

◆ renderbits

int EMAN::MrcIO::renderbits
private

Definition at line 288 of file mrcio.h.

◆ rendermax

float EMAN::MrcIO::rendermax
private

Definition at line 287 of file mrcio.h.

◆ rendermin

float EMAN::MrcIO::rendermin
private

Definition at line 286 of file mrcio.h.

◆ SHORT_CTF_MAGIC

const char * MrcIO::SHORT_CTF_MAGIC = "!$"
staticprivate

Definition at line 261 of file mrcio.h.

◆ stack_size

int EMAN::MrcIO::stack_size
private

Definition at line 276 of file mrcio.h.

Referenced by get_nimg().

◆ use_given_dimensions

bool EMAN::MrcIO::use_given_dimensions
private

Definition at line 280 of file mrcio.h.


The documentation for this class was generated from the following files: