38#define M_PI 3.14159265358979323846f
39#define MAXPATHLEN (MAX_PATH*4)
50const char *LstFastIO::MAGIC =
"#LSX";
52LstFastIO::LstFastIO(
const string & fname,
IOMode rw)
85 bool is_new_file =
false;
92 if (!fgets(buf, MAXPATHLEN,
file)) {
100 fgets(buf,MAXPATHLEN,
file);
101 fgets(buf,MAXPATHLEN,
file);
104 fseek(
file,0L,SEEK_END);
124 for (
int i=0; i<1024; i++) {
125 char c = ((
const char *)first_block)[i];
129 printf(
"ERROR: .lst file contains \\r at pos %d. This should never happen. (If you edit a .lst file with a text editor on Windows, it will corrupt the file). Aborting program.\n",i);
148 LOGERR(
"reach EOF in file '%s' before reading %dth image",
153 int ref_image_index = 0;
154 char ref_image_path[MAXPATHLEN];
156 sscanf(buf.data(),
" %d %s %[ .,0-9-]", &ref_image_index, ref_image_path, unused.data());
157 string newrefname = string(ref_image_path);
183 dict.
put(
"data_n",ref_image_index);
209 char *data2=(
char*)data;
211 fprintf(
file,
"%s", (
char*)data);
212 for (
unsigned int i=strlen(data2); i<
line_length-1; i++) putc(
' ',
file);
static bool is_host_big_endian()
Dict is a dictionary to store <string, EMObject> pair.
void put(const string &key, EMObject val)
Put the value/key pair into the dictionary probably better to just use operator[].
EMDataType
Image pixel data type used in EMAN.
static ImageIO * get_imageio(const string &filename, int rw_mode, ImageType image_type=IMAGE_UNKNOWN)
Get an ImageIO object.
ImageIO classes are designed for reading/writing various electron micrography image formats,...
virtual void flush()=0
Flush the IO buffer.
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.
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.
virtual bool is_complex_mode()=0
Is this an complex image or not.
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.
FILE * sfopen(const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
Run fopen safely.
void check_read_access(int image_index)
Validate 'image_index' in file reading.
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.
virtual void init()=0
Do some initialization before doing the read/write.
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
static bool is_valid(const void *first_block)
int get_nimg()
Return the number of images in this image file.
int calc_ref_image_index(int image_index)
static const char * MAGIC
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
static bool is_file_exist(const string &filename)
check whether a file exists or not
static bool check_file_by_magic(const void *first_block, const char *magic)
check whether a file starts with certain magic string.
#define ImageReadException(filename, desc)
#define FileAccessException(filename)
#define ImageWriteException(imagename, desc)