TPCCLIB
Loading...
Searching...
No Matches
ecat63ml.c File Reference

Reading and writing ECAT 6.3 matrix list. More...

#include "libtpcimgio.h"

Go to the source code of this file.

Functions

void ecat63InitMatlist (MATRIXLIST *mlist)
void ecat63EmptyMatlist (MATRIXLIST *mlist)
int ecat63ReadMatlist (FILE *fp, MATRIXLIST *ml, int verbose)
void ecat63PrintMatlist (MATRIXLIST *ml)
int ecat63Matenter (FILE *fp, int matnum, int blkNr)
int mat_numcod (int frame, int plane, int gate, int data, int bed)
void mat_numdoc (int matnum, Matval *matval)
void ecat63SortMatlistByPlane (MATRIXLIST *ml)
void ecat63SortMatlistByFrame (MATRIXLIST *ml)
int ecat63CheckMatlist (MATRIXLIST *ml)
int ecat63DeleteLateFrames (MATRIXLIST *ml, int frame_nr)
int ecat63GetMatrixBlockSize (MATRIXLIST *mlist, int *blk_nr)
int ecat63GetPlaneAndFrameNr (MATRIXLIST *mlist, ECAT63_mainheader *h, int *plane_nr, int *frame_nr)
int ecat63GetNums (MATRIXLIST *ml, short int *num_planes, short int *num_frames, short int *num_gates, short int *num_bed_pos)
int ecat63GatherMatlist (MATRIXLIST *ml, short int do_planes, short int do_frames, short int do_gates, short int do_beds)

Detailed Description

Reading and writing ECAT 6.3 matrix list.

Author
Vesa Oikonen

Assumptions:

  1. Assumes that matrix list data is in VAX little endian format
  2. Data is automatically converted to big endian when read, if necessary according to the current platform.

Definition in file ecat63ml.c.

Function Documentation

◆ ecat63CheckMatlist()

int ecat63CheckMatlist ( MATRIXLIST * ml)

Checks that all matrixlist entries have read/write status.

Parameters
mlmatrix list
Returns
0 if ok, or 1 if an entry is marked as deleted or unfinished.

Definition at line 324 of file ecat63ml.c.

326 {
327 if(ml==NULL) return(1);
328 for(int i=0; i<ml->matrixNr; i++) if(ml->matdir[i].matstat!=1) return(1);
329 return(0);
330}
MatDir * matdir
int matstat

Referenced by atnMake(), and ecatFixMatrixlist().

◆ ecat63DeleteLateFrames()

int ecat63DeleteLateFrames ( MATRIXLIST * ml,
int frame_nr )

Mark deleted the frames after the specified frame number.

This can be used to delete sum images from the end of dynamic ECAT images.

Parameters
mlmatrix list.
frame_nrlast index not to be marked as deleted.
Returns
number of deleted matrices.

Definition at line 342 of file ecat63ml.c.

344 {
345 int del_nr=0;
346 Matval matval;
347
348 for(int i=0; i<ml->matrixNr; i++) {
349 mat_numdoc(ml->matdir[i].matnum, &matval);
350 if(matval.frame>frame_nr) {del_nr++; ml->matdir[i].matstat=-1;}
351 }
352 return(del_nr);
353}
void mat_numdoc(int matnum, Matval *matval)
Definition ecat63ml.c:254
int matnum
int frame

Referenced by ecat63ReadAllToImg(), ecat63ReadPlaneToImg(), and imgReadEcat63Header().

◆ ecat63EmptyMatlist()

void ecat63EmptyMatlist ( MATRIXLIST * mlist)

Free memory allocated for ECAT matrix list

Parameters
mlistmatrix list

Definition at line 31 of file ecat63ml.c.

31 {
32 if(mlist->matrixSpace>0) free((char*)(mlist->matdir));
33 mlist->matrixSpace=mlist->matrixNr=0;
34}

Referenced by atnMake(), ecat63AddImg(), ecat63ReadAllToImg(), ecat63ReadMatlist(), ecat63ReadPlaneToImg(), ecat6PrintSubheader(), imgReadEcat63Frame(), and imgReadEcat63Header().

◆ ecat63GatherMatlist()

int ecat63GatherMatlist ( MATRIXLIST * ml,
short int do_planes,
short int do_frames,
short int do_gates,
short int do_beds )

Matrix numbers in ECAT 6.3 matrix list are edited, when necessary, so that plane, frame, gate and/or bed numbers are continuous, starting from one (planes, frames and gates) or from zero (beds). List order is not changed.

Parameters
mlECAT 6.3 matrix list, where the matrix numbers will be edited
do_planesPlane numbers are gathered together (1) or not (0)
do_framesFrame numbers are gathered together (1) or not (0)
do_gatesGate numbers are gathered together (1) or not (0)
do_bedsBed numbers are gathered together (1) or not (0)
Returns
0 if successful, 1 if invalid input, 3 failed to allocate memory

Definition at line 510 of file ecat63ml.c.

513 {
514 int i, ncurr, n;
515 Matval* matval;
516
517 if(ml==NULL) return(1);
518 if(ml->matrixNr<1) return(0);
519
520 /* Allocate memory for matrix values */
521 matval = (Matval*)calloc(ml->matrixNr,sizeof(Matval));
522 if(matval == NULL) return(3);
523
524 /* And get the matrix values */
525 for(i=0; i<ml->matrixNr; i++) mat_numdoc(ml->matdir[i].matnum, matval+i);
526
527 /* Planes */
528 if(do_planes!=0) {
529 ncurr=1;
530 while(ncurr <= ml->matrixNr) {
531 /* Find any matrix with this number? */
532 for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].plane==ncurr) {n=1; break;}
533 /* If yes, then go on to the next matrix number */
534 if(n==1) {ncurr++; continue;}
535 /* If not, then subtract 1 from all matrix numbers that are larger */
536 for(i=0, n=0; i<ml->matrixNr; i++)
537 if(matval[i].plane>ncurr) {
538 matval[i].plane--; n++;
539 }
540 /* If no larger values were found any more, then quit */
541 if(n<1) break;
542 }
543 }
544
545 /* Frames */
546 if(do_frames!=0) {
547 ncurr=1;
548 while(ncurr <= ml->matrixNr) {
549 /* Find any matrix with this number? */
550 for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].frame==ncurr) {n=1; break;}
551 /* If yes, then go on to the next matrix number */
552 if(n==1) {ncurr++; continue;}
553 /* If not, then subtract 1 from all matrix numbers that are larger */
554 for(i=0, n=0; i<ml->matrixNr; i++)
555 if(matval[i].frame>ncurr) {matval[i].frame--; n++;}
556 /* If no larger values were found any more, then quit */
557 if(n<1) break;
558 }
559 }
560
561 /* Gates */
562 if(do_gates!=0) {
563 ncurr=1;
564 while(ncurr <= ml->matrixNr) {
565 /* Find any matrix with this number? */
566 for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].gate==ncurr) {n=1; break;}
567 /* If yes, then go on to the next matrix number */
568 if(n==1) {ncurr++; continue;}
569 /* If not, then subtract 1 from all matrix numbers that are larger */
570 for(i=0, n=0; i<ml->matrixNr; i++)
571 if(matval[i].gate>ncurr) {matval[i].gate--; n++;}
572 /* If no larger values were found any more, then quit */
573 if(n<1) break;
574 }
575 }
576
577 /* Beds */
578 if(do_beds!=0) {
579 ncurr=1;
580 while(ncurr <= ml->matrixNr) {
581 /* Find any matrix with this number? */
582 for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].bed==ncurr) {n=1; break;}
583 /* If yes, then go on to the next matrix number */
584 if(n==1) {ncurr++; continue;}
585 /* If not, then subtract 1 from all matrix numbers that are larger */
586 for(i=0, n=0; i<ml->matrixNr; i++)
587 if(matval[i].bed>ncurr) {matval[i].bed--; n++;}
588 /* If no larger values were found any more, then quit */
589 if(n<1) break;
590 }
591 }
592
593 /* Write matrix values (possibly changed) into matrix list */
594 for(i=0; i<ml->matrixNr; i++) ml->matdir[i].matnum=mat_numcod(
595 matval[i].frame, matval[i].plane,
596 matval[i].gate, matval[i].data,
597 matval[i].bed);
598 free(matval);
599 return(0);
600}
int mat_numcod(int frame, int plane, int gate, int data, int bed)
Definition ecat63ml.c:242
int plane

Referenced by ecatFixMatrixlist(), imgReadEcat63Frame(), and imgReadEcat63Header().

◆ ecat63GetMatrixBlockSize()

int ecat63GetMatrixBlockSize ( MATRIXLIST * mlist,
int * blk_nr )

Calculate the size of one data matrix in ECAT 6.3 file matrix list, and check that the size is same in all matrices.

Parameters
mlistEcat 6.3 matrix list; note that this list is here sorted by planes
blk_nrNumber of blocks will be put here; NULL if not needed
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 366 of file ecat63ml.c.

368 {
369 int m, prev_blk, blk;
370
371 /* Check input */
372 if(mlist==NULL) return STATUS_FAULT;
373 if(blk_nr!=NULL) *blk_nr=0;
374
375 /* Calculate the size of first data matrix */
376 m=0; prev_blk=blk=mlist->matdir[m].endblk - mlist->matdir[m].strtblk;
377 for(m=1; m<mlist->matrixNr; m++) {
378 blk=mlist->matdir[m].endblk - mlist->matdir[m].strtblk;
379 if(blk!=prev_blk) return STATUS_VARMATSIZE;
380 else prev_blk=blk;
381 }
382 if(blk_nr!=NULL) *blk_nr=blk;
383 return STATUS_OK;
384}
int endblk
int strtblk

Referenced by imgReadEcat63Frame(), and imgReadEcat63Header().

◆ ecat63GetNums()

int ecat63GetNums ( MATRIXLIST * ml,
short int * num_planes,
short int * num_frames,
short int * num_gates,
short int * num_bed_pos )

Read the maximum plane, frame, gate and bed number from matrixlist.

Parameters
mlPointer to matrixlist
num_planesnumber of planes will be put here; NULL if not needed
num_framesnumber of frames will be put here; NULL if not needed
num_gatesnumber of gates will be put here; NULL if not needed
num_bed_posnumber of gates will be put here; NULL if not needed
Returns
0 if successful, 1 no matrix list, 2 invalid matrix number, 3 failed to allocate memory

Definition at line 450 of file ecat63ml.c.

453 {
454 int i, nmax;
455 Matval* matval;
456
457 if(ml==NULL) return(1);
458 if(ml->matrixNr<1) return(2);
459
460 /* Allocate memory for matrix values */
461 matval = (Matval*)calloc(ml->matrixNr,sizeof(Matval));
462 if(matval == NULL) return(3);
463
464 /* And get the matrix values */
465 for(i=0; i<ml->matrixNr; i++) mat_numdoc(ml->matdir[i].matnum, matval+i);
466
467 /* Planes */
468 if(num_planes!=NULL) {
469 nmax=matval[0].plane;
470 for(i=1; i<ml->matrixNr; i++) if(matval[i].plane>nmax) nmax=matval[i].plane;
471 *num_planes=nmax;
472 }
473 /* Frames */
474 if(num_frames!=NULL) {
475 nmax=matval[0].frame;
476 for(i=1; i<ml->matrixNr; i++) if(matval[i].frame>nmax) nmax=matval[i].frame;
477 *num_frames=nmax;
478 }
479 /* Gates */
480 if(num_gates!=NULL) {
481 nmax=matval[0].gate;
482 for(i=1; i<ml->matrixNr; i++) if(matval[i].gate>nmax) nmax=matval[i].gate;
483 *num_gates=nmax;
484 }
485 /* Beds */
486 if(num_bed_pos!=NULL) {
487 nmax=matval[0].bed;
488 for(i=1; i<ml->matrixNr; i++) if(matval[i].bed>nmax) nmax=matval[i].bed;
489 *num_bed_pos=nmax;
490 }
491 free(matval);
492 return(0);
493}

Referenced by ecatFixMatrixlist().

◆ ecat63GetPlaneAndFrameNr()

int ecat63GetPlaneAndFrameNr ( MATRIXLIST * mlist,
ECAT63_mainheader * h,
int * plane_nr,
int * frame_nr )

Calculate the number of planes and frames/gates from ECAT 6.3 matrix list. Check that all planes have equal nr of frames/gates, that frames/gates are sequentially numbered. This routines sorts the matrix list by planes.

Parameters
mlistEcat 6.3 matrix list; note that this list is here sorted by planes
hEcat 6.3 mainheader
plane_nrNumber of planes will be put here; NULL if not needed
frame_nrNumber of frames/gates will be put here; NULL if not needed
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 400 of file ecat63ml.c.

402 {
403 Matval matval;
404 int m, plane, frame, prev_plane, prev_frame, fnr, pnr;
405
406 /* Check input */
407 if(mlist==NULL) return STATUS_FAULT;
408 if(plane_nr!=NULL) *plane_nr=0;
409 if(frame_nr!=NULL) *frame_nr=0;
410
411 /* Sort matrices by plane so that following computation works */
413
414 prev_plane=plane=-1; prev_frame=frame=-1;
415 fnr=pnr=0;
416 for(m=0; m<mlist->matrixNr; m++) if(mlist->matdir[m].matstat==1) {
417 mat_numdoc(mlist->matdir[m].matnum, &matval);
418 plane=matval.plane;
419 if(h->num_frames>=h->num_gates)
420 frame=matval.frame;
421 else
422 frame=matval.gate;
423 if(plane!=prev_plane) {
424 fnr=1; pnr++;
425 } else {
426 fnr++;
427 if(prev_frame>0 && frame!=prev_frame+1) return STATUS_MISSINGMATRIX;
428 }
429 prev_plane=plane; prev_frame=frame;
430 } /* next matrix */
431 if(fnr*pnr != mlist->matrixNr) return STATUS_MISSINGMATRIX;
432 if(plane_nr!=NULL) *plane_nr=pnr;
433 if(frame_nr!=NULL) *frame_nr=fnr;
434 return STATUS_OK;
435}
void ecat63SortMatlistByPlane(MATRIXLIST *ml)
Definition ecat63ml.c:271

Referenced by imgReadEcat63Header().

◆ ecat63InitMatlist()

void ecat63InitMatlist ( MATRIXLIST * mlist)

Initiate ECAT matrix list. Call this once before first use.

Parameters
mlistmatrix list

Definition at line 20 of file ecat63ml.c.

20 {
21 mlist->matrixSpace=mlist->matrixNr=0; mlist->matdir=NULL;
22}

Referenced by atnMake(), ecat63AddImg(), ecat63ReadAllToImg(), ecat63ReadPlaneToImg(), ecat6PrintSubheader(), ecatFixMatrixlist(), imgReadEcat63Frame(), and imgReadEcat63Header().

◆ ecat63Matenter()

int ecat63Matenter ( FILE * fp,
int matnum,
int blkNr )

Prepare matrix list for additional matrix data and Directory records are written in big endian byte order. Set block_nr to the number of data blocks excluding header;

Parameters
fpfile pointer
matnummatrix number [1..number of matrices]
blkNrmatrix block number [ >= 1]
Returns
block number for matrix header, or 0 in case of an error.

Definition at line 159 of file ecat63ml.c.

161 {
162 unsigned int i=0, dirblk, little, busy=1, nxtblk=0, oldsize;
163 unsigned int dirbuf[MatBLKSIZE/4];
164
165 if(ECAT63_TEST) printf("ecat63Matenter(fp, %d, %d)\n", matnum, blkNr);
166 if(fp==NULL || matnum<1 || blkNr<1) return(0);
167 little=little_endian(); memset(dirbuf, 0, MatBLKSIZE);
168 /* Read first matrix list block */
169 dirblk=MatFirstDirBlk;
170 fseeko(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
171 if(ftello(fp)!=(int)(dirblk-1)*MatBLKSIZE) return(0);
172 if(fread(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(0);
173 /* Byte order conversion for ints in big endian platforms */
174 if(!little) swawbip(dirbuf, MatBLKSIZE);
175
176 while(busy) {
177 nxtblk=dirblk+1;
178 for(i=4; i<MatBLKSIZE/4; i+=4) {
179 if(dirbuf[i]==0) { /* Check for end of matrix list */
180 busy=0; break;
181 } else if(dirbuf[i]==(unsigned int)matnum) { /* Check if this matrix already exists */
182 oldsize=dirbuf[i+2]-dirbuf[i+1]+1;
183 if(oldsize<(unsigned int)blkNr) { /* If old matrix is smaller */
184 dirbuf[i] = 0xFFFFFFFF;
185 if(!little) swawbip(dirbuf, MatBLKSIZE);
186 fseeko(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
187 if(ftello(fp)!=(int)(dirblk-1)*MatBLKSIZE) return(0);
188 if(fwrite(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(0);
189 if(!little) swawbip(dirbuf, MatBLKSIZE);
190 nxtblk=dirbuf[i+2]+1;
191 } else { /* old matrix size is ok */
192 nxtblk=dirbuf[i+1]; dirbuf[0]++; dirbuf[3]--; busy=0;
193 break;
194 }
195 } else /* not this one */
196 nxtblk=dirbuf[i+2]+1;
197 }
198 if(!busy) break;
199 if(dirbuf[1]!=MatFirstDirBlk) {
200 dirblk=dirbuf[1];
201 fseeko(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
202 if(ftello(fp)!=(int)(dirblk-1)*MatBLKSIZE) return(0);
203 if(fread(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(0);
204 if(!little) swawbip(dirbuf, MatBLKSIZE);
205 } else {
206 dirbuf[1]=nxtblk;
207 if(!little) swawbip(dirbuf, MatBLKSIZE);
208 fseeko(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
209 if(ftello(fp)!=(int)(dirblk-1)*MatBLKSIZE) return(0);
210 if(fwrite(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(0);
211 dirbuf[0]=31; dirbuf[1]=MatFirstDirBlk; dirbuf[2]=dirblk;
212 dirbuf[3]=0; dirblk=nxtblk;
213 for(i=4; i<MatBLKSIZE/4; i++) dirbuf[i]=0;
214 }
215 }
216 dirbuf[i]=matnum;
217 dirbuf[i+1]=nxtblk;
218 dirbuf[i+2]=nxtblk+blkNr;
219 dirbuf[i+3]=1;
220 dirbuf[0]--;
221 dirbuf[3]++;
222 if(!little) swawbip(dirbuf, MatBLKSIZE);
223 fseeko(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
224 if(ftello(fp)!=(int)(dirblk-1)*MatBLKSIZE) return(0);
225 if(fwrite(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(0);
226 if(ECAT63_TEST) printf("returning %d from ecat63Matenter()\n", nxtblk);
227 return(nxtblk);
228}
int ECAT63_TEST
Definition ecat63h.c:6
#define MatFirstDirBlk
#define MatBLKSIZE
void swawbip(void *buf, long long int size)
Definition swap.c:93
int little_endian()
Definition swap.c:14

Referenced by ecat63CopyFile(), ecat63WriteAttn(), ecat63WriteImage(), ecat63WriteImageMatrix(), ecat63WriteNorm(), ecat63WriteScan(), and ecat63WriteScanMatrix().

◆ ecat63PrintMatlist()

void ecat63PrintMatlist ( MATRIXLIST * ml)

Print ECAT matrix list on stdout.

Parameters
mlPointer to matrix list to print.

Definition at line 130 of file ecat63ml.c.

133 {
134 int i;
135 Matval matval;
136
137 printf("nr\tmatrix\tpl\tfr\tgate\tbed\tstartblk\tblknr\n");
138 for(i=0; i<ml->matrixNr; i++) {
139 mat_numdoc(ml->matdir[i].matnum, &matval);
140 printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i+1, ml->matdir[i].matnum,
141 matval.plane, matval.frame, matval.gate, matval.bed,
142 ml->matdir[i].strtblk, 1+ml->matdir[i].endblk-ml->matdir[i].strtblk);
143 }
144 return;
145}

Referenced by ecat63ReadAllToImg(), ecat6PrintSubheader(), and ecatFixMatrixlist().

◆ ecat63ReadMatlist()

int ecat63ReadMatlist ( FILE * fp,
MATRIXLIST * ml,
int verbose )

Read ECAT 6.3 matrix list.

Matrix list must be initiated (once) before calling this.

Returns
Returns 0 if ok, 1 if invalid input, 2 first matrix is not found, 3 if failed to read matrix, 4 failed to allocate memory, 5 other error.
Parameters
fpFile pointer.
mlPointer to initiated matrix list.
verboseVerbose level; if zero, then nothing is printed to stderr or stdout

Definition at line 46 of file ecat63ml.c.

53 {
54 int i, err=0, little;
55 int blk=MatFirstDirBlk, next_blk=0;
56 size_t sn;
57 unsigned int dirbuf[MatBLKSIZE/4];
58
59
60 if(verbose>0) {printf("ecat63ReadMatlist(fp, mlist)\n"); fflush(stdout);}
61 if(fp==NULL) return(1);
62 little=little_endian();
63 /* Make sure that matrix list is empty */
65 /* Seek the first list block */
66 fseek(fp, (blk-1)*MatBLKSIZE, SEEK_SET); if(ftell(fp)!=(blk-1)*MatBLKSIZE) return(2);
67 do {
68 /* Read the data block */
69 if(verbose>1) {printf(" reading dirblock %d\n", blk); fflush(stdout);}
70 sn=fread(dirbuf, sizeof(int), MatBLKSIZE/4, fp);
71 if(sn==0) { /* this never happens in valid ECAT file, but it does happen... */
72 if(verbose>0) {printf("sn=%d\n", (int)sn); fflush(stdout);}
73 //ml->matrixNr--;
74 break;
75 }
76 if(sn<MatBLKSIZE/4) { /* this would be a real error in file */
77 if(verbose>0) {printf("sn=%d\n", (int)sn); fflush(stdout);}
78 err=2; break;
79 }
80 /* Allocate (more) memory for one block */
81 if(ml->matrixSpace==0) {
83 ml->matdir=(MatDir*)malloc(ml->matrixSpace*sizeof(MatDir));
84 } else if(ml->matrixSpace<(ml->matrixNr+MatBLKSIZE/4)) {
86 ml->matdir=(MatDir*)realloc(ml->matdir, sizeof(MatDir)*ml->matrixSpace);
87 }
88 if(ml->matdir==NULL) return(4);
89 /* Byte order conversion for ints in big endian platforms */
90 if(!little) swawbip(dirbuf, MatBLKSIZE);
91 /* Read "header" integers */
92 /*nr_free = dirbuf[0];*/
93 next_blk = dirbuf[1];
94 /*prev_blk = dirbuf[2];*/
95 /*nr_used = dirbuf[3];*/
96 if(verbose>3) printf("next_blk=%d\n", next_blk);
97 fpos_t current_fp; fgetpos(fp, &current_fp); // save current file position
98 for(i=4; i<MatBLKSIZE/4; i+=4) if(dirbuf[i]>0) {
99 ml->matdir[ml->matrixNr].matnum=dirbuf[i];
100 ml->matdir[ml->matrixNr].strtblk=dirbuf[i+1];
101 ml->matdir[ml->matrixNr].endblk=dirbuf[i+2];
102 ml->matdir[ml->matrixNr].matstat=dirbuf[i+3];
103 if(verbose>4) printf("matnum=%d strtblk=%d endblk=%d matstat=%d matrixNr=%d\n",
104 ml->matdir[ml->matrixNr].matnum, ml->matdir[ml->matrixNr].strtblk,
105 ml->matdir[ml->matrixNr].endblk, ml->matdir[ml->matrixNr].matstat,
106 ml->matrixNr);
107 /* verify that these block can be found in the file */
108 int ret=fseek(fp, (ml->matdir[ml->matrixNr].endblk-1)*MatBLKSIZE, SEEK_SET);
109 fsetpos(fp, &current_fp); // back to saved file position
110 if(ret==0) { // end block can be found
111 ml->matrixNr++;
112 } else { // not found, file probably broken
113 if(verbose>0) {
114 printf("matnum %d points to data outside of file.\n", ml->matdir[ml->matrixNr].matnum);
115 fflush(stdout);
116 }
117 }
118 }
119 blk=next_blk;
120 /* Seek the next list block */
121 fseeko(fp, (blk-1)*MatBLKSIZE, SEEK_SET); if(ftello(fp)!=(blk-1)*MatBLKSIZE) err=1;
122 } while(err==0 && feof(fp)==0 && blk!=MatFirstDirBlk);
123 if(err) {ecat63EmptyMatlist(ml); return(5);}
124 return(0);
125}
void ecat63EmptyMatlist(MATRIXLIST *mlist)
Definition ecat63ml.c:31

Referenced by atnMake(), ecat63AddImg(), ecat63ReadAllToImg(), ecat63ReadPlaneToImg(), ecat6PrintSubheader(), ecatFixMatrixlist(), imgReadEcat63Frame(), and imgReadEcat63Header().

◆ ecat63SortMatlistByFrame()

void ecat63SortMatlistByFrame ( MATRIXLIST * ml)

Sort matrixlist by frame and plane. Bubble sorting algorithm.

Parameters
mlmatrix list

Definition at line 297 of file ecat63ml.c.

299 {
300 Matval mv1, mv2;
301 MatDir tmpMatdir;
302
303 for(int i=0; i<ml->matrixNr-1; i++) {
304 mat_numdoc(ml->matdir[i].matnum, &mv1);
305 for(int j=i+1; j<ml->matrixNr; j++) {
306 mat_numdoc(ml->matdir[j].matnum, &mv2);
307 if(mv2.frame<mv1.frame||(mv2.frame==mv1.frame&&mv2.plane<mv1.plane)) {
308 tmpMatdir=ml->matdir[i];
309 ml->matdir[i]=ml->matdir[j]; ml->matdir[j]=tmpMatdir;
310 mat_numdoc(ml->matdir[i].matnum, &mv1);
311 }
312 }
313 }
314}

Referenced by imgReadEcat63Frame().

◆ ecat63SortMatlistByPlane()

void ecat63SortMatlistByPlane ( MATRIXLIST * ml)

Sort matrixlist by plane and frame. Bubble sorting algorithm.

Parameters
mlmarix list.

Definition at line 271 of file ecat63ml.c.

273 {
274 Matval mv1, mv2;
275 MatDir tmpMatdir;
276
277 for(int i=0; i<ml->matrixNr-1; i++) {
278 mat_numdoc(ml->matdir[i].matnum, &mv1);
279 for(int j=i+1; j<ml->matrixNr; j++) {
280 mat_numdoc(ml->matdir[j].matnum, &mv2);
281 if(mv2.plane<mv1.plane||(mv2.plane==mv1.plane&&mv2.frame<mv1.frame)) {
282 tmpMatdir=ml->matdir[i];
283 ml->matdir[i]=ml->matdir[j]; ml->matdir[j]=tmpMatdir;
284 mat_numdoc(ml->matdir[i].matnum, &mv1);
285 }
286 }
287 }
288}

Referenced by ecat63GetPlaneAndFrameNr(), and imgReadEcat63Header().

◆ mat_numcod()

int mat_numcod ( int frame,
int plane,
int gate,
int data,
int bed )

Returns the matrix identifier

Parameters
frameframe number [0..4096]
planeplane number [0..256]
gategate number [0..64]
datadata number [0..8]
bedbed position [0..16]
Returns
matrix identifier coding

Definition at line 242 of file ecat63ml.c.

244 {
245 return((frame&0xFFF)|((bed&0xF)<<12)|((plane&0xFF)<<16)|
246 ((gate&0x3F)<<24)|((data&0x3)<<30));
247}

Referenced by atnMake(), ecat63AddImg(), ecat63GatherMatlist(), ecat63WriteAllImg(), and imgWriteEcat63Frame().

◆ mat_numdoc()

void mat_numdoc ( int matnum,
Matval * matval )

Conversion of matrix identifier to numerical values

Parameters
matnummatrix identifier coding
matvaltarget matrix value structure

Definition at line 254 of file ecat63ml.c.

256 {
257 matval->frame = matnum&0xFFF;
258 matval->plane = (matnum>>16)&0xFF;
259 matval->gate = (matnum>>24)&0x3F;
260 matval->data = (matnum>>30)&0x3;
261 matval->bed = (matnum>>12)&0xF;
262}

Referenced by atnMake(), ecat63AddImg(), ecat63DeleteLateFrames(), ecat63GatherMatlist(), ecat63GetNums(), ecat63GetPlaneAndFrameNr(), ecat63PrintMatlist(), ecat63ReadAllToImg(), ecat63ReadPlaneToImg(), ecat63SortMatlistByFrame(), ecat63SortMatlistByPlane(), ecat6PrintSubheader(), imgReadEcat63Frame(), roi_mframe(), and roi_mplane().