TPCCLIB
Loading...
Searching...
No Matches
ecatcat.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <math.h>
13#include <string.h>
14#include <time.h>
15/*****************************************************************************/
16#include "libtpcmisc.h"
17#include "libtpcimgio.h"
18/*****************************************************************************/
19
20/*****************************************************************************/
21static char *info[] = {
22 "Combine two or more dynamic ECAT 6.3 or 7.x images or sinograms.",
23 "This program can be used to catenate separate scans/images from one study,",
24 "when imaging session has been interrupted for some reason, or when",
25 "flat data with frames in separate files were converted to ECAT format.",
26 " ",
27 "Program corrects for decay and frame times to the start time of the first",
28 "specified image/sinogram. Use the original images or sinograms, if possible,",
29 "Input images must be decay corrected to the scan start time that is",
30 "specified in the main header and shown by this program.",
31 " ",
32 "Usage: @P [Options] file1 file2 [file3 ...] outputfile",
33 " ",
34 "Options:",
35 " -stdoptions", // List standard options like --help, -v, etc
36 " ",
37 "See also: lmlist, eframe, lmhdr, sifcat, taccat, esplit, imgdelfr, imgcat",
38 " ",
39 "Example:",
40 " @P a2345dy1.v a2345dy2.v a2345dy.v",
41 " ",
42 "Keywords: image, ECAT, tool, catenate, time",
43 0};
44/*****************************************************************************/
45
46/*****************************************************************************/
47/* Turn on the globbing of the command line, since it is disabled by default in
48 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
49 In Unix&Linux wildcard command line processing is enabled by default. */
50/*
51#undef _CRT_glob
52#define _CRT_glob -1
53*/
54int _dowildcard = -1;
55/*****************************************************************************/
56
57/*****************************************************************************/
61int main(int argc, char **argv)
62{
63 int ai, help=0, version=0, verbose=1;
64 int i, ii, m, ret, frameNr, planeNr, blkNr;
65 int fformat=63;
66 int plane, prev_plane, frame, catframeNr, catplaneNr;
67 int matrixNr, pxlNr=0, blk, nxtblk, dimz;
68 char ecatfile[FILENAME_MAX], catfile[FILENAME_MAX],
69 tmp[FILENAME_MAX], *mdata, *cptr;
70 int ffi=0, fileNr=0;
71 FILE *fp1, *fp2;
72 ECAT63_mainheader e63first_mhdr, e63mhdr;
73 ECAT7_mainheader e7first_mhdr, e7mhdr;
74 MATRIXLIST e63mlist;
75 ECAT7_MATRIXLIST e7mlist;
76 ECAT63_imageheader e63ihdr;
77 ECAT7_imageheader e7ihdr;
78 ECAT63_scanheader e63shdr;
79 ECAT7_scanheader e7shdr3d;
80 ECAT7_2Dscanheader e7shdr2d;
81 Matval e63matval;
82 ECAT7_Matval e7matval;
83 int matnum, datatype=0, t;
84 float decayf;
85
86
87 /*
88 * Get arguments
89 */
90 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
91 ecatfile[0]=catfile[0]=(char)0;
92 ecat63InitMatlist(&e63mlist); ecat7InitMatlist(&e7mlist);
93 /* Options */
94 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') { /* options */
95 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
96 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
97 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
98 return(1);
99 } else break;
100
101 /* Print help or version? */
102 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
103 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
104 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
105
106 /* Last argument is the output filename */
107 strcpy(catfile, argv[argc-1]);
108
109 /* Process other arguments, starting from the first non-option */
110 for(; ai<argc-1; ai++) { // do not process the last name again
111 if(ffi<1) ffi=ai; // save the first input file position
112 /* check that file exists */
113 if(access(argv[ai], 0) == -1) {
114 fprintf(stderr, "Error: file '%s' does not exist.\n", argv[ai]);
115 return(1);
116 }
117 /* Check that output file does not overwrite any of input files */
118 if(strcasecmp(argv[ai], catfile)==0) {
119 fprintf(stderr, "Error: same name for input and output file.\n");
120 return(1);
121 }
122 fileNr++;
123 }
124
125 /* Is something missing? */
126 if(fileNr<2) {
127 fprintf(stderr, "Error: missing command-line argument; try %s --help\n",
128 argv[0]);
129 return(1);
130 }
131
132 /* In verbose mode print arguments and options */
133 if(verbose>1) {
134 printf("catenated_file := %s\n", catfile);
135 printf("fileNr := %d\n", fileNr);
136 }
137
138 /*
139 * Check if output file exists; rename to backup file, if necessary
140 */
141 ret=backupExistingFile(catfile, NULL, tmp);
142 if(ret) {
143 fprintf(stderr, "Error: %s\n", tmp);
144 return(2);
145 }
146
147
148 /*
149 * Read first main header
150 */
151 strcpy(ecatfile, argv[ffi]);
152 if(verbose>1) printf("reading first main header in %s\n", ecatfile);
153 /* Open file */
154 if((fp1=fopen(ecatfile, "rb")) == NULL) {
155 fprintf(stderr, "Error: cannot open file %s\n", ecatfile);
156 return(2);
157 }
158 /* Read main header */
159 /* Try to read ECAT 7.x main header */
160 ret=ecat7ReadMainheader(fp1, &e7first_mhdr);
161 if(ret) {
162 fprintf(stderr, "Error (%d): cannot read main header.\n", ret);
163 fclose(fp1); return(2);
164 }
165 /* If header could be read, check for magic number */
166 if(strncmp(e7first_mhdr.magic_number, ECAT7V_MAGICNR, 7)==0) {
167 /* This is ECAT 7.x file */
168 fformat=7;
169 /* Close file */
170 fclose(fp1);
171 /* Check if file type is supported */
172 if(e7first_mhdr.file_type!=ECAT7_VOLUME8 &&
173 e7first_mhdr.file_type!=ECAT7_VOLUME16 &&
174 e7first_mhdr.file_type!=ECAT7_IMAGE8 &&
175 e7first_mhdr.file_type!=ECAT7_IMAGE16 &&
176 e7first_mhdr.file_type!=ECAT7_2DSCAN &&
177 e7first_mhdr.file_type!=ECAT7_3DSCAN8 &&
178 e7first_mhdr.file_type!=ECAT7_3DSCAN
179 ) {
180 fprintf(stderr, "Error: illegal file_type in %s\n", ecatfile);
181 return(3);
182 }
183 if(verbose>1) printf("%s is identified as an ECAT 7 file.\n", ecatfile);
184 } else { /* Try to read as ECAT 6.3 file */
185 if((ret=ecat63ReadMainheader(fp1, &e63first_mhdr))) {
186 fprintf(stderr, "Error (%d): cannot read main header.\n", ret);
187 fclose(fp1); return(2);
188 }
189 if(verbose>10) ecat63PrintMainheader(&e63first_mhdr, stdout);
190 /* Close file */
191 fclose(fp1);
192 /* Check file type */
193 if(e63first_mhdr.file_type!=IMAGE_DATA &&
194 e63first_mhdr.file_type!=RAW_DATA) {
195 fprintf(stderr, "Error: illegal file_type in %s\n", ecatfile);
196 return(3);
197 }
198 /* This is ECAT 6.3 file */
199 fformat=63;
200 if(verbose>1) printf("%s is identified as an ECAT 6.3 file.\n", ecatfile);
201 }
202
203 /*
204 * Open output ECAT file
205 */
206 if(verbose>1) printf("creating output file %s\n", catfile);
207 if(fformat==63) fp2=ecat63Create(catfile, &e63first_mhdr);
208 else fp2=ecat7Create(catfile, &e7first_mhdr);
209 if(fp2==NULL) {
210 fprintf(stderr, "Error: cannot write file %s\n", catfile);
211 return(11);
212 }
213
214 /*
215 * Read one file at a time and write the contents to output file
216 */
217 catframeNr=catplaneNr=0;
218 for(ii=ffi; ii<argc-1; ii++) { // -1 to not go to output file
219
220 /* Open file */
221 strcpy(ecatfile, argv[ii]);
222 if(verbose>0) {fprintf(stdout, " reading %s\n", ecatfile); fflush(stdout);}
223 if((fp1=fopen(ecatfile, "rb")) == NULL) {
224 fprintf(stderr, "Error: cannot open file %s\n", ecatfile);
225 fclose(fp2); remove(catfile); return(2);
226 }
227 /* Read main header */
228 if(fformat==63) ret=ecat63ReadMainheader(fp1, &e63mhdr);
229 else ret=ecat7ReadMainheader(fp1, &e7mhdr);
230 if(ret) {
231 fprintf(stderr, "Error (%d): cannot read main header.\n", ret);
232 fclose(fp1); fclose(fp2); remove(catfile); return(2);
233 }
234 if(verbose>20) {
235 if(fformat==63) ecat63PrintMainheader(&e63mhdr, stdout);
236 else ecat7PrintMainheader(&e7mhdr, stdout);
237 }
238
239 /* Check file and data type */
240 if((fformat==63 && e63mhdr.file_type!=e63first_mhdr.file_type) ||
241 (fformat==7 && e7mhdr.file_type!=e7first_mhdr.file_type)) {
242 fprintf(stderr, "Error: different file_type in %s\n", ecatfile);
243 fclose(fp1); fclose(fp2); remove(catfile); return(3);
244 }
245 if(fformat==63 && e63mhdr.data_type!=e63first_mhdr.data_type) {
246 fprintf(stderr, "Error: different data_type in %s\n", ecatfile);
247 fclose(fp1); fclose(fp2); remove(catfile); return(3);
248 }
249
250 /* Print the scan start time */
251 if(verbose>0) {
252 char *p;
253 if(fformat==63) p=ecat63ScanstarttimeInt(&e63mhdr, tmp);
254 else {time_t t=e7mhdr.scan_start_time; p=ctime_r_int(&t, tmp);}
255 if(!p) {
256 fprintf(stderr, "Warning: invalid scan_start_time in %s\n", ecatfile);
257 //fclose(fp1); fclose(fp2); remove(catfile); return(3);
258 }
259 fprintf(stdout, " scan_start_time := %s\n", tmp);
260 }
261
262 /* Calculate the difference (sec) in scan start times */
263 if(fformat==63) {
264 t=(e63mhdr.scan_start_second - e63first_mhdr.scan_start_second) +
265 60*(e63mhdr.scan_start_minute - e63first_mhdr.scan_start_minute) +
266 3600*(e63mhdr.scan_start_hour - e63first_mhdr.scan_start_hour) +
267 86400*(e63mhdr.scan_start_day - e63first_mhdr.scan_start_day);
268 } else {
269 t=e7mhdr.scan_start_time - e7first_mhdr.scan_start_time;
270 }
271 if(t<-30) {
272 fprintf(stderr, "Error: check the order of files and scan start times.\n");
273 fclose(fp1); fclose(fp2); remove(catfile); return(3);
274 }
275 if(t<0) {
276 fprintf(stderr, " Warning: possible inaccuracies in scan start times.\n");
277 }
278 /* and decay correction */
279 if(fformat==63) {
280 if(e63mhdr.isotope_halflife<=0.0) decayf=1.0;
281 else decayf=exp(M_LN2*(float)t/e63mhdr.isotope_halflife);
282 } else {
283 if(e7mhdr.isotope_halflife<=0.0) decayf=1.0;
284 else decayf=exp(M_LN2*(float)t/e7mhdr.isotope_halflife);
285 }
286 if(verbose>0) printf(" t=%d sec => decayf=%g\n", t, decayf);
287
288
289 /*
290 * Read matrix list and nr
291 */
292 if(fformat==63) ret=ecat63ReadMatlist(fp1, &e63mlist, verbose-2);
293 else ret=ecat7ReadMatlist(fp1, &e7mlist, verbose-2);
294 if(ret) {
295 fprintf(stderr, "Error (%d): cannot read matrix list.\n", ret);
296 fclose(fp1); fclose(fp2); remove(catfile); return(4);
297 }
298 if((fformat==63 && e63mlist.matrixNr<=0) ||
299 (fformat==7 && e7mlist.matrixNr<=0)) {
300 fprintf(stderr, "Error: matrix list is empty.\n");
301 fclose(fp1); fclose(fp2); remove(catfile); return(4);
302 }
303 if(verbose>30) {
304 if(fformat==63) ecat63PrintMatlist(&e63mlist);
305 else ecat7PrintMatlist(&e7mlist);
306 }
307 /* Sort matrix list */
308 if(fformat==63) ecat63SortMatlistByPlane(&e63mlist);
309 else ecat7SortMatlistByPlane(&e7mlist);
310 if(0) {
311 printf("and after sorting:\n");
312 if(fformat==63) ecat63PrintMatlist(&e63mlist);
313 else ecat7PrintMatlist(&e7mlist);
314 }
315
316 /*
317 * Read and write matrix data
318 */
319 prev_plane=plane=-1; frameNr=planeNr=0;
320 if(fformat==63) matrixNr=e63mlist.matrixNr;
321 else matrixNr=e7mlist.matrixNr;
322 for(m=0; m<matrixNr; m++) {
323
324 /* get frame and plane */
325 if(fformat==63) {
326 mat_numdoc(e63mlist.matdir[m].matnum, &e63matval);
327 plane=e63matval.plane;
328 if(e63mhdr.num_frames>=e63mhdr.num_gates) frame=e63matval.frame;
329 else frame=e63matval.gate;
330 if(verbose>1) printf(" frame=%d plane=%d\n", frame, plane);
331 } else {
332 ecat7_id_to_val(e7mlist.matdir[m].id, &e7matval);
333 plane=e7matval.plane;
334 if(e7mhdr.num_frames>=e7mhdr.num_gates) frame=e7matval.frame;
335 else frame=e7matval.gate;
336 if(verbose>1) printf(" frame=%d\n", frame);
337 }
338
339 /* calculate plane and frame number */
340 if(plane!=prev_plane) {frameNr=1; planeNr++;} else {frameNr++;}
341 prev_plane=plane;
342
343 /* Read subheader */
344 if(fformat==63) {
345 if(e63mhdr.file_type==IMAGE_DATA) {
346 ret=ecat63ReadImageheader(fp1, e63mlist.matdir[m].strtblk, &e63ihdr, verbose-3, NULL);
347 datatype=e63ihdr.data_type;
348 } else if(e63mhdr.file_type==RAW_DATA) {
349 ret=ecat63ReadScanheader(fp1, e63mlist.matdir[m].strtblk, &e63shdr, verbose-3, NULL);
350 datatype=e63shdr.data_type;
351 }
352 if(ret) {
353 fprintf(stderr, "Error: cannot read matrix %u subheader in '%s'.\n",
354 e63mlist.matdir[m].matnum, ecatfile);
355 fclose(fp1); fclose(fp2); remove(catfile);
356 ecat63EmptyMatlist(&e63mlist);
357 return(5);
358 }
359 } else {
360 if(e7first_mhdr.file_type==ECAT7_VOLUME8 ||
361 e7first_mhdr.file_type==ECAT7_VOLUME16 ||
362 e7first_mhdr.file_type==ECAT7_IMAGE8 ||
363 e7first_mhdr.file_type==ECAT7_IMAGE16) {
364 ret=ecat7ReadImageheader(fp1, e7mlist.matdir[m].strtblk, &e7ihdr);
365 datatype=e7ihdr.data_type;
366 } else if(e7first_mhdr.file_type==ECAT7_2DSCAN) {
367 ret=ecat7Read2DScanheader(fp1, e7mlist.matdir[m].strtblk, &e7shdr2d);
368 datatype=e7shdr2d.data_type;
369 } else if(e7first_mhdr.file_type==ECAT7_3DSCAN8 ||
370 e7first_mhdr.file_type==ECAT7_3DSCAN) {
371 ret=ecat7ReadScanheader(fp1, e7mlist.matdir[m].strtblk, &e7shdr3d);
372 datatype=e7shdr3d.data_type;
373 }
374 if(ret) {
375 fprintf(stderr, "Error: cannot read matrix %u subheader in '%s'.\n",
376 e7mlist.matdir[m].id, ecatfile);
377 fclose(fp1); fclose(fp2); remove(catfile);
378 ecat7EmptyMatlist(&e7mlist);
379 return(6);
380 }
381 }
382
383 /* Calculate the size of data */
384 if(fformat==63)
385 blkNr=e63mlist.matdir[m].endblk-e63mlist.matdir[m].strtblk;
386 else {
387 blkNr=e7mlist.matdir[m].endblk-e7mlist.matdir[m].strtblk;
388 if(e7first_mhdr.file_type==ECAT7_3DSCAN8 ||
389 e7first_mhdr.file_type==ECAT7_3DSCAN) blkNr--;
390 }
391 /* Allocate memory for data */
392 mdata=(char*)malloc(blkNr*MatBLKSIZE);
393 if(mdata==NULL) {
394 fprintf(stderr, "Error: out of memory.\n");
395 fclose(fp1); fclose(fp2); remove(catfile);
396 if(fformat==63) ecat63EmptyMatlist(&e63mlist);
397 else ecat7EmptyMatlist(&e7mlist);
398 return(6);
399 }
400
401 /* Read matrix data */
402 if(fformat==63) {
403 blk=e63mlist.matdir[m].strtblk+1;
404 ret=ecat63ReadMatdata(fp1, blk, blkNr, mdata, datatype);
405 } else {
406 blk=e7mlist.matdir[m].strtblk+1;
407 if(e7first_mhdr.file_type==ECAT7_3DSCAN8 ||
408 e7first_mhdr.file_type==ECAT7_3DSCAN) blk++;
409 ret=ecat7ReadMatrixdata(fp1, blk, blkNr, mdata, datatype);
410 }
411 if(ret) {
412 fprintf(stderr, "Error: cannot read matrix data!\n");
413 fclose(fp1); fclose(fp2); remove(catfile);
414 if(fformat==63) ecat63EmptyMatlist(&e63mlist);
415 else ecat7EmptyMatlist(&e7mlist);
416 free(mdata);
417 return(7);
418 }
419
420 /* Change frame time */
421 if(fformat==63) {
422 if(e63mhdr.file_type==IMAGE_DATA) e63ihdr.frame_start_time+=1000*t;
423 else e63shdr.frame_start_time+=1000*t;
424 } else {
425 if(e7first_mhdr.file_type==ECAT7_VOLUME8 ||
426 e7first_mhdr.file_type==ECAT7_VOLUME16 ||
427 e7first_mhdr.file_type==ECAT7_IMAGE8 ||
428 e7first_mhdr.file_type==ECAT7_IMAGE16) {
429 e7ihdr.frame_start_time+=1000*t;
430 } else if(e7first_mhdr.file_type==ECAT7_2DSCAN) {
431 e7shdr2d.frame_start_time+=1000*t;
432 } else if(e7first_mhdr.file_type==ECAT7_3DSCAN8 ||
433 e7first_mhdr.file_type==ECAT7_3DSCAN) {
434 e7shdr3d.frame_start_time+=1000*t;
435 }
436 }
437 /* Decay correction */
438 if(fformat==63) {
439 if(e63mhdr.file_type==IMAGE_DATA) {
440 e63ihdr.quant_scale*=decayf;
441 if(e63ihdr.decay_corr_fctr>0.0 && e63ihdr.decay_corr_fctr!=1.0)
442 e63ihdr.decay_corr_fctr*=decayf;
443 }
444 } else {
445 if(e7first_mhdr.file_type==ECAT7_VOLUME8 ||
446 e7first_mhdr.file_type==ECAT7_VOLUME16 ||
447 e7first_mhdr.file_type==ECAT7_IMAGE8 ||
448 e7first_mhdr.file_type==ECAT7_IMAGE16) {
449 e7ihdr.scale_factor*=decayf;
450 if(e7ihdr.decay_corr_fctr>0.0 && e7ihdr.decay_corr_fctr!=1.0)
451 e7ihdr.decay_corr_fctr*=decayf;
452 }
453 }
454
455 /* Write matrix data */
456 if(fformat==63)
457 matnum=mat_numcod(catframeNr+frameNr, plane, e63matval.gate,
458 e63matval.data, e63matval.bed);
459 else
460 matnum=ecat7_val_to_id(catframeNr+frameNr, plane, e7matval.gate,
461 e7matval.data, e7matval.bed);
462 if(fformat==63) {
463 if(e63mhdr.file_type==RAW_DATA) {
464 ret=ecat63WriteScan(fp2, matnum, &e63shdr, mdata);
465 } else if(e63mhdr.file_type==IMAGE_DATA) {
466 ret=ecat63WriteImage(fp2, matnum, &e63ihdr, mdata);
467 }
468 } else {
469 if(e7first_mhdr.file_type==ECAT7_VOLUME8 ||
470 e7first_mhdr.file_type==ECAT7_VOLUME16 ||
471 e7first_mhdr.file_type==ECAT7_IMAGE8 ||
472 e7first_mhdr.file_type==ECAT7_IMAGE16) {
473 /* Get block number for matrix header and data */
474 nxtblk=ecat7EnterMatrix(fp2, matnum, blkNr); if(nxtblk<1) ret=51;
475 /* Write header */
476 if(ret==0) ret=ecat7WriteImageheader(fp2, nxtblk, &e7ihdr);
477 /* Write matrix data */
478 pxlNr=e7ihdr.x_dimension*e7ihdr.y_dimension;
479 if(e7ihdr.num_dimensions>2) pxlNr*=e7ihdr.z_dimension;
480 if(ret==0) ret=ecat7WriteMatrixdata(fp2, nxtblk+1, mdata, pxlNr,
481 ecat7pxlbytes(e7ihdr.data_type));
482 } else if(e7first_mhdr.file_type==ECAT7_2DSCAN) {
483 nxtblk=ecat7EnterMatrix(fp2, matnum, blkNr); if(nxtblk<1) ret=51;
484 if(ret==0) ret=ecat7Write2DScanheader(fp2, nxtblk, &e7shdr2d);
485 pxlNr=e7shdr2d.num_r_elements*e7shdr2d.num_angles;
486 if(e7shdr2d.num_dimensions>2) pxlNr*=e7shdr2d.num_z_elements;
487 if(ret==0) ret=ecat7WriteMatrixdata(fp2, nxtblk+1, mdata, pxlNr,
488 ecat7pxlbytes(e7shdr2d.data_type));
489 } else if(e7first_mhdr.file_type==ECAT7_3DSCAN8 ||
490 e7first_mhdr.file_type==ECAT7_3DSCAN) {
491 /* Note that one extra block (blkNr+1) is needed for 3D scan header */
492 nxtblk=ecat7EnterMatrix(fp2, matnum, blkNr+1); if(nxtblk<1) ret=51;
493 if(ret==0) ret=ecat7WriteScanheader(fp2, nxtblk, &e7shdr3d);
494 pxlNr=e7shdr3d.num_r_elements*e7shdr3d.num_angles;
495 for(i=dimz=0; i<64; i++) dimz+=e7shdr3d.num_z_elements[i];
496 pxlNr*=dimz;
497 /* Note that 3D scan header takes TWO blocks */
498 if(ret==0) ret=ecat7WriteMatrixdata(fp2, nxtblk+2, mdata, pxlNr,
499 ecat7pxlbytes(e7shdr3d.data_type));
500 }
501 }
502 if(ret) {
503 fprintf(stderr, "Error (%d) in writing data on pl%02d fr%02d.\n",
504 ret, plane, frame);
505 fclose(fp1); fclose(fp2); remove(catfile);
506 if(fformat==63) ecat63EmptyMatlist(&e63mlist);
507 else ecat7EmptyMatlist(&e7mlist);
508 free(mdata);
509 return(12);
510 }
511 /* Free matrix data */
512 free(mdata);
513
514 } /* next matrix */
515 if(verbose>0) {
516 if(fformat==63)
517 fprintf(stdout, " %d frame(s) and %d plane(s) written in %s\n",
518 frameNr, planeNr, catfile);
519 else
520 fprintf(stdout, " %d frame(s) written in %s\n",
521 frameNr, catfile);
522 }
523 /* prepare for the next file */
524 catframeNr+=frameNr; if(planeNr>catplaneNr) catplaneNr=planeNr;
525 if(fformat==63) ecat63EmptyMatlist(&e63mlist);
526 else ecat7EmptyMatlist(&e7mlist);
527 fclose(fp1);
528 } /* next input file */
529
530 /* Rewrite the main header */
531 if(fformat==63) {
532 e63first_mhdr.num_planes=catplaneNr;
533 e63first_mhdr.num_frames=catframeNr;
534 ret=ecat63WriteMainheader(fp2, &e63first_mhdr);
535 } else {
536 if(catplaneNr>1) e7first_mhdr.num_planes=catplaneNr;
537 e7first_mhdr.num_frames=catframeNr;
538 ret=ecat7WriteMainheader(fp2, &e7first_mhdr);
539 }
540 /* close output file */
541 fclose(fp2);
542 if(ret) {
543 fprintf(stderr, "Error: cannot write the mainheader.\n");
544 remove(catfile);
545 return(14);
546 }
547 if(verbose>0) fprintf(stdout, " done.\n");
548
549 return(0);
550}
551/*****************************************************************************/
552
553/*****************************************************************************/
int backupExistingFile(char *filename, char *backup_ext, char *status)
Definition backup.c:14
char * ctime_r_int(const time_t *t, char *buf)
Convert calendard time t into a null-terminated string of the form YYYY-MM-DD hh:mm:ss,...
Definition datetime.c:110
int ecat63ReadMatlist(FILE *fp, MATRIXLIST *ml, int verbose)
Definition ecat63ml.c:46
void ecat63InitMatlist(MATRIXLIST *mlist)
Definition ecat63ml.c:20
void ecat63EmptyMatlist(MATRIXLIST *mlist)
Definition ecat63ml.c:31
int mat_numcod(int frame, int plane, int gate, int data, int bed)
Definition ecat63ml.c:242
void ecat63SortMatlistByPlane(MATRIXLIST *ml)
Definition ecat63ml.c:271
void ecat63PrintMatlist(MATRIXLIST *ml)
Definition ecat63ml.c:130
void mat_numdoc(int matnum, Matval *matval)
Definition ecat63ml.c:254
void ecat63PrintMainheader(ECAT63_mainheader *h, FILE *fp)
Definition ecat63p.c:16
char * ecat63ScanstarttimeInt(const ECAT63_mainheader *h, char *buf)
Convert scan_start_time in ECAT 6.3 main header into a null-terminated string of the form YYYY-MM-DD ...
Definition ecat63p.c:391
int ecat63ReadScanheader(FILE *fp, int blk, ECAT63_scanheader *h, int verbose, char *errmsg)
Definition ecat63r.c:377
int ecat63ReadMatdata(FILE *fp, int strtblk, int blkNr, char *data, int dtype)
Definition ecat63r.c:568
int ecat63ReadImageheader(FILE *fp, int blk, ECAT63_imageheader *h, int verbose, char *errmsg)
Definition ecat63r.c:187
int ecat63ReadMainheader(FILE *fp, ECAT63_mainheader *h)
Definition ecat63r.c:25
int ecat63WriteScan(FILE *fp, int matnum, ECAT63_scanheader *h, void *data)
Definition ecat63w.c:461
int ecat63WriteImage(FILE *fp, int matnum, ECAT63_imageheader *h, void *data)
Definition ecat63w.c:410
FILE * ecat63Create(const char *fname, ECAT63_mainheader *h)
Definition ecat63w.c:365
int ecat63WriteMainheader(FILE *fp, ECAT63_mainheader *h)
Definition ecat63w.c:24
void ecat7InitMatlist(ECAT7_MATRIXLIST *mlist)
Definition ecat7ml.c:15
void ecat7SortMatlistByPlane(ECAT7_MATRIXLIST *ml)
Definition ecat7ml.c:277
void ecat7_id_to_val(int matrix_id, ECAT7_Matval *matval)
Definition ecat7ml.c:262
int ecat7ReadMatlist(FILE *fp, ECAT7_MATRIXLIST *ml, int verbose)
Definition ecat7ml.c:41
void ecat7EmptyMatlist(ECAT7_MATRIXLIST *mlist)
Definition ecat7ml.c:26
int ecat7EnterMatrix(FILE *fp, int matrix_id, int block_nr)
Definition ecat7ml.c:147
int ecat7_val_to_id(int frame, int plane, int gate, int data, int bed)
Definition ecat7ml.c:245
void ecat7PrintMatlist(ECAT7_MATRIXLIST *ml)
Definition ecat7ml.c:112
void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp)
Definition ecat7p.c:16
int ecat7pxlbytes(short int data_type)
Definition ecat7r.c:1274
int ecat7ReadScanheader(FILE *fp, int blk, ECAT7_scanheader *h)
Definition ecat7r.c:536
int ecat7ReadMatrixdata(FILE *fp, int start_block, int block_nr, char *data, int dtype)
Definition ecat7r.c:791
int ecat7ReadMainheader(FILE *fp, ECAT7_mainheader *h)
Definition ecat7r.c:15
int ecat7Read2DScanheader(FILE *fp, int blk, ECAT7_2Dscanheader *h)
Definition ecat7r.c:631
int ecat7ReadImageheader(FILE *fp, int blk, ECAT7_imageheader *h)
Definition ecat7r.c:162
int ecat7WriteScanheader(FILE *fp, int blk, ECAT7_scanheader *h)
Definition ecat7w.c:383
int ecat7WriteImageheader(FILE *fp, int blk, ECAT7_imageheader *h)
Definition ecat7w.c:113
int ecat7WriteMatrixdata(FILE *fp, int start_block, char *data, long long pxl_nr, int pxl_size)
Definition ecat7w.c:974
int ecat7Write2DScanheader(FILE *fp, int blk, ECAT7_2Dscanheader *h)
Definition ecat7w.c:450
FILE * ecat7Create(const char *fname, ECAT7_mainheader *h)
Definition ecat7w.c:567
int ecat7WriteMainheader(FILE *fp, ECAT7_mainheader *h)
Definition ecat7w.c:16
Header file for libtpcimgio.
#define ECAT7_VOLUME8
#define ECAT7_3DSCAN
#define ECAT7_3DSCAN8
#define ECAT7_IMAGE16
#define ECAT7_VOLUME16
#define RAW_DATA
#define ECAT7_IMAGE8
#define IMAGE_DATA
#define MatBLKSIZE
#define ECAT7_2DSCAN
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
#define M_LN2
Definition libtpcmisc.h:90
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:213
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:383
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:158
short int scan_start_second
short int scan_start_day
short int scan_start_minute
short int scan_start_hour
short int num_z_elements
short int num_r_elements
short int num_dimensions
ECAT7_MatDir * matdir
short int y_dimension
short int z_dimension
short int num_dimensions
short int x_dimension
short int data_type
short int file_type
short int num_frames
char magic_number[14]
short int num_gates
short int num_planes
short int num_r_elements
short int num_angles
short int data_type
short int num_z_elements[64]
MatDir * matdir
int endblk
int matnum
int strtblk
int frame
int plane