EMAN2
imagicio.cpp
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#include <cstring>
33#include "imagicio.h"
34#include "portable_fileio.h"
35#include "util.h"
36#include "geometry.h"
37#include "ctf.h"
38#include "emassert.h"
39#include "transform.h"
40
41#include <ctime>
42
43using namespace EMAN;
44
45const char *ImagicIO::HED_EXT = "hed";
46const char *ImagicIO::IMG_EXT = "img";
47const char *ImagicIO::REAL_TYPE_MAGIC = "REAL";
48const char *ImagicIO::CTF_MAGIC = "!-";
49
50ImagicIO::ImagicIO(const string & fname, IOMode rw)
51: ImageIO(fname, rw), hed_file(0), img_file(0)
52{
55
57 is_new_hed = false;
58 is_new_img = false;
59 memset(&imagich, 0, sizeof(ImagicHeader));
60 imagich.count = -1;
62 nz = 0;
63}
64
66{
67 if (hed_file) {
68 fclose(hed_file);
69 hed_file = 0;
70 }
71
72 if (img_file) {
73 fclose(img_file);
74 img_file = 0;
75 }
76}
77
78void ImagicIO::init()
79{
81
82 if (initialized) {
83 return;
84 }
85
86 initialized = true;
87
88 is_new_hed = false;
89 is_new_img = false;
90
93
94 if (is_new_hed != is_new_img) {
95 LOGWARN("IMAGIC header file and data file should both exist or both not exist");
96 }
97
98 if (!is_new_hed) {
99 if (fread(&imagich, sizeof(ImagicHeader), 1, hed_file) != 1) {
100 throw ImageReadException(hed_filename, "IMAGIC header");
101 }
102
103// if (!is_valid(&imagich)) {
104// throw ImageReadException(hed_filename, "invalid IMAGIC file");
105// }
106
108
110 LOGERR("unsupported imagic data type: %s", imagich.type);
111 throw ImageReadException(hed_filename, "unsupported imagic data type");
112 }
113
116 rewind(hed_file);
117 }
118 EXITFUNC;
119}
120
121bool ImagicIO::is_valid(const void *first_block)
122{
123 ENTERFUNC;
124
125 if (!first_block) {
126 return false;
127 }
128
129 const int *data = static_cast < const int *>(first_block);
130 int count = data[1];
131 int headrec = data[3];
132 int month = data[5];
133 int hour = data[7];
134 int nx = data[13];
135 int ny = data[12];
136
137 bool data_big_endian = ByteOrder::is_data_big_endian(&headrec);
138
139 if (data_big_endian != ByteOrder::is_host_big_endian()) {
140 ByteOrder::swap_bytes(&count);
141 ByteOrder::swap_bytes(&headrec);
142 ByteOrder::swap_bytes(&month);
146 }
147
148 const int max_dim = 1 << 20;
149 bool result = false;
150
151 if (headrec == 1 &&
152 count >= 0 && count < max_dim &&
153 nx > 0 && nx < max_dim &&
154 ny > 0 && ny < max_dim && month >= 0 && hour >= 0 && hour <= 24) {
155 result = true;
156 }
157
158 EXITFUNC;
159 return result;
160}
161
162int ImagicIO::read_header(Dict & dict, int image_index, const Region * area, bool is_3d)
163{
164 ENTERFUNC;
165
166 check_read_access(image_index);
167
168 int nimg = 1;
169
170 if (is_3d) {
171 nimg = imagich.count + 1;
172
173 if (nimg <= 1) {
174 LOGWARN("this is not a 3D IMAGIC. Read as a 2D");
175 }
176 }
177
178 ImagicHeader hed;
179 if (image_index == 0) {
180 hed = imagich;
181 }
182 else {
183 memset(&hed, 0, sizeof(ImagicHeader));
184 portable_fseek(hed_file, sizeof(ImagicHeader) * image_index, SEEK_SET);
185 fread(&hed, sizeof(ImagicHeader), 1, hed_file);
187 }
188 check_region(area, FloatSize(hed.nx, hed.ny, nimg), is_new_hed,false);
189
191
192 int xlen = 0, ylen = 0, zlen = 0;
193 EMUtil::get_region_dims(area, hed.nx, &xlen, hed.ny, &ylen, nimg, &zlen);
194
195 dict["nx"] = xlen;
196 dict["ny"] = ylen;
197 dict["nz"] = zlen;
198
199 dict["datatype"] = to_em_datatype(datatype);
200
201 dict["minimum"] = hed.min;
202 dict["maximum"] = hed.max;
203 dict["mean"] = hed.avdens;
204 dict["sigma"] = hed.sigma;
205
206 dict["IMAGIC.imgnum"] = hed.imgnum;
207 dict["IMAGIC.count"] = hed.count;
208 dict["IMAGIC.error"] = hed.error;
209
210 dict["IMAGIC.headrec"] = hed.headrec;
211 dict["IMAGIC.mday"] = hed.mday;
212 dict["IMAGIC.month"] = hed.month;
213
214 dict["IMAGIC.year"] = hed.year;
215 dict["IMAGIC.hour"] = hed.hour;
216 dict["IMAGIC.minute"] = hed.minute;
217
218 dict["IMAGIC.sec"] = hed.sec;
219 dict["IMAGIC.reals"] = hed.reals;
220 dict["IMAGIC.pixels"] = hed.pixels;
221
222 char tmp[5] = { hed.type[0],hed.type[1],hed.type[2],hed.type[3],0 };
223 dict["IMAGIC.type"] = tmp;
224 dict["IMAGIC.ixold"] = hed.ixold;
225 dict["IMAGIC.iyold"] = hed.iyold;
226
227 dict["IMAGIC.oldav"] = hed.oldav;
228 dict["IMAGIC.label"] = hed.label;
229 dict["ptcl_repr"] = hed.mrc2; // raw images represented by this image
230
231 dict["orientation_convention"] = "EMAN";
232 const float alt = hed.mrc1[1]*180.0f/M_PI;
233 const float az = hed.mrc1[2]*180.0f/M_PI;
234 const float phi = hed.mrc1[0]*180.0f/M_PI;
235 dict["euler_alt"] = alt;
236 dict["euler_az"] = az;
237 dict["euler_phi"] = phi;
238 Transform *trans = new Transform();
239 trans->set_rotation(Dict("type", "eman", "alt", alt, "az", az, "phi", phi));
240 if( hed.count==0 ) {
241 dict["xform.projection"] = trans;
242 }
243 else {
244 dict["xform.projection"] = trans;
245 dict["xform.align3d"] = trans;
246 }
247 Ctf * ctf_ = read_ctf(hed);
248 if( ctf_ != 0) {
249 dict["ctf"] = ctf_;
250 }
251 if(trans) {delete trans; trans=0;}
252 if(ctf_) {delete ctf_; ctf_=0;}
253 EXITFUNC;
254 return 0;
255}
256
257int ImagicIO::write_header(const Dict & dict, int image_index,
258 const Region * area, EMUtil::EMDataType, bool use_host_endian)
259{
260 ENTERFUNC;
261
262 if(image_index<0) {
263 image_index = get_nimg();
264 }
265
266 check_write_access(rw_mode, image_index);
267 nz = dict["nz"];
268 if (nz > 1 && image_index != 0) {
269 throw ImageWriteException(filename, "to write 3D IMAGIC image, image index must be 0");
270 }
271
272 if (area) {
274 is_new_hed);
275 EXITFUNC;
276 return 0;
277 }
278
279 int nx = dict["nx"];
280 int ny = dict["ny"];
281 int nimg=0; //# images currently in file
282
283
284 if (!is_new_hed) {
286
287 if (imagich.nx != nx || imagich.ny != ny) {
288 char desc[256];
289 sprintf(desc, "new IMAGIC size %dx%d is not equal to existing size %dx%d",
290 nx, ny, imagich.nx, imagich.ny);
291 throw ImageWriteException(filename, desc);
292 }
293
294 if (datatype!=IMAGIC_FLOAT) {
295 throw ImageWriteException(filename, "Attempted write to non REAL Imagic file");
296 }
297
298 rewind(hed_file);
299 nimg=imagich.count+1;
300 }
301
302 ImagicHeader new_hed;
303 memset(&new_hed, 0, sizeof(ImagicHeader));
304
305 time_t cur_time = time(0);
306 struct tm *tm = localtime(&cur_time);
307
308 new_hed.error = 0;
309 new_hed.headrec = 1;
310
311 new_hed.mday = tm->tm_mday;
312 new_hed.month = tm->tm_mon;
313 new_hed.year = tm->tm_year + 1900;
314 new_hed.hour = tm->tm_hour;
315 new_hed.minute = tm->tm_min;
316 new_hed.sec = tm->tm_sec;
317
318 new_hed.reals = nx * ny;
319 new_hed.pixels = nx * ny;
320 new_hed.ny = ny;
321 new_hed.nx = nx;
322
323 new_hed.ixold = 0;
324 new_hed.iyold = 0;
325 new_hed.oldav = 0;
326
327 new_hed.min = (float)dict["minimum"];
328 new_hed.max = (float)dict["maximum"];
329 new_hed.avdens = (float)dict["mean"];
330 new_hed.sigma = (float)dict["sigma"];
331
332 if(nz<=1 && dict.has_key("xform.projection")) {
333 Transform * t = dict["xform.projection"];
334 Dict d = t->get_rotation("eman");
335 new_hed.mrc1[1] = (float)d["alt"]*M_PI/180.0f;
336 new_hed.mrc1[2] = (float)d["az"]*M_PI/180.0f;
337 new_hed.mrc1[0] = (float)d["phi"]*M_PI/180.0f;
338 if(t) {delete t; t=0;}
339 }
340 else if(nz>1 && dict.has_key("xform.align3d")) {
341 Transform * t = dict["xform.align3d"];
342 Dict d = t->get_rotation("eman");
343 new_hed.mrc1[1] = (float)d["alt"]*M_PI/180.0f;
344 new_hed.mrc1[2] = (float)d["az"]*M_PI/180.0f;
345 new_hed.mrc1[0] = (float)d["phi"]*M_PI/180.0f;
346 if(t) {delete t; t=0;}
347 }
348 else {
349 if(dict.has_key("euler_alt")) new_hed.mrc1[1] = (float)dict["euler_alt"]*M_PI/180.0f;
350 if(dict.has_key("euler_az")) new_hed.mrc1[2] = (float)dict["euler_az"]*M_PI/180.0f;
351 if(dict.has_key("euler_phi")) new_hed.mrc1[0] = (float)dict["euler_phi"]*M_PI/180.0f;
352 }
353
354 if(dict.has_key("ptcl_repr")) new_hed.mrc2 = (int)dict["ptcl_repr"];
355
356 string new_label = dict.has_key("IMAGIC.label") ? (string) dict["IMAGIC.label"] : "";
357 sprintf(new_hed.label, "%s", new_label.c_str() );
358
359 new_hed.lbuf = nx;
360 new_hed.inn = 1;
361 new_hed.iblp = ny;
362 new_hed.ifb = 0;
363 new_hed.lbw = 0;
364 new_hed.lbr = -1;
365 new_hed.lastlr = -1;
366 new_hed.lastlw = 1;
367 new_hed.num = 8;
368 new_hed.nhalf = nx / 2;
369 new_hed.ibsd = nx * 2;
370 new_hed.ihfl = 7;
371 new_hed.lcbr = -1;
372 new_hed.lcbw = 1;
373 new_hed.imstr = -1;
374 new_hed.imstw = -1;
375 new_hed.istart = 1;
376 new_hed.iend = nx;
377 new_hed.leff = nx;
378 new_hed.linbuf = nx * 2;
379 new_hed.ntotbuf = -1;
380 new_hed.icstart = 1;
381 new_hed.icend = nx / 2;
382 strncpy(new_hed.type, REAL_TYPE_MAGIC,4);
383
384
385 // header in file order
386 if ( (is_big_endian != ByteOrder::is_host_big_endian()) || !use_host_endian) swap_header(new_hed);
387
388 // overwrite existing header if necessary
389 if (image_index>=0 && image_index<nimg) {
390 portable_fseek(hed_file, sizeof(ImagicHeader)*image_index, SEEK_SET);
391 new_hed.imgnum=image_index+1;
393 ByteOrder::swap_bytes((int *) &new_hed.imgnum,1);
394 fwrite(&new_hed, sizeof(ImagicHeader),1,hed_file);
395 }
396
397 // How many images does the file need when we're done ?
398 int required_len;
399 if (nz>1) required_len=nz;
400 else {
401 if (image_index<0) required_len=nimg+1;
402 else if (image_index+1>nimg) required_len=image_index+1;
403 else required_len=nimg;
404 }
405
406 // Extend the file to the necessary length
407 portable_fseek(hed_file, 0, SEEK_END);
408 while (nimg<required_len) {
409 nimg++;
410 new_hed.imgnum=nimg;
412 ByteOrder::swap_bytes((int *) &new_hed.imgnum,1);
413 fwrite(&new_hed, sizeof(ImagicHeader),1,hed_file);
414 }
415
416 // update the 1st header with total # images
417 portable_fseek(hed_file, sizeof(int), SEEK_SET);
418 nimg--;
420 ByteOrder::swap_bytes((int *) &nimg,1);
421 fwrite(&nimg, sizeof(int), 1, hed_file);
422
423 // header in machine order
424 if ( (is_big_endian != ByteOrder::is_host_big_endian()) || !use_host_endian) swap_header(new_hed);
425 imagich=new_hed;
426 imagich.count=nimg;
427 is_new_hed = false;
428
429 if( dict.has_key("ctf") ) {
430 Ctf * ctf_ = dict["ctf"];
431 write_ctf(ctf_);
432 if(ctf_) {delete ctf_; ctf_=0;}
433 }
434
435 EXITFUNC;
436 return 0;
437}
438
439int ImagicIO::read_data(float *data, int image_index, const Region * area, bool is_3d)
440{
441 ENTERFUNC;
442
443 check_read_access(image_index, data);
445 int nimg = 1;
446 if (is_3d) {
447 nimg = imagich.count + 1;
448 }
449
450 if (is_3d && imagich.count < 1) {
451 LOGWARN("this is not a 3D IMAGIC. Read as a 2D");
452 is_3d = false;
453 }
454
455 check_region(area, FloatSize(imagich.nx, imagich.ny, nimg), is_new_hed,false);
456
457 rewind(img_file);
458
459 unsigned short *sdata = (unsigned short *) data;
460 unsigned char *cdata = (unsigned char *) data;
461 size_t mode_size = get_datatype_size(datatype);
462 EMUtil::process_region_io(cdata, img_file, READ_ONLY, image_index, mode_size,
463 imagich.nx, imagich.ny, nimg, area, true);
464
465#if 0
466 int row_size = imagich.nx * mode_size;
467 int sec_size = imagich.nx * imagich.ny * mode_size;
468
469 for (int k = 0; k < nimg; k++) {
470 for (int i = imagich.ny - 1; i >= 0; i--) {
471 if (fread(&cdata[k * sec_size + i * row_size], row_size, 1, img_file) != 1) {
472 LOGERR("incomplete data read: %d/%d blocks on file '%s'",
473 i, imagich.ny, filename.c_str());
474 return 1;
475 }
476 }
477 }
478#endif
479
480 size_t img_size = imagich.nx * imagich.ny * nimg;
481
482 if (datatype == IMAGIC_FLOAT) {
483 become_host_endian(data, img_size);
484 }
485 else if (datatype == IMAGIC_USHORT) {
486 become_host_endian((unsigned short *) cdata, img_size);
487
488 for (int j = img_size - 1; j >= 0; j--) {
489 data[j] = static_cast < float >(sdata[j]);
490 }
491 }
492 else {
493 throw ImageReadException(filename, "unknown imagic data type");
494 }
495
496 EXITFUNC;
497 return 0;
498}
499
500int ImagicIO::write_data(float *data, int image_index, const Region* area,
501 EMUtil::EMDataType, bool use_host_endian)
502{
503 ENTERFUNC;
504
505 check_write_access(rw_mode, image_index, 0, data);
507 is_new_hed);
508
509 if (nz == 1) {
510 if (image_index == -1) {
511 portable_fseek(img_file, 0, SEEK_END);
512 }
513 else {
514 size_t sec_size = imagich.nx * imagich.ny * sizeof(float);
515 portable_fseek(img_file, ((off_t) sec_size) * image_index, SEEK_SET);
516 }
517 }
518
519 if(is_new_img) {
520 if(!use_host_endian) {
522 }
523 }
526 }
527#if 0
528 int n_pad_imgs = 0;
529 int old_num_imgs = imagich.count + 1;
530 if (image_index > old_num_imgs) {
531 n_pad_imgs = image_index - old_num_imgs;
532 }
533#endif
534
535 // New way to write data which includes region writing.
536 // If it is tested to be OK, remove the old code in the
537 // #if 0 ... #endif block.
539 sizeof(float), imagich.nx, imagich.ny,
540 nz, area, true);
541
542
543#if 0
544 size_t row_size = imagich.nx * sizeof(float);
545 int nxy = imagich.nx * imagich.ny;
546
547 for (int i = 0; i < nz; i++) {
548 for (int j = imagich.ny - 1; j >= 0; j--) {
549 fwrite(&data[i * nxy + j * imagich.nx], row_size, 1, img_file);
550 }
551
554 }
555 }
556#endif
557 EXITFUNC;
558 return 0;
559}
560
561void ImagicIO::flush()
562{
563 fflush(img_file);
564 fflush(hed_file);
565}
566
568{
569 ENTERFUNC;
570
571 Ctf * ctf_ = 0;
572 size_t n = strlen(CTF_MAGIC);
573
574 if (strncmp(imagich.label, CTF_MAGIC, n) == 0) {
575 ctf_ = new EMAN1Ctf();
576 string header_label(hed.label);
577 // Note: this block was making things crash because it assumed the following if statement
578 // was true - I added the if statement (d.woolford)
579 if (header_label.size() > 2) {
580 string sctf = "O" + header_label.substr(2);
581 ctf_->from_string(sctf);
582 }
583 }
584
585 EXITFUNC;
586 return ctf_;
587}
588
589void ImagicIO::write_ctf(const Ctf * const ctf, int)
590{
591 ENTERFUNC;
592 init();
593
594 size_t n = strlen(CTF_MAGIC);
595 strcpy(imagich.label, CTF_MAGIC);
596 string ctf_ = ctf->to_string().substr(1);
597 strncpy(&imagich.label[n], ctf_.c_str(), sizeof(imagich.label) - n);
598
599 rewind(hed_file);
600 if (fwrite(&imagich, sizeof(ImagicHeader), 1, hed_file) != 1) {
601 throw ImageWriteException(hed_filename, "Imagic Header");
602 }
603
604 EXITFUNC;
605}
606
608{
609 init();
611 return true;
612 }
613 return false;
614}
615
617{
618 init();
619 return is_big_endian;
620}
621
623{
624 init();
625 return (imagich.count + 1);
626}
627
629{
631
632 if (strncmp(name, "PACK",4) == 0) {
633 t = IMAGIC_UCHAR;
634 }
635 else if (strncmp(name, "INTG",4) == 0) {
636 t = IMAGIC_USHORT;
637 }
638 else if (strncmp(name, REAL_TYPE_MAGIC,4) == 0) {
639 t = IMAGIC_FLOAT;
640 }
641 else if (strncmp(name, "COMP",4) == 0) {
643 }
644 else if (strncmp(name, "RECO",4) == 0) {
646 }
647 return t;
648}
649
651{
652 size_t s = 0;
653 switch (t) {
654 case IMAGIC_UCHAR:
655 s = sizeof(unsigned char);
656 break;
657 case IMAGIC_USHORT:
658 s = sizeof(unsigned short);
659 break;
660 case IMAGIC_FLOAT:
663 s = sizeof(float);
664 break;
665 default:
666 s = 0;
667 }
668
669 return s;
670}
671
673{
674 switch (t) {
675 case IMAGIC_UCHAR:
676 return EMUtil::EM_UCHAR;
677 case IMAGIC_USHORT:
678 return EMUtil::EM_USHORT;
679 case IMAGIC_FLOAT:
680 return EMUtil::EM_FLOAT;
683 default:
684 break;
685 }
686
687 return EMUtil::EM_UNKNOWN;
688}
689
691{
693 swap_header(hed);
694 }
695}
696
697
699{
703}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
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 bool is_data_big_endian(const T *small_num_addr)
given a pointer to a reasonable small integer number, return whether the number is big endian or not.
Definition: byteorder.h:76
Ctf is the base class for all CTF model.
Definition: ctf.h:60
virtual int from_string(const string &ctf)=0
virtual string to_string() const =0
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
EMAN1Ctf is the CTF model used in EMAN1.
Definition: ctf.h:120
static void process_region_io(void *cdata, FILE *file, int rw_mode, int image_index, size_t mode_size, int nx, int ny, int nz=1, const Region *area=0, bool need_flip=false, ImageType imgtype=IMAGE_UNKNOWN, int pre_row=0, int post_row=0)
Process image region IO.
Definition: emutil.cpp:931
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
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
ImageIO classes are designed for reading/writing various electron micrography image formats,...
Definition: imageio.h:127
IOMode rw_mode
Definition: imageio.h:353
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
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.
bool initialized
Definition: imageio.h:355
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.
Definition: imageio.cpp:135
void check_read_access(int image_index)
Validate 'image_index' in file reading.
Definition: imageio.cpp:95
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.
void check_write_access(IOMode rw_mode, int image_index, int max_nimg=0)
Validate rw_mode and image_index in file writing.
Definition: imageio.cpp:113
void become_host_endian(T *data, size_t n=1)
Convert data of this image into host endian format.
Definition: imageio.h:261
virtual bool is_image_big_endian()=0
Is this image in big endian or not.
size_t get_datatype_size(DataType t)
Definition: imagicio.cpp:650
bool is_big_endian
Definition: imagicio.h:189
FILE * hed_file
Definition: imagicio.h:185
FILE * img_file
Definition: imagicio.h:186
static const char * REAL_TYPE_MAGIC
Definition: imagicio.h:85
ImagicHeader imagich
Definition: imagicio.h:188
DataType get_datatype_from_name(const char *name)
Definition: imagicio.cpp:628
bool is_new_img
Definition: imagicio.h:191
@ IMAGIC_UNKNOWN_TYPE
Definition: imagicio.h:96
@ IMAGIC_FFT_FLOAT_COMPLEX
Definition: imagicio.h:95
@ IMAGIC_FLOAT_COMPLEX
Definition: imagicio.h:94
int get_nimg()
Return the number of images in this image file.
Definition: imagicio.cpp:622
static bool is_valid(const void *first_block)
Definition: imagicio.cpp:121
bool is_new_hed
Definition: imagicio.h:190
static const char * HED_EXT
Definition: imagicio.h:68
DataType datatype
Definition: imagicio.h:193
void make_header_host_endian(ImagicHeader &hed)
Definition: imagicio.cpp:690
string img_filename
Definition: imagicio.h:183
@ NUM_4BYTES_AFTER_SPACE
Definition: imagicio.h:103
@ NUM_4BYTES_AFTER_IXOLD
Definition: imagicio.h:102
@ NUM_4BYTES_PRE_IXOLD
Definition: imagicio.h:101
int to_em_datatype(DataType t)
Definition: imagicio.cpp:672
static const char * IMG_EXT
Definition: imagicio.h:69
string hed_filename
Definition: imagicio.h:182
Ctf * read_ctf(const ImagicHeader &hed) const
the Ctf object is a EMAN1Ctf object.
Definition: imagicio.cpp:567
void swap_header(ImagicHeader &hed)
Definition: imagicio.cpp:698
static const char * CTF_MAGIC
Definition: imagicio.h:86
void write_ctf(const Ctf *const ctf, int image_index=0)
Definition: imagicio.cpp:589
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
void set_rotation(const Dict &rotation)
Set a rotation using a specific Euler type and the dictionary interface Works for all Euler types.
Definition: transform.cpp:519
Dict get_rotation(const string &euler_type="eman") const
Get a rotation in any Euler format.
Definition: transform.cpp:829
static string change_filename_ext(const string &old_filename, const string &new_ext)
Change a file's extension and return the new filename.
Definition: util.cpp:485
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
Definition: emassert.h:42
#define ImageReadException(filename, desc)
Definition: exception.h:204
#define ImageWriteException(imagename, desc)
Definition: exception.h:223
#define LOGWARN
Definition: log.h:53
#define LOGERR
Definition: log.h:51
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
E2Exception class.
Definition: aligner.h:40
int portable_fseek(FILE *fp, off_t offset, int whence)