TPCCLIB
Loading...
Searching...
No Matches
ecat63p.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpcimgio.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
17 ECAT63_mainheader *h, FILE *fp
18) {
19 char tmp[32];
20
21 if(ECAT63_TEST) fprintf(stdout, "ecat63PrintMainheader()\n");
22
23 fprintf(fp, "original_file_name := %.20s\n", h->original_file_name);
24 fprintf(fp, "sw_version := %d\n", h->sw_version);
25 fprintf(fp, "data_type := %d (%s)\n",
27 fprintf(fp, "system_type := %d\n", h->system_type);
28 if(h->file_type==1) strcpy(tmp, "sinogram");
29 else if(h->file_type==2) strcpy(tmp, "image");
30 else if(h->file_type==3) strcpy(tmp, "attenuation");
31 else if(h->file_type==4) strcpy(tmp, "normalization");
32 else strcpy(tmp, "unknown");
33 fprintf(fp, "file_type := %d (%s)\n", h->file_type, tmp);
34 fprintf(fp, "scan_start_time := %04d-%02d-%02d %02d:%02d:%02d\n",
37/*
38 fprintf(fp, "scan start := %02d.%02d.%04d %02d:%02d:%02d\n",
39 h->scan_start_day, h->scan_start_month, h->scan_start_year,
40 h->scan_start_hour, h->scan_start_minute, h->scan_start_second);
41*/
42 fprintf(fp, "isotope_code := %.8s\n", h->isotope_code);
43 fprintf(fp, "isotope_halflife := %E sec\n", h->isotope_halflife);
44 fprintf(fp, "radiopharmaceutical := %.32s\n", h->radiopharmaceutical);
45 fprintf(fp, "gantry_tilt := %g\n", h->gantry_tilt);
46 fprintf(fp, "gantry_rotation := %g\n", h->gantry_rotation);
47 fprintf(fp, "bed_elevation := %g\n", h->bed_elevation);
48 fprintf(fp, "axial_fov := %g\n", h->axial_fov);
49 fprintf(fp, "transaxial_fov := %g\n", h->transaxial_fov);
50 fprintf(fp, "calibration_factor := %g\n", h->calibration_factor);
51 fprintf(fp, "calibration_units := %d (%s)\n",
53 fprintf(fp, "study_name := %.12s\n", h->study_name);
54 fprintf(fp, "patient_id := %.32s\n", h->patient_id);
55 fprintf(fp, "patient_name := %.32s\n", h->patient_name);
56
57 if(isalnum(h->patient_sex))
58 fprintf(fp, "patient_sex := %c\n", h->patient_sex);
59 else fprintf(fp, "patient_sex := \n");
60
61 fprintf(fp, "patient_age := %.10s\n", h->patient_age);
62 fprintf(fp, "patient_height := %.10s\n", h->patient_height);
63 fprintf(fp, "patient_weigth := %.10s\n", h->patient_weight);
64
65 if(isalnum(h->patient_dexterity))
66 fprintf(fp, "patient_dexterity := %c\n", h->patient_dexterity);
67 else fprintf(fp, "patient_dexterity := \n");
68
69 fprintf(fp, "physician_name := %.32s\n", h->physician_name);
70 fprintf(fp, "operator_name := %.32s\n", h->operator_name);
71 fprintf(fp, "study_description := %.32s\n", h->study_description);
72 fprintf(fp, "acquisition_type := %d\n", h->acquisition_type);
73 fprintf(fp, "bed_type := %d\n", h->bed_type);
74 fprintf(fp, "septa_type := %d\n", h->septa_type);
75 fprintf(fp, "facility_name := %.20s\n", h->facility_name);
76
77 fprintf(fp, "num_planes := %d\n", h->num_planes);
78 fprintf(fp, "num_frames := %d\n", h->num_frames);
79 fprintf(fp, "num_gates := %d\n", h->num_gates);
80 fprintf(fp, "num_bed_pos := %d\n", h->num_bed_pos);
81 fprintf(fp, "init_bed_position := %g\n", h->init_bed_position);
82 fprintf(fp, "plane_separation := %g cm\n", h->plane_separation);
83 fprintf(fp, "user_process_code := %.10s\n", h->user_process_code);
84}
85/*****************************************************************************/
86
87/*****************************************************************************/
95 ECAT63_imageheader *h, FILE *fp
96) {
97 if(ECAT63_TEST) printf("ecat63PrintImageheader()\n");
98 fprintf(fp, "data_type := %d (%s)\n", h->data_type, ecat63Datatype(h->data_type));
99 fprintf(fp, "dimension_1 := %d\n", h->dimension_1);
100 fprintf(fp, "dimension_2 := %d\n", h->dimension_2);
101 fprintf(fp, "x_origin := %g\ny_origin := %g\nrecon_scale := %g\n",
102 h->x_origin, h->y_origin, h->recon_scale);
103 fprintf(fp, "quant_scale := %g\nimage_min := %d\nimage_max := %d\n",
104 h->quant_scale, h->image_min, h->image_max);
105 fprintf(fp, "slice_width := %g\npixel_size := %g\n", h->slice_width, h->pixel_size);
106 fprintf(fp, "frame_start_time := %d\nframe_duration := %d\n",
108/*
109 fprintf(fp, "reconstruction_start := %02d.%02d.%04d %02d:%02d:%02d\n",
110 h->recon_start_day, h->recon_start_month, h->recon_start_year,
111 h->recon_start_hour, h->recon_start_min, h->recon_start_sec);
112*/
113 fprintf(fp, "reconstruction_start := %04d-%02d-%02d %02d:%02d:%02d\n",
116 fprintf(fp, "filter_code := %d\nimage_rotation := %g\nintrinsic_tilt := %g\n",
118 fprintf(fp, "filter_params :=");
119 for(int i=0; i<6; i++) fprintf(fp, " %g", h->filter_params[i]);
120 fprintf(fp, "\n");
121 fprintf(fp, "plane_eff_corr_fctr := %g\ndecay_corr_fctr := %g\nloss_corr_fctr := %g\n",
123 fprintf(fp, "quant_units := %d (%s)\n", h->quant_units, ecat63Unit(h->quant_units));
124 fprintf(fp, "ecat_calibration_fctr := %g\nwell_counter_cal_fctr := %g\n",
126 fprintf(fp, "annotation := %.40s\n", h->annotation);
127}
128/*****************************************************************************/
129
130/*****************************************************************************/
138 ECAT63_scanheader *h, FILE *fp
139) {
140 if(ECAT63_TEST) printf("ecat63PrintScanheader()\n");
141 fprintf(fp, "data_type := %d (%s)\n", h->data_type, ecat63Datatype(h->data_type));
142 fprintf(fp, "dimension_1 := %d\n", h->dimension_1);
143 fprintf(fp, "dimension_2 := %d\n", h->dimension_2);
144 fprintf(fp, "sample_distance := %g cm\n", h->sample_distance);
145 fprintf(fp, "isotope_halflife := %g sec\n", h->isotope_halflife);
146 fprintf(fp, "gate_duration := %d\nr_wave_offset := %d\n",
148 fprintf(fp, "scale_factor := %g\n", h->scale_factor);
149 fprintf(fp, "scan_min := %d\nscan_max := %d\n", h->scan_min, h->scan_max);
150 fprintf(fp, "prompts := %d\ndelayed := %d\nmultiples := %d\nnet_trues := %d\n",
151 h->prompts, h->delayed, h->multiples, h->net_trues);
152 fprintf(fp, "cor_singles :=");
153 for(int i=0; i<16; i++) fprintf(fp, " %8.0f", h->cor_singles[i]);
154 printf("\n");
155 fprintf(fp, "uncor_singles :=");
156 for(int i=0; i<16; i++) fprintf(fp, " %8.0f", h->uncor_singles[i]);
157 printf("\n");
158 fprintf(fp, "tot_avg_cor := %g\ntot_avg_uncor := %g\n", h->tot_avg_cor, h->tot_avg_uncor);
159 fprintf(fp, "total_coin_rate := %d\n", h->total_coin_rate);
160 fprintf(fp, "frame_start_time := %d\nframe_duration := %d\n",
162 fprintf(fp, "loss_correction_fctr := %g\n", h->loss_correction_fctr);
163}
164/*****************************************************************************/
165
166/*****************************************************************************/
174 ECAT63_attnheader *h, FILE *fp
175) {
176 if(ECAT63_TEST) printf("ecat63PrintAttnheader()\n");
177 fprintf(fp, "data_type := %d (%s)\n", h->data_type, ecat63Datatype(h->data_type));
178 fprintf(fp, "dimension_1 := %d\n", h->dimension_1);
179 fprintf(fp, "dimension_2 := %d\n", h->dimension_2);
180 fprintf(fp, "sample_distance := %g cm\n", h->sample_distance);
181 fprintf(fp, "attenuation_type := %d\n", h->attenuation_type);
182 fprintf(fp, "scale_factor := %g\n", h->scale_factor);
183 fprintf(fp, "x_origin := %g\ny_origin := %g\nx_radius := %g\ny_radius := %g\n",
184 h->x_origin, h->y_origin, h->x_radius, h->y_radius);
185 fprintf(fp, "tilt_angle := %g\nattenuation_coeff := %g\n",
187}
188/*****************************************************************************/
189
190/*****************************************************************************/
198 ECAT63_normheader *h, FILE *fp
199) {
200 if(ECAT63_TEST) printf("ecat63PrintNormheader()\n");
201 fprintf(fp, "data_type := %d (%s)\n", h->data_type, ecat63Datatype(h->data_type));
202 fprintf(fp, "dimension_1 := %d\n", h->dimension_1);
203 fprintf(fp, "dimension_2 := %d\n", h->dimension_2);
204 fprintf(fp, "scale_factor := %g\n", h->scale_factor);
205 fprintf(fp, "norm_time := %04d-%02d-%02d %02d:%02d:%02d\n",
206 h->norm_year, h->norm_month, h->norm_day,
208}
209/*****************************************************************************/
210
211/*****************************************************************************/
219 short int dtype
220) {
221 static char *ecat63_datatype[]={
222 /* 0 */ "Unknown",
223 /* 1 */ "BYTE_TYPE",
224 /* 2 */ "VAX_I2",
225 /* 3 */ "VAX_I4",
226 /* 4 */ "VAX_R4",
227 /* 5 */ "IEEE_R4",
228 /* 6 */ "SUN_I2",
229 /* 7 */ "SUN_I4",
230 /* 8 */ "Unknown",
231 /* 9 */ "Unknown"
232 };
233 if(dtype>=0 && dtype<10) return(ecat63_datatype[dtype]);
234 else return(ecat63_datatype[0]);
235}
236
244 short int dunit
245) {
246 static char *ecat63_unit[]={
247 /* 0 */ "Unknown",
248 /* 1 */ "Unknown",
249 /* 2 */ "ECAT counts",
250 /* 3 */ "uCi/ml",
251 /* 4 */ "LMRGlu",
252 /* 5 */ "LMRUGlu umol/min/100g",
253 /* 6 */ "LMRUGlu mg/min/100g",
254 /* 7 */ "nCi/mL",
255 /* 8 */ "Well counts",
256 /* 9 */ "Becquerels",
257 /* 10 */ "kBq/mL",
258 /* 11 */ "1/min",
259 /* 12 */ "mL/min/100g",
260 /* 13 */ "sec*kBq/mL",
261 /* 14 */ "sec*nCi/mL",
262 /* 15 */ "1/sec",
263 /* 16 */ "Unitless",
264 /* 17 */ "Unknown"
265 };
266 if(dunit>=0 && dunit<18) return(ecat63_unit[dunit]);
267 else return(ecat63_unit[0]);
268}
269/*****************************************************************************/
278 float *buf
279) {
280 unsigned int u, exp, mantissa;
281 char sign;
282
283 memcpy(&u, buf, 4); if(u & 1L<<31) sign='-'; else sign='+';
284 exp=u<<1; exp=exp>>24; mantissa=u<<9; mantissa=mantissa>>9;
285 printf("%e = %c (%u/8388608 + 1)*2^(%u-127)\n", *buf, sign, mantissa, exp);
286}
287/*****************************************************************************/
288
289/*****************************************************************************/
297 FILE *fp,
299 int plane,
301 int frame,
303 FILE *ofp
304) {
305 int mi, ret, nr=0;
306 static MATRIXLIST mlist;
307 ECAT63_imageheader image_header;
308 ECAT63_scanheader scan_header;
309 ECAT63_attnheader attn_header;
310 ECAT63_normheader norm_header;
311 Matval matval;
312
313
314 /* Read matrix list and nr */
315 ecat63InitMatlist(&mlist);
316 ret=ecat63ReadMatlist(fp, &mlist, ECAT63_TEST);
317 if(ret) {
318 fprintf(stderr, "Error (%d): cannot read matrix list.\n", ret);
319 return 2;
320 }
321 if(mlist.matrixNr<=0) {
322 fprintf(stderr, "Error: matrix list is empty.\n");
323 return 2;
324 }
325 if(ECAT63_TEST>1) ecat63PrintMatlist(&mlist);
326
327 /*
328 * Read and print subheaders one at a time
329 */
330 char errmsg[128]; int errCount=0;
331 for(mi=nr=0; mi<mlist.matrixNr; mi++) {
332 /* Get plane and frame nr */
333 mat_numdoc(mlist.matdir[mi].matnum, &matval);
334 /* Check if this is supposed to be listed or not */
335 if(frame>=0 && frame!=matval.frame) continue;
336 if(plane>=0 && plane!=matval.plane) continue;
337 fprintf(ofp, "\nMatrix: plane %d frame %d gate %d bed %d\n",
338 matval.plane, matval.frame, matval.gate, matval.bed);
339 fflush(ofp);
340 /* Read subheader */
341 if(mh.file_type==IMAGE_DATA)
342 ret=ecat63ReadImageheader(fp, mlist.matdir[mi].strtblk, &image_header, ECAT63_TEST-1, errmsg);
343 else if(mh.file_type==RAW_DATA)
344 ret=ecat63ReadScanheader(fp, mlist.matdir[mi].strtblk, &scan_header, ECAT63_TEST-1, errmsg);
345 else if(mh.file_type==ATTN_DATA)
346 ret=ecat63ReadAttnheader(fp, mlist.matdir[mi].strtblk, &attn_header, ECAT63_TEST-1, errmsg);
347 else if(mh.file_type==NORM_DATA)
348 ret=ecat63ReadNormheader(fp, mlist.matdir[mi].strtblk, &norm_header, ECAT63_TEST-1, errmsg);
349 if(ret) {
350 fprintf(stderr, "Error: %s.\n", errmsg);
351 //fprintf(stderr, "Error: cannot read matrix %u subheader.\n", mlist.matdir[mi].matnum);
352 //if(ECAT63_TEST>0) printf(" ret=%d\n", ret);
353 /*ecat63EmptyMatlist(&mlist); return 4;*/
354 errCount++;
355 continue;
356 }
357 /* Print subheader */
358 if(mh.file_type==IMAGE_DATA)
359 ecat63PrintImageheader(&image_header, ofp);
360 else if(mh.file_type==RAW_DATA)
361 ecat63PrintScanheader(&scan_header, ofp);
362 else if(mh.file_type==ATTN_DATA)
363 ecat63PrintAttnheader(&attn_header, ofp);
364 else if(mh.file_type==NORM_DATA)
365 ecat63PrintNormheader(&norm_header, ofp);
366 nr++; // counter
367 } /* next matrix */
368 ecat63EmptyMatlist(&mlist);
369
370 if(errCount>0 && nr>0 && (plane<0 || frame<0)) {
371 if(errCount==1) fprintf(stderr, "\nWarning: one matrix could not be read.\n");
372 else fprintf(stderr, "\nWarning: %d matrices could not be read.\n", errCount);
373 }
374
375 if(nr==0 && (plane>=0 || frame>=0)) {
376 fprintf(stderr, "Error: specified matrices not found.\n");
377 return(11);
378 }
379
380 return(0);
381}
382/*****************************************************************************/
383
384/*****************************************************************************/
393 const ECAT63_mainheader *h,
396 char *buf
397) {
398 //printf("ecat63ScanstarttimeInt()\n");
399 if(buf==NULL) return(NULL);
400 buf[0]=(char)0;
401 if(h==NULL) return(NULL);
402 if(h->scan_start_year<0 || h->scan_start_year>9999) return(NULL);
403 if(h->scan_start_month<0 || h->scan_start_month>12) return(NULL);
404 if(h->scan_start_day<0 || h->scan_start_day>31) return(NULL);
405 if(h->scan_start_hour<0 || h->scan_start_hour>24) return(NULL);
406 if(h->scan_start_minute<0 || h->scan_start_minute>59) return(NULL);
407 if(h->scan_start_second<0 || h->scan_start_second>59) return(NULL);
408 sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d",
411 return(buf);
412}
413/*****************************************************************************/
414
415/*****************************************************************************/
int ECAT63_TEST
Definition ecat63h.c:6
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
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 * ecat63Datatype(short int dtype)
Definition ecat63p.c:218
void ecat63PrintImageheader(ECAT63_imageheader *h, FILE *fp)
Definition ecat63p.c:94
void ecat63PrintScanheader(ECAT63_scanheader *h, FILE *fp)
Definition ecat63p.c:137
void ecat63PrintNormheader(ECAT63_normheader *h, FILE *fp)
Definition ecat63p.c:197
void float2parts(float *buf)
Definition ecat63p.c:277
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
void ecat63PrintAttnheader(ECAT63_attnheader *h, FILE *fp)
Definition ecat63p.c:173
char * ecat63Unit(short int dunit)
Definition ecat63p.c:243
int ecat6PrintSubheader(ECAT63_mainheader mh, FILE *fp, int plane, int frame, FILE *ofp)
Definition ecat63p.c:293
int ecat63ReadNormheader(FILE *fp, int blk, ECAT63_normheader *h, int verbose, char *errmsg)
Definition ecat63r.c:483
int ecat63ReadScanheader(FILE *fp, int blk, ECAT63_scanheader *h, int verbose, char *errmsg)
Definition ecat63r.c:377
int ecat63ReadAttnheader(FILE *fp, int blk, ECAT63_attnheader *h, int verbose, char *errmsg)
Definition ecat63r.c:296
int ecat63ReadImageheader(FILE *fp, int blk, ECAT63_imageheader *h, int verbose, char *errmsg)
Definition ecat63r.c:187
Header file for libtpcimgio.
#define ATTN_DATA
#define RAW_DATA
#define NORM_DATA
#define IMAGE_DATA
short int dimension_1
short int dimension_2
short int attenuation_type
short int recon_start_month
short int recon_start_day
short int recon_start_min
short int recon_start_year
short int recon_start_hour
short int recon_start_sec
char radiopharmaceutical[32]
short int scan_start_month
char patient_height[10]
short int scan_start_second
short int num_bed_pos
short int acquisition_type
short int calibration_units
short int scan_start_year
char original_file_name[20]
char study_description[32]
short int scan_start_day
short int scan_start_minute
char user_process_code[10]
char patient_weight[10]
short int scan_start_hour
char physician_name[32]
short int system_type
short int dimension_1
short int norm_second
short int dimension_2
short int norm_minute
short int dimension_2
float uncor_singles[16]
short int dimension_1
float cor_singles[16]
MatDir * matdir
int matnum
int strtblk
int frame
int plane