| Bsoft 2.0.5 Bernard's software package

rwPIF.cpp
Go to the documentation of this file.
1
9 #include "rwPIF.h"
10 #include "file_util.h"
11 #include "utilities.h"
12
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15
16 extern char* month[];
17
18 // The PIF format's internal scale factor
19 #define PIF_SCALE 1e-5
20 double PIFscale = PIF_SCALE;
21
22 // Internal function prototypes
23 char* read_sf(ifstream* fimg, Bimage* p, int mode, int sb);
24
60 int readPIF(Bimage* p, int readdata, int img_select)
61 {
62 // double PIFscale = PIF_SCALE;
63
64 ifstream* fimg = new ifstream(p->file_name());
65 if ( fimg->fail() ) return -1;
66
67 long header_size = sizeof(PIFhead);
68 long image_header_size = sizeof(PIFimagehead);
69 if ( verbose & VERB_DEBUG ) {
70 cout << "DEBUG readPIF: Size of file header: " << header_size << endl;
71 cout << "DEBUG readPIF: Size of image header: " << image_header_size << endl;
72 }
73
74 PIFhead* header = new PIFhead;
75
76 fimg->read((char *)header, header_size);
77 if ( fimg->fail() ) return -2;
78
79 // Determine byte order and swap bytes if from little-endian machine
80 unsigned char* b = (unsigned char *) header;
81 long i, j, sb = 0;
82 if ( ( abs( header->mode ) > SWAPTRIG ) || ( abs(header->nz) > SWAPTRIG ) ) {
83 if ( verbose & VERB_PROCESS )
84 cerr << "Warning: Swapping header byte order for 4-byte types" << endl;
85 sb = 1;
86 long extent = 84; // exclude labels from swapping
87 for ( i=0; i<extent; i+=4 ) {
88 if ( i > 20 && i < 32 ) swapbytes(b+i, 4);
89 if ( i > 60 ) swapbytes(b+i, 4);
90 }
91 }
92
93 if ( verbose & VERB_DEBUG )
94 cout << "DEBUG readPIF: Mode = " << header->mode << endl;
95
96 // Map the parameters of the file header
97 // All numerical parameters are integer and some must be converted
98 // to floating point using a scaling factor
99 // long pad = 0;
100 char realscalefactor[20];
101 strncpy(realscalefactor, header->realscalefactor, 16);
102 realscalefactor[16] = 0;
103 sscanf(realscalefactor, "%lf", &PIFscale);
104 // p->scale = PIFscale;
105 if ( verbose & VERB_DEBUG )
106 cout << "DEBUG readPIF: PIF scale factor: " << realscalefactor << " " << PIFscale << endl;
107 p->size(header->nx, header->ny, header->nz);
108 p->page_size(p->size());
109 p->channels(1);
110 if ( header->numimages > 1 ) {
111 if ( verbose & VERB_DEBUG )
112 printf( "DEBUG readPIF: Multi-image file with %d images!\n",
113 header->numimages);
114 // pad = 512;
115 }
116 if ( header->numimages > 1 && header->htype < 1 ) {
117 cerr << "Error: Images with different sizes!" << endl;
118 return -1;
119 }
120
121 switch ( header->mode ) { // Note: There are many more types!
122 case 0:
123 case 6: p->data_type(UCharacter); break;
124 case 1:
125 case 7:
126 case 20:
127 case 88: p->data_type(Short); break;
128 case 2:
129 case 21:
130 case 22:
131 case 46: p->data_type(Integer); break;
132 case 9: p->data_type(Float); break;
133 case 40: p->data_type(Double); break;
134 case 3:
135 case 8: p->data_type(Short); p->compound_type(TComplex); p->channels(2); break;
136 case 4:
137 case 31:
138 case 32: p->data_type(Integer); p->compound_type(TComplex); p->channels(2); break;
139 case 10: p->data_type(Float); p->compound_type(TComplex); p->channels(2); break;
140 case 41: p->data_type(Double); p->compound_type(TComplex); p->channels(2); break;
141 default: p->data_type(UCharacter); break;
142 }
143
144 if ( header->even < 2) p->label(header->label);
145 else p->label((char *) &header->even);
146
147 p->data_offset(PIFSIZE);
148 if ( header->mode == 97 ) { // Depth-cued ===> colourmap
149 PIFcolor* colormap = new PIFcolor;
150 fimg->read((char *)colormap, sizeof(PIFcolor));
151 p->data_offset(p->data_offset() + sizeof(PIFcolor));
152 delete colormap;
153 }
154
155 // Map the parameters in the image headers
156 long xstore = p->sizeX();
157 if ( p->compound_type() == TComplex ) xstore = p->sizeX()/2 + 1;
158 long image_size = xstore*p->sizeY()*p->sizeZ()*p->channels()*p->data_type_size()
159 + image_header_size;
160 PIFimagehead* imageheader = new PIFimagehead;
161 PIFimagehead_new* imageheader_new = (PIFimagehead_new *) imageheader;
162
163 long n(0), imgstart(0);
164 long imgend(header->numimages - 1);
165 double min(1e37), max(-1e37), sum(0), ssum(0);
166 Vector3<double> ori;
167
168 if ( img_select > -1 ) {
169 if ( img_select >= header->numimages ) img_select = header->numimages - 1;
170 imgstart = img_select;
171 imgend = img_select;
172 p->images(1);
173 } else {
174 p->images(header->numimages);
175 }
176
177 tm* t = p->get_localtime();
178 char mon[4];
179
180 fimg->seekg(header_size + imgstart*image_size, ios_base::beg);
181
182 for ( i = imgstart; i<=imgend; i++ ) {
183 if ( verbose & VERB_DEBUG )
184 cout << "DEBUG readPIF: Reading image " << i+1 << " at position "
185 << header_size + i*image_size << endl;
186 // fimg->seekg(header_size + i*image_size, ios_base::beg);
187 fimg->read((char *)imageheader, image_header_size);
188 if ( fimg->fail() ) {
189 cerr << "Error: Reading image " << i+1 << " header failed!" << endl;
190 fimg->close();
191 delete fimg;
192 return -3;
193 }
194
195 if ( verbose & VERB_DEBUG )
196 cout << "DEBUG readPIF: time string: " << imageheader->timestamp << endl;
197 if ( strlen(imageheader->timestamp) ) {
198 j = sscanf(imageheader->timestamp, "%3s %3s %2d %2d:%2d:%2d %4d",
199 mon, mon, &t->tm_mday, &t->tm_hour, &t->tm_min, &t->tm_sec, &t->tm_year);
200 if ( j > 6 ) {
201 for ( j=0; strncmp(mon, month[j], 3) != 0; j++ ) ;
202 if ( j < 12 ) t->tm_mon = j;
203 t->tm_year -= 1900;
204 p->set_time(t);
205 }
206 }
207
208 if ( sb ) {
209 b = (unsigned char *) imageheader;
210 for ( j=0; j<368; j+=4 ) {
211 if ( j < 116 || j > 248 ) swapbytes(b+j, 4);
212 }
213 }
214 j = ( p->images() > 1 )? i: 0;
215 p->background(j, imageheader->bkgnd);
216 p->image[j].minimum(PIFscale*imageheader->min);
217 p->image[j].maximum(PIFscale*imageheader->max);
218 p->image[j].average(PIFscale*imageheader->mean);
219 p->image[j].standard_deviation(PIFscale*imageheader->stddev);
220 if ( abs(imageheader->nxstart) < 1e6 )
221 ori[0] = -imageheader->nxstart;
222 if ( abs(imageheader->nystart) < 1e6 )
223 ori[1] = -imageheader->nystart;
224 if ( abs(imageheader->nzstart) < 1e6 )
225 ori[2] = -imageheader->nzstart;
226 // Trigger for new image header
227 if ( imageheader_new->ctfMode < 10 ) {
228 if ( fabs(PIFscale*imageheader_new->origX) < 1e6 )
229 ori[0] = PIFscale*imageheader_new->origX;
230 if ( fabs(PIFscale*imageheader_new->origY) < 1e6 )
231 ori[1] = PIFscale*imageheader_new->origY;
232 if ( fabs(PIFscale*imageheader_new->origZ) < 1e6 )
233 ori[2] = PIFscale*imageheader_new->origZ;
234 p->image[j].view(PIFscale*imageheader_new->view_x, PIFscale*imageheader_new->view_y,
235 PIFscale*imageheader_new->view_z, PIFscale*imageheader_new->view_angle);
236 } else {
237 if ( fabs(PIFscale*imageheader->xorigin) < 1e6 )
238 ori[0] = PIFscale*imageheader->xorigin;
239 if ( fabs(PIFscale*imageheader->yorigin) < 1e6 )
240 ori[1] = PIFscale*imageheader->yorigin;
241 if ( fabs(PIFscale*imageheader->zorigin) < 1e6 )
242 ori[2] = PIFscale*imageheader->zorigin;
243 p->image[j].view(PIFscale*imageheader->view_x, PIFscale*imageheader->view_y,
244 PIFscale*imageheader->view_z, PIFscale*imageheader->view_angle);
245 }
246 p->image[j].origin(ori);
247 if ( min > p->image[j].minimum() ) min = p->image[j].minimum();
248 if ( max < p->image[j].maximum() ) max = p->image[j].maximum();
249 sum += p->image[j].average();
250 ssum += p->image[j].standard_deviation()*
251 p->image[j].standard_deviation();
252 n++;
253 fimg->seekg(image_size-image_header_size, ios_base::cur);
254 }
255
256 if ( ( verbose & VERB_DEBUG ) && sb )
257 cout << "DEBUG readPIF: Header swapping done" << endl;
258
259 if ( verbose & VERB_DEBUG )
260 cout << "DEBUG readPIF: min=" << imageheader->min << " max=" <<
261 imageheader->max << " mean=" << imageheader->mean << " std=" << imageheader->stddev << endl;
262 p->minimum(min);
263 p->maximum(max);
264 p->average(sum/n);
265 p->standard_deviation(sqrt(ssum/n));
266
267 UnitCell uc(PIFscale*imageheader->xlength, PIFscale*imageheader->ylength,
268 PIFscale*imageheader->zlength, PIFscale*imageheader->alpha,
269 PIFscale*imageheader->beta, PIFscale*imageheader->gamma);
270 uc.degrees_to_radians();
271 p->unit_cell(uc);
272
273 p->space_group(imageheader->ispg);
274
275 if ( p->space_group() < 2 ) p->space_group(1);
276
277 // Pixel size
278 Vector3<double> sam(1,1,1);
279 if ( verbose & VERB_DEBUG )
280 cout << "DEBUG readPIF: stored pixelsize = " << imageheader->pixelsize_x
281 << " " << imageheader->pixelsize_y
282 << " " << imageheader->pixelsize_z << endl;
283 if ( imageheader->mx > 0 && imageheader->my > 0 && imageheader->mz > 0)
284 sam = {uc.a()/imageheader->mx, uc.b()/imageheader->my, uc.c()/imageheader->mz};
285
286 // Trigger for new image header
287 if ( imageheader_new->ctfMode < 10 ) {
288 if ( imageheader_new->pixelSize > 0 && imageheader_new->pixelSize < 1e9 )
289 sam[0] = sam[1] = sam[2] = PIFscale*imageheader_new->pixelSize;
290 } else {
291 if ( imageheader->pixelsize_x > 0 && imageheader->pixelsize_x < 1e9 )
292 sam[0] = PIFscale*imageheader->pixelsize_x;
293 if ( imageheader->pixelsize_y > 0 && imageheader->pixelsize_y < 1e9 )
294 sam[1] = PIFscale*imageheader->pixelsize_y;
295 if ( imageheader->pixelsize_z > 0 && imageheader->pixelsize_z < 1e9 )
296 sam[2] = PIFscale*imageheader->pixelsize_z;
297 }
298
299 if ( imageheader_new->pixelsize_x > 0 && imageheader_new->pixelsize_x < 1e9 )
300 sam[0] = PIFscale*imageheader_new->pixelsize_x;
301 if ( imageheader_new->pixelsize_y > 0 && imageheader_new->pixelsize_y < 1e9 )
302 sam[1] = PIFscale*imageheader_new->pixelsize_y;
303 if ( imageheader_new->pixelsize_z > 0 && imageheader_new->pixelsize_z < 1e9 )
304 sam[2] = PIFscale*imageheader_new->pixelsize_z;
305
306 if ( verbose & VERB_DEBUG )
307 cout << "DEBUG readPIF: assigned pixelsize = " << sam << endl;
308
309 p->sampling(sam);
310
311 if ( verbose & VERB_DEBUG )
312 cout << "DEBUG readPIF: converted pixelsize = " << sam << endl;
313
314 if ( verbose & VERB_DEBUG )
315 cout << "DEBUG readPIF: Mode = " << header->mode << endl;
316
317 if ( header->mode == 31 || header->mode == 32 ) {
318 read_sf( fimg, p, header->mode, sb );
319 cerr << "rwPIF: Structure factor I/O not implemented!" << endl << endl;
320 return -4;
321 }
322
323 long pagesize = p->channels()*xstore*p->sizeY()*p->sizeZ()*p->data_type_size();
324 long offset(p->data_offset() + imgstart*image_size);
325 unsigned char* data = NULL;
326
327 if ( readdata ) {
328 p->data_alloc();
329 if ( p->compound_type() == TSimple ) {
330 for ( i=imgstart, data=p->data_pointer(); i<=imgend; i++, data+=pagesize, offset+=image_size ) {
331 fread_large(data, pagesize, offset, fimg);
332 }
333 if ( sb ) swapbytes(p->alloc_size(), p->data_pointer(), p->data_type_size());
334 } else {
335 data = new unsigned char[pagesize];
336 for ( i=imgstart; i<=imgend; i++, offset+=image_size ) {
337 fread_large(data, pagesize, offset, fimg);
338 if ( sb ) swapbytes(pagesize, data, p->data_type_size());
339 p->unpack_transform(i-imgstart, data, CentHerm);
340 }
341 delete[] data;
342 }
343 }
344
345 fimg->close();
346 delete fimg;
347
348 delete header;
349 delete imageheader;
350
351 if ( verbose & VERB_DEBUG )
352 cout << "DEBUG readPIF: Done" << endl;
353
354 return 0;
355 }
356
357 char* read_sf(ifstream* fimg, Bimage* p, int mode, int sb)
358 {
359 error_show("Note: Structure factor format within PIF is not supported!", __FILE__, __LINE__);
360
361 return NULL;
362 }
363
370 int writePIF(Bimage* p)
371 {
372 // double PIFscale = PIFSCALE;
373
374 p->color_to_simple();
375
376 switch ( p->data_type() ) {
377 case Bit:
378 case SCharacter: p->change_type(UCharacter); break;
379 case UShort: p->change_type(Short); break;
380 default: break;
381 }
382
383 if ( verbose & VERB_DEBUG )
384 cout << "DEBUG writePIF: Writing PIF file" << endl;
385
386 // Map the parameters to the file header
387 long header_size = sizeof(PIFhead);
388 long image_header_size = sizeof(PIFimagehead);
389 PIFhead* header = new PIFhead;
390 memset(header, 0, sizeof(PIFhead));
391
392 // Scale factor to convert integers to floating point
393 if ( PIFscale <= 0 || PIFscale > PIF_SCALE ) {
394 // if ( p->scale > 0 && p->scale < PIF_SCALE ) PIFscale = p->scale;
395 // else PIFscale = PIF_SCALE;
396 PIFscale = PIF_SCALE;
397 if ( PIFscale > (p->maximum() - p->minimum())*PIF_SCALE ) PIFscale = (p->maximum() - p->minimum())*PIF_SCALE;
398 }
399 if ( fabs(p->minimum()/PIFscale) > INT_MAX ) PIFscale = fabs(p->minimum()/INT_MAX);
400 if ( fabs(p->maximum()/PIFscale) > INT_MAX ) PIFscale = fabs(p->maximum()/INT_MAX);
401
402 if ( verbose & VERB_DEBUG )
403 cout << "DEBUG writePIF: PIF scale factor: " << PIFscale << endl;
404 double invPIFscale = 1.0L/PIFscale;
405 char astring[32];
406
407 header->file_id[0] = 8; // Need to change this!
408 header->file_id[4] = 8; // Need to change this!
409 snprintf(astring, 32, " %13e", PIFscale);
410 strncpy(header->realscalefactor, astring, 16);
411 snprintf(astring, 32, "%16.9E", invPIFscale);
412 strncpy(header->floatScaleStr, astring, 16);
413 header->numimages = p->images();
414 header->endianness = 1; // Byte order
415 if ( systype(0) >= LittleIEEE ) header->endianness = 0;
416 header->htype = 1; // Flag to indicate all images of same size
417 header->nx = p->sizeX();
418 header->ny = p->sizeY();
419 header->nz = p->sizeZ();
420 switch ( p->data_type() ) { // Many more types!
421 case UCharacter:
422 header->mode = 0;
423 if ( p->images() > 1 ) header->mode = 6;
424 break;
425 case Short:
426 header->mode = 1;
427 if ( p->sizeZ() > 1 ) header->mode = 20;
428 if ( p->compound_type() == TComplex ) header->mode = 3;
429 break;
430 case Integer:
431 header->mode = 2;
432 if ( p->sizeZ() > 1 ) header->mode = 21;
433 if ( p->images() > 1 ) header->mode = 46;
434 if ( p->compound_type() == TComplex ) header->mode = 4;
435 break;
436 case Float:
437 header->mode = 9;
438 if ( p->compound_type() == TComplex ) header->mode = 10;
439 break;
440 case Double:
441 header->mode = 40;
442 if ( p->compound_type() == TComplex ) header->mode = 41;
443 break;
444 default: header->mode = 0; break;
445 }
446 snprintf(astring, 32, "Bsoft %s", BVERSION);
447 memset(header->genprogram, ' ', 32);
448 memcpy(header->genprogram, astring, strlen(astring));
449
450 // Map the parameters to the image header
451 UnitCell uc = p->unit_cell();
452
453 PIFimagehead* imageheader = new PIFimagehead;
454 PIFimagehead_new* imageheader_new = (PIFimagehead_new *) imageheader;
455 memset(imageheader, 0, sizeof(PIFimagehead));
456
457 strcpy(imageheader->timestamp, asctime(p->get_localtime()));
458 imageheader->mode = header->mode;
459 imageheader->nx = p->sizeX();
460 imageheader->ny = p->sizeY();
461 imageheader->nz = p->sizeZ();
462 imageheader->mx = (int) (uc.a()/p->sampling(0)[0] + 0.5);
463 imageheader->my = (int) (uc.b()/p->sampling(0)[1] + 0.5);
464 imageheader->mz = (int) (uc.c()/p->sampling(0)[2] + 0.5);
465 imageheader_new->pixelsize_x = (int) (p->sampling(0)[0]*invPIFscale + 0.5);
466 imageheader_new->pixelsize_y = (int) (p->sampling(0)[1]*invPIFscale + 0.5);
467 imageheader_new->pixelsize_z = (int) (p->sampling(0)[2]*invPIFscale + 0.5);
468 imageheader_new->pixelSize = imageheader_new->pixelsize_x;
469 imageheader_new->pixSizUnits = 1;
470 imageheader->mapc = 1;
471 imageheader->mapr = 2;
472 imageheader->maps = 3;
473 imageheader->min = (int) (p->minimum()*invPIFscale + 0.5);
474 imageheader->max = (int) (p->maximum()*invPIFscale + 0.5);
475 imageheader->mean = (int) (p->average()*invPIFscale + 0.5);
476 imageheader->stddev = (int) (p->standard_deviation()*invPIFscale + 0.5);
477 imageheader->xlength = (int) (uc.a()*invPIFscale + 0.5);
478 imageheader->ylength = (int) (uc.b()*invPIFscale + 0.5);
479 imageheader->zlength = (int) (uc.c()*invPIFscale + 0.5);
480 imageheader->alpha = (int) (uc.alpha()*180.0/(M_PI*PIFscale) + 0.5);
481 imageheader->beta = (int) (uc.beta()*180.0/(M_PI*PIFscale) + 0.5);
482 imageheader->gamma = (int) (uc.gamma()*180.0/(M_PI*PIFscale) + 0.5);
483 imageheader->ispg = p->space_group();
484 imageheader->aoverb = (int) (1.0*invPIFscale + 0.5);
485 imageheader->map_abang = imageheader->gamma;
486 imageheader->dela = (int) (1.0*invPIFscale + 0.5);
487 imageheader->delb = (int) (1.0*invPIFscale + 0.5);
488 imageheader->delc = (int) (1.0*invPIFscale + 0.5);
489
490 if ( verbose & VERB_DEBUG ) {
491 cout << "DEBUG writePIF: pixelsize=" << PIFscale*imageheader->pixelsize_x << "," <<
492 PIFscale*imageheader->pixelsize_y << "," << PIFscale*imageheader->pixelsize_z << endl;
493 cout << "DEBUG writePIF: min=" << imageheader->min << " max=" << imageheader->max <<
494 " mean=" << imageheader->mean << " std=" << imageheader->stddev << endl;
495 cout << "DEBUG writePIF: Writing labels" << endl;
496 }
497
498 long label_size = p->label().length();
499 if ( label_size > 255 ) label_size = 255;
500 memcpy(header->label, p->label().c_str(), label_size);
501 header->label[label_size] = 0;
502 if ( label_size > 79 ) label_size = 79;
503 memcpy(imageheader->title, p->label().c_str(), label_size);
504 imageheader->title[label_size] = 0;
505
506 // imageheader->nsymbt = p->nsym*80;
507
508 p->data_offset(PIFSIZE);
509
510 long xstore = p->sizeX();
511 if ( p->compound_type() == TComplex ) xstore = p->sizeX()/2 + 1;
512 long datatypesize = p->channels()*p->data_type_size();
513 long datasize = xstore*p->sizeY()*p->sizeZ()*datatypesize;
514
515 if ( verbose & VERB_DEBUG ) {
516 cout << "DEBUG writePIF: header size=" << header_size << " image header size =" <<
517 image_header_size << " new image header size = " << sizeof(PIFimagehead_new) << endl;
518 cout << "DEBUG writePIF: offset=" << p->data_offset() << " typesize=" <<
519 datatypesize << " datasize =" << datasize << endl;
520 }
521
522 long n;
523 unsigned char* data = NULL;
524 unsigned char* aptr = p->data_pointer();
525
526 if ( p->compound_type() == TComplex ) data = new unsigned char[datasize];
527
528 ofstream fimg(p->file_name());
529 if ( fimg.fail() ) return -1;
530
531 fimg.write((char *)header, header_size);
532
533 if ( header->mode == 31 || header->mode == 32 ) {
534 if ( verbose & VERB_DEBUG )
535 cout << "DEBUG writePIF: Writing structure factors not yet implemented" << endl;
536
537 } else {
538 for ( n=0; n<p->images(); n++ ) {
539 imageheader->bkgnd = (int) (p->background(n) + 0.5);
540 imageheader->min = (int) (p->image[n].minimum()*invPIFscale + 0.5);
541 imageheader->max = (int) (p->image[n].maximum()*invPIFscale + 0.5);
542 imageheader->mean = (int) (p->image[n].average()*invPIFscale + 0.5);
543 imageheader->stddev = (int) (p->image[n].standard_deviation()*invPIFscale + 0.5);
544 if ( p->image[n].origin()[0] >= 0 )
545 imageheader->nxstart = (int) -(p->image[n].origin()[0] + 0.5);
546 else
547 imageheader->nxstart = (int) -(p->image[n].origin()[0] - 0.5);
548 if ( p->image[n].origin()[1] >= 0 )
549 imageheader->nystart = (int) -(p->image[n].origin()[1] + 0.5);
550 else
551 imageheader->nystart = (int) -(p->image[n].origin()[1] - 0.5);
552 if ( p->image[n].origin()[2] >= 0 )
553 imageheader->nzstart = (int) -(p->image[n].origin()[2] + 0.5);
554 else
555 imageheader->nzstart = (int) -(p->image[n].origin()[2] - 0.5);
556 imageheader_new->origX = (int) (p->image[n].origin()[0]*invPIFscale + 0.5);
557 imageheader_new->origY = (int) (p->image[n].origin()[1]*invPIFscale + 0.5);
558 imageheader_new->origZ = (int) (p->image[n].origin()[2]*invPIFscale + 0.5);
559 imageheader_new->view_x = (int) (p->image[n].view()[0]*invPIFscale + 0.5);
560 imageheader_new->view_y = (int) (p->image[n].view()[1]*invPIFscale + 0.5);
561 imageheader_new->view_z = (int) (p->image[n].view()[2]*invPIFscale + 0.5);
562 imageheader_new->view_angle = (int) (p->image[n].view().angle()*invPIFscale + 0.5);
563 fimg.write((char *)imageheader, image_header_size);
564 if ( p->compound_type() < TComplex ) {
565 fimg.write((char *)aptr, datasize);
566 } else {
567 p->pack_transform(n, data, CentHerm);
568 fimg.write((char *)data, datasize);
569 }
570 aptr += datasize;
571 }
572 }
573
574 fimg.close();
575
576 if ( data ) delete[] data;
577
578 delete header;
579 delete imageheader;
580
581 return 0;
582 }
583
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
SWAPTRIG
#define SWAPTRIG
Definition: rwimg.h:16
PIFhead::label
char label[256]
Definition: rwPIF.h:39
PIFimagehead_new::view_x
int view_x
Definition: rwPIF.h:182
PIFhead::file_id
char file_id[8]
Definition: rwPIF.h:16
PIFimagehead::ylength
int ylength
Definition: rwPIF.h:62
UnitCell
Definition: UnitCell.h:22
PIFhead::floatScaleStr
char floatScaleStr[16]
Definition: rwPIF.h:31
PIFimagehead::xlength
int xlength
Definition: rwPIF.h:61
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:143
PIFimagehead::ny
int ny
Definition: rwPIF.h:50
PIFimagehead_new::origZ
int origZ
Definition: rwPIF.h:177
writePIF
int writePIF(Bimage *p)
Writing a PIF image file format. A 2D and 3D image format used in electron microscopy.
Definition: rwPIF.cpp:370
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
BVERSION
#define BVERSION
Definition: utilities.h:9
PIFimagehead_new::pixelsize_y
int pixelsize_y
Definition: rwPIF.h:180
read_sf
char * read_sf(ifstream *fimg, Bimage *p, int mode, int sb)
Definition: rwPIF.cpp:357
LittleIEEE
Definition: utilities.h:131
PIFcolor
Definition: rwPIF.h:42
UnitCell::gamma
void gamma(double d)
Definition: UnitCell.h:41
PIFimagehead_new::pixelsize_z
int pixelsize_z
Definition: rwPIF.h:181
Bimage::data_type_size
long data_type_size() const
Returns the size of the datatype in bytes.
Definition: Bimage.cpp:1585
PIFimagehead::mapc
int mapc
Definition: rwPIF.h:67
PIFhead::nz
int nz
Definition: rwPIF.h:24
utilities.h
Header file for general utilities.
PIF_SCALE
#define PIF_SCALE
Definition: rwPIF.cpp:19
PIFhead::endianness
int endianness
Definition: rwPIF.h:19
PIFimagehead::dela
int dela
Definition: rwPIF.h:84
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
PIFhead::genprogram
char genprogram[32]
Definition: rwPIF.h:20
PIFimagehead::title
char title[80]
Definition: rwPIF.h:78
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
UnitCell::beta
void beta(double d)
Definition: UnitCell.h:40
PIFimagehead::alpha
int alpha
Definition: rwPIF.h:64
Integer
Definition: utilities.h:154
PIFimagehead::nx
int nx
Definition: rwPIF.h:49
PIFimagehead::pixelsize_y
int pixelsize_y
Definition: rwPIF.h:100
PIFhead::nx
int nx
Definition: rwPIF.h:22
PIFhead
Definition: rwPIF.h:15
PIFimagehead::aoverb
int aoverb
Definition: rwPIF.h:82
month
char * month[]
Definition: rwimg.cpp:55
PIFimagehead::nystart
int nystart
Definition: rwPIF.h:56
SCharacter
Definition: utilities.h:150
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
UnitCell::a
void a(double d)
Definition: UnitCell.h:36
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
TComplex
Definition: Bimage.h:59
rwPIF.h
Header file for reading and writing PIF files.
Bimage::pack_transform
int pack_transform(unsigned char *data, FourierType tf)
Definition: Bimage.cpp:2422
TSimple
Definition: Bimage.h:58
Float
Definition: utilities.h:157
PIFimagehead::ispg
int ispg
Definition: rwPIF.h:74
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::data_alloc
unsigned char * data_alloc()
Definition: Bimage.h:256
PIFimagehead::nzstart
int nzstart
Definition: rwPIF.h:57
PIFimagehead::pixelsize_z
int pixelsize_z
Definition: rwPIF.h:101
PIFimagehead::mean
int mean
Definition: rwPIF.h:72
PIFimagehead::maps
int maps
Definition: rwPIF.h:69
M_PI
#define M_PI
Definition: utilities.h:59
PIFimagehead::min
int min
Definition: rwPIF.h:70
PIFimagehead::nz
int nz
Definition: rwPIF.h:51
PIFimagehead_new::ctfMode
int ctfMode
Definition: rwPIF.h:162
PIFhead::htype
int htype
Definition: rwPIF.h:21
Bimage::maximum
double maximum()
Definition: Bimage.h:535
PIFhead::realscalefactor
char realscalefactor[16]
Definition: rwPIF.h:17
Double
Definition: utilities.h:158
readPIF
int readPIF(Bimage *p, int readdata, int img_select)
Reading a PIF image and structure factor file format. A 2D and 3D image format used in electron micro...
Definition: rwPIF.cpp:60
PIFimagehead_new::pixelSize
int pixelSize
Definition: rwPIF.h:159
CentHerm
Definition: Bimage.h:44
PIFimagehead::pixelsize_x
int pixelsize_x
Definition: rwPIF.h:99
PIFimagehead::my
int my
Definition: rwPIF.h:59
Bimage::label
void label(string s)
Definition: Bimage.h:235
PIFhead::ny
int ny
Definition: rwPIF.h:23
Bimage::set_time
void set_time(time_t t)
Definition: Bimage.h:249
PIFscale
double PIFscale
Definition: rwPIF.cpp:20
PIFimagehead::nxstart
int nxstart
Definition: rwPIF.h:55
Bimage::unit_cell
void unit_cell(UnitCell uc)
Definition: Bimage.h:601
UnitCell::b
void b(double d)
Definition: UnitCell.h:37
sb
int sb(0)
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
PIFimagehead::delb
int delb
Definition: rwPIF.h:85
file_util.h
Header file for file checking functions.
Bsub_image::maximum
double maximum()
Definition: Bimage.h:114
PIFimagehead::map_abang
int map_abang
Definition: rwPIF.h:83
Bimage::data_offset
long data_offset()
Definition: Bimage.h:265
Bimage::get_localtime
tm * get_localtime()
Definition: Bimage.h:245
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bimage::channels
long channels()
Definition: Bimage.h:371
swapbytes
void swapbytes(unsigned char *v, size_t n)
Swaps bytes.
Definition: utilities.cpp:504
PIFimagehead_new::pixSizUnits
int pixSizUnits
Definition: rwPIF.h:160
Bimage::unpack_transform
int unpack_transform(unsigned char *data, FourierType tf)
Definition: Bimage.cpp:2337
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:537
Bimage::space_group
long space_group()
Definition: Bimage.h:591
PIFimagehead::zlength
int zlength
Definition: rwPIF.h:63
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:261
verbose
int verbose
UnitCell::alpha
void alpha(double d)
Definition: UnitCell.h:39
PIFimagehead::bkgnd
int bkgnd
Definition: rwPIF.h:53
UCharacter
Definition: utilities.h:149
PIFimagehead::gamma
int gamma
Definition: rwPIF.h:66
PIFimagehead_new::pixelsize_x
int pixelsize_x
Definition: rwPIF.h:179
PIFimagehead_new::view_y
int view_y
Definition: rwPIF.h:183
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bit
Definition: utilities.h:148
PIFhead::numimages
int numimages
Definition: rwPIF.h:18
UnitCell::degrees_to_radians
void degrees_to_radians()
Definition: UnitCell.h:54
PIFimagehead_new::view_angle
int view_angle
Definition: rwPIF.h:185
Bsub_image::minimum
double minimum()
Definition: Bimage.h:113
PIFimagehead::mapr
int mapr
Definition: rwPIF.h:68
fread_large
int fread_large(unsigned char *aptr, size_t pagesize, size_t offset, ifstream *fimg)
Reads blocks of memeory no larger than 1Gb.
Definition: file_util.cpp:347
PIFimagehead::delc
int delc
Definition: rwPIF.h:86
Bimage::alloc_size
long alloc_size() const
Definition: Bimage.h:252
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< double >
PIFimagehead::stddev
int stddev
Definition: rwPIF.h:73
PIFimagehead::beta
int beta
Definition: rwPIF.h:65
PIFimagehead
Definition: rwPIF.h:48
PIFimagehead::mx
int mx
Definition: rwPIF.h:58
PIFimagehead_new::view_z
int view_z
Definition: rwPIF.h:184
PIFSIZE
#define PIFSIZE
Definition: rwPIF.h:13
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1349
Bimage::color_to_simple
void color_to_simple()
A color image is converted to a simple image.
Definition: Bimage_color.cpp:94
Short
Definition: utilities.h:152
PIFimagehead::timestamp
char timestamp[32]
Definition: rwPIF.h:79
PIFimagehead_new::origX
int origX
Definition: rwPIF.h:175
PIFimagehead::max
int max
Definition: rwPIF.h:71
PIFhead::mode
int mode
Definition: rwPIF.h:25
Bsub_image::average
double average()
Definition: Bimage.h:115
PIFimagehead_new
Definition: rwPIF.h:109
PIFimagehead::mz
int mz
Definition: rwPIF.h:60
UShort
Definition: utilities.h:151
Bimage::page_size
Vector3< long > page_size()
Definition: Bimage.h:480
Bimage::images
long images()
Definition: Bimage.h:491
systype
SysType systype(int show)
Finds the system type - mostly just for byte order.
Definition: utilities.cpp:144
PIFimagehead_new::origY
int origY
Definition: rwPIF.h:176
Bimage::background
double background(long nn)
Definition: Bimage.h:542
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
Bimage::minimum
double minimum()
Definition: Bimage.h:534
Bsub_image::standard_deviation
double standard_deviation()
Definition: Bimage.h:116
PIFimagehead::mode
int mode
Definition: rwPIF.h:52
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:755
UnitCell::c
void c(double d)
Definition: UnitCell.h:38
Bimage::image
Bsub_image * image
Definition: Bimage.h:188