ecat7ml.c
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Copyright (c) 2003-2007 Turku PET Centre
4 
5  Library: ecat7ml.c
6  Description: Reading and writing ECAT 7.x matrix list.
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  See the GNU Lesser General Public License for more details:
17  http://www.gnu.org/copyleft/lesser.html
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with this library/program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi/
24 
25  Modification history:
26  2003-07-21 Vesa Oikonen
27  First created.
28  2004-06-20 VO
29  ecat7PrintMatlist(): blkNr is printed correctly (+1).
30  2004-06-27 VO
31  Included ecat7DeleteLateFrames().
32  2007-02-27 VO
33  Added functions ecat7GetMatrixBlockSize() and ecat7GetPlaneAndFrameNr().
34  2007-03-13 VO
35  Added functions ecat7GetNums() and ecat7GatherMatlist().
36  2007-17-07 Harri Merisaari
37  fixed for ANSI
38 
39 ******************************************************************************/
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <math.h>
43 #include <ctype.h>
44 #include <string.h>
45 #include <unistd.h>
46 #include <time.h>
47 /*****************************************************************************/
48 #include <swap.h>
49 #include "include/img.h"
50 #include "include/ecat7.h"
51 /*****************************************************************************/
52 
53 /*****************************************************************************/
60  mlist->matrixSpace=mlist->matrixNr=0; mlist->matdir=NULL;
61 }
62 /*****************************************************************************/
63 
64 /*****************************************************************************/
71  if(mlist->matrixSpace>0) free((char*)(mlist->matdir));
72  mlist->matrixSpace=mlist->matrixNr=0;
73 }
74 /*****************************************************************************/
75 
76 /*****************************************************************************/
86 int ecat7ReadMatlist(FILE *fp, ECAT7_MATRIXLIST *ml) {
87  int i, err=0, little;
88  int blk=MatFirstDirBlk, next_blk=0, nr_free, prev_blk, nr_used;
89  size_t sn;
90  unsigned int dirbuf[MatBLKSIZE/4];
91 
92 
93  if(ECAT7_TEST) printf("ecat7ReadMatlist(fp, mlist)\n");
94  if(fp==NULL) return(1);
95  little=little_endian();
96  /* Make sure that matrix list is empty */
98  /* Seek the first list block */
99  fseek(fp, (blk-1)*MatBLKSIZE, SEEK_SET); if(ftell(fp)!=(blk-1)*MatBLKSIZE) return(2);
100  do {
101  /* Read the data block */
102  if(ECAT7_TEST) printf(" reading dirblock %d\n", blk);
103  sn=fread(dirbuf, sizeof(int), MatBLKSIZE/4, fp); if(sn<MatBLKSIZE/4) return(3);
104  /* Allocate (more) memory for one block */
105  if(ml->matrixSpace==0) {
106  ml->matrixSpace=MatBLKSIZE/4;
107  ml->matdir=(ECAT7_MatDir*)malloc(ml->matrixSpace*sizeof(ECAT7_MatDir));
108  } else if(ml->matrixSpace<(ml->matrixNr+MatBLKSIZE/4)) {
109  ml->matrixSpace+=MatBLKSIZE/4;
110  ml->matdir=(ECAT7_MatDir*)realloc(ml->matdir, sizeof(ECAT7_MatDir)*ml->matrixSpace);
111  }
112  if(ml->matdir==NULL) return(4);
113  /* Byte order conversion for ints in little endian platforms */
114  if(little) swawbip(dirbuf, MatBLKSIZE);
115  /* Read "header" integers */
116  nr_free = dirbuf[0];
117  next_blk = dirbuf[1];
118  prev_blk = dirbuf[2];
119  nr_used = dirbuf[3];
120  if(ECAT7_TEST>1) printf("nr_free=%d next_blk=%d prev_blk=%d nr_used=%d\n", nr_free, next_blk, prev_blk, nr_used);
121  for(i=4; i<MatBLKSIZE/4; i+=4) if(dirbuf[i]>0) {
122  ml->matdir[ml->matrixNr].id=dirbuf[i];
123  ml->matdir[ml->matrixNr].strtblk=dirbuf[i+1];
124  ml->matdir[ml->matrixNr].endblk=dirbuf[i+2];
125  ml->matdir[ml->matrixNr].status=dirbuf[i+3];
126  if(ECAT7_TEST>3) {
127  printf("matnum=%d strtblk=%d endblk=%d matstat=%d matrixNr=%d\n",
128  ml->matdir[ml->matrixNr].id, ml->matdir[ml->matrixNr].strtblk,
129  ml->matdir[ml->matrixNr].endblk, ml->matdir[ml->matrixNr].status,
130  ml->matrixNr);
131  }
132  ml->matrixNr++;
133  }
134  blk=next_blk;
135  /* Seek the next list block */
136  fseek(fp, (blk-1)*MatBLKSIZE, SEEK_SET); if(ftell(fp)!=(blk-1)*MatBLKSIZE) err=1;
137  } while(err==0 && feof(fp)==0 && blk!=MatFirstDirBlk);
138  if(err) {ecat7EmptyMatlist(ml); return(5);}
139  return(0);
140 }
141 /*****************************************************************************/
142 
143 /*****************************************************************************/
150  int i;
151  ECAT7_Matval matval;
152 
153  printf(" matrix pl fr gate bed startblk blknr status\n");
154  for(i=0; i<ml->matrixNr; i++) {
155  ecat7_id_to_val(ml->matdir[i].id, &matval);
156  printf("%4d %8d %3d %3d %3d %3d %8d %5d ", i+1, ml->matdir[i].id,
157  matval.plane, matval.frame, matval.gate, matval.bed,
158  ml->matdir[i].strtblk, 1+ml->matdir[i].endblk-ml->matdir[i].strtblk);
159  if(ml->matdir[i].status==1) printf("read/write\n");
160  else if(ml->matdir[i].status==0) printf("not ready\n");
161  else if(ml->matdir[i].status==-1) printf("deleted\n");
162  else printf("%d\n", ml->matdir[i].status);
163  }
164  return;
165 }
166 /*****************************************************************************/
167 
168 /*****************************************************************************/
184 int ecat7EnterMatrix(FILE *fp, int matrix_id, int block_nr) {
185  unsigned int i=0, dirblk, little, busy=1, nxtblk=0, oldsize;
186  /*unsigned*/ int dirbuf[MatBLKSIZE/4];
187 
188  if(ECAT7_TEST) printf("ecat7EnterMatrix(fp, %d, %d)\n", matrix_id, block_nr);
189  /* Check the input */
190  if(fp==NULL || matrix_id<1 || block_nr<1) return(-1);
191  /* Is this a little endian machine? */
192  little=little_endian();
193  /* Read first directory record block */
194  dirblk=MatFirstDirBlk;
195  fseek(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
196  if(ftell(fp)!=(dirblk-1)*MatBLKSIZE) return(-2);
197  if(fread(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(-3);
198  /* Byte order conversion for ints in little endian platforms */
199  if(little) swawbip(dirbuf, MatBLKSIZE);
200  /* Read through the existing directory records */
201  while(busy) {
202  /* Go through the directory entries in this record */
203  for(i=4, nxtblk=dirblk+1; i<MatBLKSIZE/4; i+=4) {
204  oldsize=dirbuf[i+2]-dirbuf[i+1]+1;
205  if(dirbuf[i]==0) { /* Check for end of matrix list */
206  busy=0; break;
207  } else if(dirbuf[i]==matrix_id) { /* Maybe this matrix already exists? */
208  /* yes it does; is old data smaller? */
209  if(oldsize<block_nr) {
210  /* it was smaller, so do not use it, but mark it deleted */
211  dirbuf[i] = 0xFFFFFFFF; dirbuf[i+3]=-1;
212  if(little) swawbip(dirbuf, MatBLKSIZE);
213  fseek(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
214  if(ftell(fp)!=(dirblk-1)*MatBLKSIZE) return(-6);
215  if(fwrite(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(-7);
216  if(little) swawbip(dirbuf, MatBLKSIZE);
217  nxtblk=dirbuf[i+2]+1;
218  } else { /* old matrix size is ok */
219  nxtblk=dirbuf[i+1]; dirbuf[0]++; dirbuf[3]--; busy=0;
220  break;
221  }
222  } else { /* this is not the same matrix */
223  /* But is deleted and of same or smaller size? */
224  if(dirbuf[i+3]==-1 && block_nr<=oldsize) {
225  /* yes it was, so lets recycle it */
226  dirbuf[i]=matrix_id;
227  nxtblk=dirbuf[i+1]; dirbuf[0]++; dirbuf[3]--; busy=0;
228  break;
229  }
230  /* nothing to be done with this entry */
231  nxtblk=dirbuf[i+2]+1;
232  }
233  } /* next entry in this record */
234  if(!busy) break; /* stop reading existing records */
235  /* Read the next directory record */
236  if(dirbuf[1]!=MatFirstDirBlk) {
237  /* There are more records left to read */
238  dirblk=dirbuf[1];
239  fseek(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
240  if(ftell(fp)!=(dirblk-1)*MatBLKSIZE) return(-9);
241  if(fread(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(-10);
242  if(little) swawbip(dirbuf, MatBLKSIZE);
243  } else {
244  /* No more records to read, so lets write a new empty one */
245  dirbuf[1]=nxtblk; /* write a pointer to the new one */
246  if(little) swawbip(dirbuf, MatBLKSIZE);
247  fseek(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
248  if(ftell(fp)!=(dirblk-1)*MatBLKSIZE) return(-11);
249  if(fwrite(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(-12);
250  /* and then initiate the contents of the next one, but do not write it */
251  dirbuf[0]=31; dirbuf[1]=MatFirstDirBlk; dirbuf[2]=dirblk;
252  dirbuf[3]=0; dirblk=nxtblk;
253  for(i=4; i<MatBLKSIZE/4; i++) dirbuf[i]=0;
254  }
255  } /* next directory record */
256  dirbuf[i]=matrix_id;
257  dirbuf[i+1]=nxtblk;
258  dirbuf[i+2]=nxtblk+block_nr;
259  dirbuf[i+3]=1; /* mark the entry as read/write */
260  dirbuf[0]--;
261  dirbuf[3]++;
262  if(little) swawbip(dirbuf, MatBLKSIZE);
263  fseek(fp, (dirblk-1)*MatBLKSIZE, SEEK_SET);
264  if(ftell(fp)!=(dirblk-1)*MatBLKSIZE) return(-15);
265  if(fwrite(dirbuf, sizeof(int), MatBLKSIZE/4, fp) != MatBLKSIZE/4) return(-16);
266  if(ECAT7_TEST) printf("returning %d from ecat7EnterMatrix()\n", nxtblk);
267  return(nxtblk);
268 }
269 /*****************************************************************************/
270 
271 /*****************************************************************************/
282 int ecat7_val_to_id(int frame, int plane, int gate, int data, int bed) {
283  return(
284  ((bed & 0xF) << 12) | /* bed */
285  (frame & 0x1FF) | /* frame */
286  ((gate & 0x3F) << 24) | /* gate */
287  ((plane & 0xFF) << 16) | /* plane low */
288  ((plane & 0x300) << 1) | /* plane high */
289  ((data & 0x3) << 30) | /* data low */
290  ((data & 0x4) << 9) /* data high */
291  );
292 }
299 void ecat7_id_to_val(int matrix_id, ECAT7_Matval *matval) {
300  matval->frame = matrix_id & 0x1FF;
301  matval->plane = ((matrix_id >> 16) & 0xFF) + ((matrix_id >> 1) & 0x300);
302  matval->gate = (matrix_id >> 24) & 0x3F;
303  matval->data = ((matrix_id >> 30) & 0x3) + ((matrix_id >> 9) & 0x4);
304  matval->bed = (matrix_id >> 12) & 0xF;
305 }
306 /*****************************************************************************/
307 
308 /*****************************************************************************/
315  int i, j;
316  ECAT7_Matval mv1, mv2;
317  ECAT7_MatDir tmpMatdir;
318 
319  for(i=0; i<ml->matrixNr-1; i++) {
320  ecat7_id_to_val(ml->matdir[i].id, &mv1);
321  for(j=i+1; j<ml->matrixNr; j++) {
322  ecat7_id_to_val(ml->matdir[j].id, &mv2);
323  if(mv2.plane<mv1.plane||(mv2.plane==mv1.plane&&mv2.frame<mv1.frame)) {
324  tmpMatdir=ml->matdir[i];
325  ml->matdir[i]=ml->matdir[j];
326  ml->matdir[j]=tmpMatdir;
327  ecat7_id_to_val(ml->matdir[i].id, &mv1);
328  }
329  }
330  }
331 }
332 /*****************************************************************************/
333 
334 /*****************************************************************************/
341  int i, j;
342  ECAT7_Matval mv1, mv2;
343  ECAT7_MatDir tmpMatdir;
344 
345  for(i=0; i<ml->matrixNr-1; i++) {
346  ecat7_id_to_val(ml->matdir[i].id, &mv1);
347  for(j=i+1; j<ml->matrixNr; j++) {
348  ecat7_id_to_val(ml->matdir[j].id, &mv2);
349  if(mv2.frame<mv1.frame||(mv2.frame==mv1.frame&&mv2.plane<mv1.plane)) {
350  tmpMatdir=ml->matdir[i];
351  ml->matdir[i]=ml->matdir[j]; ml->matdir[j]=tmpMatdir;
352  ecat7_id_to_val(ml->matdir[i].id, &mv1);
353  }
354  }
355  }
356 }
357 /*****************************************************************************/
358 
359 /*****************************************************************************/
367  int i;
368 
369  if(ml==NULL) return(1);
370  for(i=0; i<ml->matrixNr; i++) if(ml->matdir[i].status!=1) return(1);
371  return(0);
372 }
373 /*****************************************************************************/
374 
375 /*****************************************************************************/
383 int ecat7DeleteLateFrames(ECAT7_MATRIXLIST *ml, int frame_nr) {
384  int i, del_nr=0;
385  ECAT7_Matval matval;
386 
387  for(i=0; i<ml->matrixNr; i++) {
388  ecat7_id_to_val(ml->matdir[i].id, &matval);
389  if(matval.frame>frame_nr) {del_nr++; ml->matdir[i].status=-1;}
390  }
391  return(del_nr);
392 }
393 /*****************************************************************************/
394 
395 /*****************************************************************************/
409 int ecat7GetPlaneAndFrameNr(ECAT7_MATRIXLIST *mlist, ECAT7_mainheader *h, int *plane_nr, int *frame_nr) {
410  ECAT7_Matval matval;
411  int m, plane, frame, prev_plane, prev_frame, fnr, pnr;
412 
413  /* Check input */
414  if(mlist==NULL) return STATUS_FAULT;
415  if(plane_nr!=NULL) *plane_nr=0;
416  if(frame_nr!=NULL) *frame_nr=0;
417 
418  /* Sort matrices by plane so that following computation works */
420 
421  prev_plane=plane=-1; prev_frame=frame=-1;
422  fnr=pnr=0;
423  for(m=0; m<mlist->matrixNr; m++) {
424  ecat7_id_to_val(mlist->matdir[m].id, &matval);
425  plane=matval.plane;
426  if(h->num_frames>=h->num_gates)
427  frame=matval.frame;
428  else
429  frame=matval.gate;
430  if(plane!=prev_plane) {
431  fnr=1; pnr++;
432  } else {
433  fnr++;
434  if(prev_frame>0 && frame!=prev_frame+1) return STATUS_MISSINGMATRIX;
435  }
436  prev_plane=plane; prev_frame=frame;
437  } /* next matrix */
438  if(fnr*pnr != mlist->matrixNr) return STATUS_MISSINGMATRIX;
439  if(plane_nr!=NULL) *plane_nr=pnr;
440  if(frame_nr!=NULL) *frame_nr=fnr;
441  return STATUS_OK;
442 }
443 /*****************************************************************************/
444 
445 /*****************************************************************************/
455 int ecat7GetMatrixBlockSize(ECAT7_MATRIXLIST *mlist, int *blk_nr) {
456  int m, prev_blk, blk;
457 
458  /* Check input */
459  if(mlist==NULL) return STATUS_FAULT;
460  if(blk_nr!=NULL) *blk_nr=0;
461 
462  /* Calculate the size of first data matrix */
463  m=0; prev_blk=blk=mlist->matdir[m].endblk - mlist->matdir[m].strtblk;
464  for(m=1; m<mlist->matrixNr; m++) {
465  blk=mlist->matdir[m].endblk - mlist->matdir[m].strtblk;
466  if(blk!=prev_blk) return STATUS_VARMATSIZE;
467  else prev_blk=blk;
468  }
469  if(blk_nr!=NULL) *blk_nr=blk;
470  return STATUS_OK;
471 }
472 /*****************************************************************************/
473 
474 /*****************************************************************************/
489 int ecat7GetNums(ECAT7_MATRIXLIST *ml, ECAT7_mainheader *mh, FILE *fp, short int *num_planes,
490  short int *num_frames, short int *num_gates, short int *num_bed_pos) {
491  int i, nmax, ret=0;
493  ECAT7_scanheader sh;
494  ECAT7_Matval* matval;
495 
496  if(ml==NULL) return(1);
497  if(ml->matrixNr<1) return(2);
498 
499  /* Allocate memory for matrix values */
500  matval = (ECAT7_Matval*)calloc(ml->matrixNr,sizeof(ECAT7_Matval));
501  if(matval == NULL) return(3);
502 
503  /* And get the matrix values */
504  for(i=0; i<ml->matrixNr; i++) ecat7_id_to_val(ml->matdir[i].id, matval+i);
505 
506  /* Planes */
507  if(num_planes!=NULL) {
508  nmax=matval[0].plane;
509  for(i=1; i<ml->matrixNr; i++) if(matval[i].plane>nmax) nmax=matval[i].plane;
510  *num_planes=nmax;
511  }
512  /* Frames */
513  if(num_frames!=NULL) {
514  nmax=matval[0].frame;
515  for(i=1; i<ml->matrixNr; i++) if(matval[i].frame>nmax) nmax=matval[i].frame;
516  *num_frames=nmax;
517  }
518  /* Gates */
519  if(num_gates!=NULL) {
520  nmax=matval[0].gate;
521  for(i=1; i<ml->matrixNr; i++) if(matval[i].gate>nmax) nmax=matval[i].gate;
522  *num_gates=nmax;
523  }
524  /* Beds */
525  if(num_bed_pos!=NULL) {
526  nmax=matval[0].bed;
527  for(i=1; i<ml->matrixNr; i++) if(matval[i].bed>nmax) nmax=matval[i].bed;
528  *num_bed_pos=nmax;
529  }
530 
531  /* Check the num_planes from the first subheader in 3D formats */
532  if(num_planes!=NULL && *num_planes<=1) switch(mh->file_type) {
533  case ECAT7_VOLUME8:
534  case ECAT7_VOLUME16:
535  ret=ecat7ReadImageheader(fp, ml->matdir[0].strtblk, &ih);
536  if(ret!=0) {
537  free(matval);
538  return(5);
539  }
540  if(ih.num_dimensions>2 && ih.z_dimension>1) *num_planes=ih.z_dimension;
541  break;
542  case ECAT7_3DSCAN:
543  case ECAT7_3DSCAN8:
544  case ECAT7_3DSCANFIT:
545  ret=ecat7ReadScanheader(fp, ml->matdir[0].strtblk, &sh);
546  if(ret!=0) {
547  free(matval);
548  return(5);
549  }
550  for(i=0, *num_planes=0; i<64; i++) *num_planes+=sh.num_z_elements[i];
551  break;
552  }
553  free(matval);
554  return(0);
555 }
556 /*****************************************************************************/
557 
558 /*****************************************************************************/
572 int ecat7GatherMatlist(ECAT7_MATRIXLIST *ml, short int do_planes, short int do_frames,
573  short int do_gates, short int do_beds) {
574  int i, ncurr, n;
575  ECAT7_Matval* matval;
576 
577  if(ml==NULL) return(1);
578  if(ml->matrixNr<1) return(0);
579 
580  /* Allocate memory for matrix values */
581  matval = (ECAT7_Matval*)calloc(ml->matrixNr,sizeof(ECAT7_Matval));
582  if(matval == NULL) return(3);
583 
584  /* And get the matrix values */
585  for(i=0; i<ml->matrixNr; i++) ecat7_id_to_val(ml->matdir[i].id, matval+i);
586 
587  /* Planes */
588  if(do_planes!=0) {
589  ncurr=1;
590  while(ncurr <= ml->matrixNr) {
591  /* Find any matrix with this number? */
592  for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].plane==ncurr) {n=1; break;}
593  /* If yes, then go on to the next matrix number */
594  if(n==1) {ncurr++; continue;}
595  /* If not, then subtract 1 from all matrix numbers that are larger */
596  for(i=0, n=0; i<ml->matrixNr; i++)
597  if(matval[i].plane>ncurr) {
598  /*printf(" plane %d -> plane %d\n", matval[i].plane, matval[i].plane-1);*/
599  matval[i].plane--; n++;
600  }
601  /* If no larger values were found any more, then quit */
602  if(n<1) break;
603  }
604  }
605 
606  /* Frames */
607  if(do_frames!=0) {
608  ncurr=1;
609  while(ncurr <= ml->matrixNr) {
610  /* Find any matrix with this number? */
611  for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].frame==ncurr) {n=1; break;}
612  /* If yes, then go on to the next matrix number */
613  if(n==1) {ncurr++; continue;}
614  /* If not, then subtract 1 from all matrix numbers that are larger */
615  for(i=0, n=0; i<ml->matrixNr; i++)
616  if(matval[i].frame>ncurr) {matval[i].frame--; n++;}
617  /* If no larger values were found any more, then quit */
618  if(n<1) break;
619  }
620  }
621 
622  /* Gates */
623  if(do_gates!=0) {
624  ncurr=1;
625  while(ncurr <= ml->matrixNr) {
626  /* Find any matrix with this number? */
627  for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].gate==ncurr) {n=1; break;}
628  /* If yes, then go on to the next matrix number */
629  if(n==1) {ncurr++; continue;}
630  /* If not, then subtract 1 from all matrix numbers that are larger */
631  for(i=0, n=0; i<ml->matrixNr; i++)
632  if(matval[i].gate>ncurr) {matval[i].gate--; n++;}
633  /* If no larger values were found any more, then quit */
634  if(n<1) break;
635  }
636  }
637 
638  /* Beds */
639  if(do_beds!=0) {
640  ncurr=1;
641  while(ncurr <= ml->matrixNr) {
642  /* Find any matrix with this number? */
643  for(i=0, n=0; i<ml->matrixNr; i++) if(matval[i].bed==ncurr) {n=1; break;}
644  /* If yes, then go on to the next matrix number */
645  if(n==1) {ncurr++; continue;}
646  /* If not, then subtract 1 from all matrix numbers that are larger */
647  for(i=0, n=0; i<ml->matrixNr; i++)
648  if(matval[i].bed>ncurr) {matval[i].bed--; n++;}
649  /* If no larger values were found any more, then quit */
650  if(n<1) break;
651  }
652  }
653 
654  /* Write matrix values (possibly changed) into matrix list */
655  for(i=0; i<ml->matrixNr; i++) ml->matdir[i].id=ecat7_val_to_id(
656  matval[i].frame, matval[i].plane,
657  matval[i].gate, matval[i].data,
658  matval[i].bed);
659  free(matval);
660  return(0);
661 }
662 /*****************************************************************************/
663 
664 /*****************************************************************************/
665 
short int num_z_elements[64]
Definition: ecat7.h:365
int status
Definition: ecat7.h:609
int data
Definition: ecat7.h:617
int frame
Definition: ecat7.h:617
short int num_dimensions
Definition: ecat7.h:232
short int z_dimension
Definition: ecat7.h:238
short int num_frames
Definition: ecat7.h:189
short int file_type
Definition: ecat7.h:113
int ECAT7_TEST
Definition: ecat7.h:101
int ecat7ReadScanheader(FILE *fp, int blk, ECAT7_scanheader *h)
Definition: ecat7r.c:424
short int num_gates
Definition: ecat7.h:191
int ecat7DeleteLateFrames(ECAT7_MATRIXLIST *ml, int frame_nr)
Definition: ecat7ml.c:383
int strtblk
Definition: ecat7.h:607
int plane
Definition: ecat7.h:617
Definition: img.h:118
int id
Definition: ecat7.h:606
int gate
Definition: ecat7.h:617
#define MatBLKSIZE
Definition: ecat63.h:27
ECAT7_MatDir * matdir
Definition: ecat7.h:614
int matrixSpace
Definition: ecat7.h:613
int ecat7GatherMatlist(ECAT7_MATRIXLIST *ml, short int do_planes, short int do_frames, short int do_gates, short int do_beds)
Definition: ecat7ml.c:572
int ecat7_val_to_id(int frame, int plane, int gate, int data, int bed)
Definition: ecat7ml.c:282
void ecat7SortMatlistByFrame(ECAT7_MATRIXLIST *ml)
Definition: ecat7ml.c:340
int ecat7GetPlaneAndFrameNr(ECAT7_MATRIXLIST *mlist, ECAT7_mainheader *h, int *plane_nr, int *frame_nr)
Definition: ecat7ml.c:409
int bed
Definition: ecat7.h:617
void ecat7InitMatlist(ECAT7_MATRIXLIST *mlist)
Definition: ecat7ml.c:59
void ecat7PrintMatlist(ECAT7_MATRIXLIST *ml)
Definition: ecat7ml.c:149
void ecat7EmptyMatlist(ECAT7_MATRIXLIST *mlist)
Definition: ecat7ml.c:70
int ecat7GetNums(ECAT7_MATRIXLIST *ml, ECAT7_mainheader *mh, FILE *fp, short int *num_planes, short int *num_frames, short int *num_gates, short int *num_bed_pos)
Definition: ecat7ml.c:489
#define ECAT7_VOLUME16
Definition: ecat7.h:74
#define ECAT7_3DSCANFIT
Definition: ecat7.h:81
int ecat7GetMatrixBlockSize(ECAT7_MATRIXLIST *mlist, int *blk_nr)
Definition: ecat7ml.c:455
#define MatFirstDirBlk
Definition: ecat63.h:28
void ecat7_id_to_val(int matrix_id, ECAT7_Matval *matval)
Definition: ecat7ml.c:299
int ecat7CheckMatlist(ECAT7_MATRIXLIST *ml)
Definition: ecat7ml.c:366
int ecat7ReadMatlist(FILE *fp, ECAT7_MATRIXLIST *ml)
Definition: ecat7ml.c:86
#define ECAT7_3DSCAN
Definition: ecat7.h:78
#define ECAT7_3DSCAN8
Definition: ecat7.h:79
int endblk
Definition: ecat7.h:608
#define ECAT7_VOLUME8
Definition: ecat7.h:73
int ecat7EnterMatrix(FILE *fp, int matrix_id, int block_nr)
Definition: ecat7ml.c:184
void ecat7SortMatlistByPlane(ECAT7_MATRIXLIST *ml)
Definition: ecat7ml.c:314
int ecat7ReadImageheader(FILE *fp, int blk, ECAT7_imageheader *h)
Definition: ecat7r.c:177