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

XPLOR image format is in ASCII: More...

#include <xplorio.h>

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

Public Member Functions

 XplorIO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~XplorIO ()
 
- 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 int read_ctf (Ctf &ctf, int image_index=0)
 Read CTF data from this image. More...
 
virtual void write_ctf (const Ctf &ctf, int image_index=0)
 Write CTF data to this image. More...
 
virtual void flush ()=0
 Flush the IO buffer. More...
 
virtual int get_nimg ()
 Return the number of images in this image file. 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)
 

Public Attributes

 DEFINE_IMAGEIO_FUNC
 

Private Attributes

bool is_big_endian
 
bool is_new_file
 
int nlines_in_header
 
int nx
 
int ny
 
int nz
 
float apix_x
 
float apix_y
 
float apix_z
 
float cell_alpha
 
float cell_beta
 
float cell_gama
 

Static Private Attributes

static const string SECTION_MODE = "ZYX"
 
static const int NFLOAT_PER_LINE = 6
 
static const int INTEGER_SIZE = 8
 
static const int FLOAT_SIZE = 12
 
static const char * OUTFORMAT = "%12.5E"
 

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

XPLOR image format is in ASCII:

  1. header: (note: each integer takes 8 Bytes space, each float is 12.5E format.) line 1: empty line 2: int: number of lines for title (ntitle) next ntitle lines: string: titles line ntitle+3: 9 int: nx, xmin, xmax, ny, ymin, ymax, nz, zmin, zmax line ntitle+4: 6 float: cell size (x, y, z), cell angles (alpha, beta, gamma) line ntitle+5: string: ZYX (this is the section mode. always ZYX)
  2. data

    for zindex = 1 to nz: zindex nx*ny floats. each line has 6 floats. each float is in 12.5E format.

A XPLOR file contains one 2D or 3D image.

Definition at line 60 of file xplorio.h.

Constructor & Destructor Documentation

◆ XplorIO()

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

Definition at line 56 of file xplorio.cpp.

57: ImageIO(fname, rw)
58{
60 is_new_file = false;
62
63 nx = 0;
64 ny = 0;
65 nz = 0;
66
67 apix_x = 0;
68 apix_y = 0;
69 apix_z = 0;
70
71 cell_alpha = 0;
72 cell_beta = 0;
73 cell_gama = 0;
74}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
ImageIO(const string &fname, IOMode rw)
Definition: imageio.cpp:40
int nlines_in_header
Definition: xplorio.h:72
bool is_big_endian
Definition: xplorio.h:70
float cell_beta
Definition: xplorio.h:83
bool is_new_file
Definition: xplorio.h:71
float cell_alpha
Definition: xplorio.h:82
float cell_gama
Definition: xplorio.h:84
float apix_y
Definition: xplorio.h:79
float apix_x
Definition: xplorio.h:78
float apix_z
Definition: xplorio.h:80

References apix_x, apix_y, apix_z, cell_alpha, cell_beta, cell_gama, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), is_new_file, nlines_in_header, nx, ny, and nz.

◆ ~XplorIO()

XplorIO::~XplorIO ( )

Definition at line 76 of file xplorio.cpp.

77{
78 if (file) {
79 fclose(file);
80 file = 0;
81 }
82}
FILE * file
Definition: imageio.h:354

References EMAN::ImageIO::file.

Member Function Documentation

◆ is_valid()

bool XplorIO::is_valid ( const void *  first_block)
static

Definition at line 148 of file xplorio.cpp.

149{
150 ENTERFUNC;
151 if (!first_block) {
152 return false;
153 }
154 char *buf = (char *)(first_block);
155 string line1 = Util::get_line_from_string(&buf);
156 bool result = true;
157
158 if (line1.size() != 0) {
159 result = false;
160 }
161 else {
162 string line2 = Util::get_line_from_string(&buf);
163 int ntitle = 0;
164
165 if ((int)line2.size() != INTEGER_SIZE) {
166 result = false;
167 }
168 else {
169 ntitle = atoi(line2.c_str());
170 if (ntitle < 0 || ntitle > 50) {
171 result = false;
172 }
173
174 else {
175 for (int i = 0; i < ntitle+2; i++) {
177 }
178
179 string modeline = Util::get_line_from_string(&buf);
180 if (modeline != SECTION_MODE) {
181 result = false;
182 }
183 }
184 }
185 }
186
187 EXITFUNC;
188 return result;
189}
static string get_line_from_string(char **str)
Extract a single line from a multi-line string.
Definition: util.cpp:322
static const string SECTION_MODE
Definition: xplorio.h:86
static const int INTEGER_SIZE
Definition: xplorio.h:88
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References ENTERFUNC, EXITFUNC, EMAN::Util::get_line_from_string(), INTEGER_SIZE, and SECTION_MODE.

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

Member Data Documentation

◆ apix_x

float EMAN::XplorIO::apix_x
private

Definition at line 78 of file xplorio.h.

Referenced by XplorIO().

◆ apix_y

float EMAN::XplorIO::apix_y
private

Definition at line 79 of file xplorio.h.

Referenced by XplorIO().

◆ apix_z

float EMAN::XplorIO::apix_z
private

Definition at line 80 of file xplorio.h.

Referenced by XplorIO().

◆ cell_alpha

float EMAN::XplorIO::cell_alpha
private

Definition at line 82 of file xplorio.h.

Referenced by XplorIO().

◆ cell_beta

float EMAN::XplorIO::cell_beta
private

Definition at line 83 of file xplorio.h.

Referenced by XplorIO().

◆ cell_gama

float EMAN::XplorIO::cell_gama
private

Definition at line 84 of file xplorio.h.

Referenced by XplorIO().

◆ DEFINE_IMAGEIO_FUNC

EMAN::XplorIO::DEFINE_IMAGEIO_FUNC

Definition at line 66 of file xplorio.h.

◆ FLOAT_SIZE

const int XplorIO::FLOAT_SIZE = 12
staticprivate

Definition at line 89 of file xplorio.h.

◆ INTEGER_SIZE

const int XplorIO::INTEGER_SIZE = 8
staticprivate

Definition at line 88 of file xplorio.h.

Referenced by is_valid().

◆ is_big_endian

bool EMAN::XplorIO::is_big_endian
private

Definition at line 70 of file xplorio.h.

Referenced by XplorIO().

◆ is_new_file

bool EMAN::XplorIO::is_new_file
private

Definition at line 71 of file xplorio.h.

Referenced by XplorIO().

◆ NFLOAT_PER_LINE

const int XplorIO::NFLOAT_PER_LINE = 6
staticprivate

Definition at line 87 of file xplorio.h.

◆ nlines_in_header

int EMAN::XplorIO::nlines_in_header
private

Definition at line 72 of file xplorio.h.

Referenced by XplorIO().

◆ nx

int EMAN::XplorIO::nx
private

Definition at line 74 of file xplorio.h.

Referenced by XplorIO().

◆ ny

int EMAN::XplorIO::ny
private

Definition at line 75 of file xplorio.h.

Referenced by XplorIO().

◆ nz

int EMAN::XplorIO::nz
private

Definition at line 76 of file xplorio.h.

Referenced by XplorIO().

◆ OUTFORMAT

const char * XplorIO::OUTFORMAT = "%12.5E"
staticprivate

Definition at line 90 of file xplorio.h.

◆ SECTION_MODE

const string XplorIO::SECTION_MODE = "ZYX"
staticprivate

Definition at line 86 of file xplorio.h.

Referenced by is_valid().


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