ecat7p.c
Go to the documentation of this file.
1 /******************************************************************************
2 
3  ecat7p.c (c) 2003-2007 by Turku PET Centre
4 
5  Procedures for printing ECAT 7.x (header) contents.
6 
7 
8  Version:
9  2003-07-17 Vesa Oikonen
10  2004-05-23 VO
11  Added ecat7datatype(short int data_type), and used too.
12  Added some units etc.
13  2004-08-15 VO
14  Main header sex and dexterity are checked printed as space instead of
15  (char)0.
16  2004-09-20 VO
17  Doxygen style comments are corrected.
18  2007-03-21 VO
19  strftime() call changed so that even Mingw can understand it.
20  2007-17-07 Harri Merisaari
21  fixed for ANSI
22  2007-09-10 VO
23  Return value of localtime() is checked.
24  2008-07-24 VO
25  Added ecat7PrintSubheader().
26 
27 ******************************************************************************/
28 #include <locale.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <math.h>
32 #include <ctype.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <time.h>
36 /*****************************************************************************/
37 #include <swap.h>
38 #include <datetime.h>
39 #include "include/ecat7.h"
40 /*****************************************************************************/
41 
42 /*****************************************************************************/
50  int i;
51  char tmp[64];
52  struct tm *st;
53  time_t lt;
54 
55  if(ECAT7_TEST) fprintf(stdout, "ecat7PrintMainheader()\n");
56  fprintf(fp, "magic_number := %.14s\n", h->magic_number);
57  fprintf(fp, "original_file_name := %.32s\n", h->original_file_name);
58  fprintf(fp, "sw_version := %d\n", h->sw_version);
59  fprintf(fp, "system_type := %d\n", h->system_type);
60  fprintf(fp, "file_type := %d (%s)\n", h->file_type, ecat7filetype(h->file_type) );
61  fprintf(fp, "serial_number := %.10s\n", h->serial_number);
62  lt=(time_t)h->scan_start_time; st=localtime(&lt);
63  if(st!=NULL) strftime(tmp, 32, "%Y-%m-%d %H:%M:%S", st); /* %T did not work with Mingw */
64  else strcpy(tmp, "1900-01-01 00:00:00");
65  fprintf(fp, "scan_start_time := %s\n", tmp);
66  fprintf(fp, "isotope_name := %.8s\n", h->isotope_name);
67  fprintf(fp, "isotope_halflife := %E sec\n", h->isotope_halflife);
68  fprintf(fp, "radiopharmaceutical := %.32s\n", h->radiopharmaceutical);
69  fprintf(fp, "gantry_tilt := %g\n", h->gantry_tilt);
70  fprintf(fp, "gantry_rotation := %g\n", h->gantry_rotation);
71  fprintf(fp, "bed_elevation := %g\n", h->bed_elevation);
72  fprintf(fp, "intrinsic_tilt := %g\n", h->intrinsic_tilt);
73  fprintf(fp, "wobble_speed := %d\n", h->wobble_speed);
74  fprintf(fp, "transm_source_type := %d\n", h->transm_source_type);
75  fprintf(fp, "distance_scanned := %g\n", h->distance_scanned);
76  fprintf(fp, "transaxial_fov := %g\n", h->transaxial_fov);
77  fprintf(fp, "angular_compression := %d\n", h->angular_compression);
78  fprintf(fp, "coin_samp_mode := %d\n", h->coin_samp_mode);
79  fprintf(fp, "axial_samp_mode := %d\n", h->axial_samp_mode);
80  fprintf(fp, "ecat_calibration_factor := %E\n", h->ecat_calibration_factor);
81  fprintf(fp, "calibration_units := %d\n", h->calibration_units);
82  fprintf(fp, "calibration_units_label := %d\n", h->calibration_units_label);
83  fprintf(fp, "compression_code := %d\n", h->compression_code);
84  fprintf(fp, "study_type := %.12s\n", h->study_type);
85  fprintf(fp, "patient_id := %.16s\n", h->patient_id);
86  fprintf(fp, "patient_name := %.32s\n", h->patient_name);
87  fprintf(fp, "patient_sex := %c\n", (h->patient_sex!=0)?h->patient_sex:(char)32);
88  fprintf(fp, "patient_dexterity := %c\n", (h->patient_dexterity!=0)?h->patient_dexterity:(char)32 );
89  fprintf(fp, "patient_age := %g\n", h->patient_age);
90  fprintf(fp, "patient_height := %g\n", h->patient_height);
91  fprintf(fp, "patient_weight := %g\n", h->patient_weight);
92  fprintf(fp, "patient_birth_date := %d\n", h->patient_birth_date);
93  fprintf(fp, "physician_name := %.32s\n", h->physician_name);
94  fprintf(fp, "operator_name := %.32s\n", h->operator_name);
95  fprintf(fp, "study_description := %.32s\n", h->study_description);
96  fprintf(fp, "acquisition_type := %d (%s)\n", h->acquisition_type,
98  fprintf(fp, "patient_orientation := %d\n", h->patient_orientation);
99  fprintf(fp, "facility_name := %.20s\n", h->facility_name);
100  fprintf(fp, "num_planes := %d\n", h->num_planes);
101  fprintf(fp, "num_frames := %d\n", h->num_frames);
102  fprintf(fp, "num_gates := %d\n", h->num_gates);
103  fprintf(fp, "num_bed_pos := %d\n", h->num_bed_pos);
104  fprintf(fp, "init_bed_position := %g\n", h->init_bed_position);
105  fprintf(fp, "bed_position :=");
106  for(i=0; i<15; i++) fprintf(fp, " %g", h->bed_position[i]);
107  fprintf(fp, "\n");
108  fprintf(fp, "plane_separation := %g cm\n", h->plane_separation);
109  fprintf(fp, "lwr_sctr_thres := %d\n", h->lwr_sctr_thres);
110  fprintf(fp, "lwr_true_thres := %d\n", h->lwr_true_thres);
111  fprintf(fp, "upr_true_thres := %d\n", h->upr_true_thres);
112  fprintf(fp, "user_process_code := %.10s\n", h->user_process_code);
113  fprintf(fp, "acquisition_mode := %d\n", h->acquisition_mode);
114  fprintf(fp, "bin_size := %g cm\n", h->bin_size);
115  fprintf(fp, "branching_fraction := %g\n", h->branching_fraction);
116  lt=(time_t)h->dose_start_time; st=localtime(&lt);
117  if(st!=NULL) strftime(tmp, 32, "%Y-%m-%d %H:%M:%S", st); /* %T did not work with Mingw */
118  else strcpy(tmp, "1900-01-01 00:00:00");
119  fprintf(fp, "dose_start_time := %s\n", tmp);
120  fprintf(fp, "dosage := %g\n", h->dosage);
121  fprintf(fp, "well_counter_corr_factor := %E\n", h->well_counter_corr_factor);
122  fprintf(fp, "data_units := %.32s\n", h->data_units);
123  fprintf(fp, "septa_state := %d\n", h->septa_state);
124  fprintf(fp, "fill_cti :=");
125  for(i=0; i<6; i++) fprintf(fp, " %d", h->fill_cti[i]);
126  fprintf(fp, "\n");
127 }
128 /*****************************************************************************/
129 
130 /*****************************************************************************/
138  int i;
139 
140  if(ECAT7_TEST) fprintf(stdout, "ecat7PrintImageheader()\n");
141  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
142  ecat7datatype(h->data_type) );
143  fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
144  fprintf(fp, "x_dimension := %d\n", h->x_dimension);
145  fprintf(fp, "y_dimension := %d\n", h->y_dimension);
146  fprintf(fp, "z_dimension := %d\n", h->z_dimension);
147  fprintf(fp, "x_offset := %g\n", h->x_offset);
148  fprintf(fp, "y_offset := %g\n", h->y_offset);
149  fprintf(fp, "z_offset := %g\n", h->z_offset);
150  fprintf(fp, "recon_zoom := %g\n", h->recon_zoom);
151  fprintf(fp, "scale_factor := %E\n", h->scale_factor);
152  fprintf(fp, "image_min := %d\n", h->image_min);
153  fprintf(fp, "image_max := %d\n", h->image_max);
154  fprintf(fp, "x_pixel_size := %g\n", h->x_pixel_size);
155  fprintf(fp, "y_pixel_size := %g\n", h->y_pixel_size);
156  fprintf(fp, "z_pixel_size := %g\n", h->z_pixel_size);
157  fprintf(fp, "frame_duration := %d\n", h->frame_duration);
158  fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
159  fprintf(fp, "filter_code := %d\n", h->filter_code);
160  fprintf(fp, "x_resolution := %g\n", h->x_resolution);
161  fprintf(fp, "y_resolution := %g\n", h->y_resolution);
162  fprintf(fp, "z_resolution := %g\n", h->z_resolution);
163  fprintf(fp, "num_r_elements := %g\n", h->num_r_elements);
164  fprintf(fp, "num_angles := %g\n", h->num_angles);
165  fprintf(fp, "z_rotation_angle := %g\n", h->z_rotation_angle);
166  fprintf(fp, "decay_corr_fctr := %g\n", h->decay_corr_fctr);
167  fprintf(fp, "processing_code := %d\n", h->processing_code);
168  fprintf(fp, "gate_duration := %d\n", h->gate_duration);
169  fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
170  fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
171  fprintf(fp, "filter_cutoff_frequency := %E\n", h->filter_cutoff_frequency);
172  fprintf(fp, "filter_resolution := %E\n", h->filter_resolution);
173  fprintf(fp, "filter_ramp_slope := %E\n", h->filter_ramp_slope);
174  fprintf(fp, "filter_order := %d\n", h->filter_order);
175  fprintf(fp, "filter_scatter_fraction := %E\n", h->filter_scatter_fraction);
176  fprintf(fp, "filter_scatter_slope := %E\n", h->filter_scatter_slope);
177  fprintf(fp, "annotation := %.40s\n", h->annotation);
178  fprintf(fp, "mt_1_1 := %g\n", h->mt_1_1);
179  fprintf(fp, "mt_1_2 := %g\n", h->mt_1_2);
180  fprintf(fp, "mt_1_3 := %g\n", h->mt_1_3);
181  fprintf(fp, "mt_2_1 := %g\n", h->mt_2_1);
182  fprintf(fp, "mt_2_2 := %g\n", h->mt_2_2);
183  fprintf(fp, "mt_2_3 := %g\n", h->mt_2_3);
184  fprintf(fp, "mt_3_1 := %g\n", h->mt_3_1);
185  fprintf(fp, "mt_3_2 := %g\n", h->mt_3_2);
186  fprintf(fp, "mt_3_3 := %g\n", h->mt_3_3);
187  fprintf(fp, "rfilter_cutoff := %g\n", h->rfilter_cutoff);
188  fprintf(fp, "rfilter_resolution := %g\n", h->rfilter_resolution);
189  fprintf(fp, "rfilter_code := %d\n", h->rfilter_code);
190  fprintf(fp, "rfilter_order := %d\n", h->rfilter_order);
191  fprintf(fp, "zfilter_cutoff := %g\n", h->zfilter_cutoff);
192  fprintf(fp, "zfilter_resolution := %g\n", h->zfilter_resolution);
193  fprintf(fp, "zfilter_code := %d\n", h->zfilter_code);
194  fprintf(fp, "zfilter_order := %d\n", h->zfilter_order);
195  fprintf(fp, "mt_1_4 := %g\n", h->mt_1_4);
196  fprintf(fp, "mt_2_4 := %g\n", h->mt_2_4);
197  fprintf(fp, "mt_3_4 := %g\n", h->mt_3_4);
198  fprintf(fp, "scatter_type := %d\n", h->scatter_type);
199  fprintf(fp, "recon_type := %d\n", h->recon_type);
200  fprintf(fp, "recon_views := %d\n", h->recon_views);
201  fprintf(fp, "fill_cti :=");
202  for(i=0; i<87; i++) fprintf(fp, " %d", h->fill_cti[i]); fprintf(fp, "\n");
203  fprintf(fp, "fill_user :=");
204  for(i=0; i<49; i++) fprintf(fp, " %d", h->fill_user[i]); fprintf(fp, "\n");
205 }
206 /*****************************************************************************/
207 
208 /*****************************************************************************/
216  int i;
217 
218  if(ECAT7_TEST) fprintf(stdout, "ecat7PrintScanheader()\n");
219  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
220  ecat7datatype(h->data_type) );
221  fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
222  fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
223  fprintf(fp, "num_angles := %d\n", h->num_angles);
224  fprintf(fp, "corrections_applied := %d\n", h->corrections_applied);
225  fprintf(fp, "num_z_elements :=");
226  for(i=0; i<64; i++) fprintf(fp, " %d", h->num_z_elements[i]);
227  fprintf(fp, "\n");
228  fprintf(fp, "ring_difference := %d\n", h->ring_difference);
229  fprintf(fp, "storage_order := %d\n", h->storage_order);
230  fprintf(fp, "axial_compression := %d (span)\n", h->axial_compression);
231  fprintf(fp, "x_resolution := %g cm\n", h->x_resolution);
232  fprintf(fp, "v_resolution := %g rad\n", h->v_resolution);
233  fprintf(fp, "z_resolution := %g cm\n", h->z_resolution);
234  fprintf(fp, "w_resolution := %g\n", h->w_resolution);
235  fprintf(fp, "gate_duration := %d\n", h->gate_duration);
236  fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
237  fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
238  fprintf(fp, "scale_factor := %E\n", h->scale_factor);
239  fprintf(fp, "scan_min := %d\n", h->scan_min);
240  fprintf(fp, "scan_max := %d\n", h->scan_max);
241  fprintf(fp, "prompts := %d\n", h->prompts);
242  fprintf(fp, "delayed := %d\n", h->delayed);
243  fprintf(fp, "multiples := %d\n", h->multiples);
244  fprintf(fp, "net_trues := %d\n", h->net_trues);
245  fprintf(fp, "tot_avg_cor := %g\n", h->tot_avg_cor);
246  fprintf(fp, "tot_avg_uncor := %g\n", h->tot_avg_uncor);
247  fprintf(fp, "total_coin_rate := %d\n", h->total_coin_rate);
248  fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
249  fprintf(fp, "frame_duration := %d\n", h->frame_duration);
250  fprintf(fp, "deadtime_correction_factor := %g\n", h->deadtime_correction_factor);
251  fprintf(fp, "uncor_singles :=");
252  for(i=0; i<128; i++) fprintf(fp, " %g", h->uncor_singles[i]);
253  fprintf(fp, "\n");
254 }
255 /*****************************************************************************/
256 
257 /*****************************************************************************/
265  int i;
266 
267  if(ECAT7_TEST) fprintf(stdout, "ecat7PrintAttenheader()\n");
268  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
269  ecat7datatype(h->data_type) );
270  fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
271  fprintf(fp, "attenuation_type := %d\n", h->attenuation_type);
272  fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
273  fprintf(fp, "num_angles := %d\n", h->num_angles);
274  fprintf(fp, "num_z_elements := %d\n", h->num_z_elements);
275  fprintf(fp, "ring_difference := %d\n", h->ring_difference);
276  fprintf(fp, "x_resolution := %g\n", h->x_resolution);
277  fprintf(fp, "y_resolution := %g\n", h->y_resolution);
278  fprintf(fp, "z_resolution := %g\n", h->z_resolution);
279  fprintf(fp, "w_resolution := %g\n", h->w_resolution);
280  fprintf(fp, "scale_factor := %E\n", h->scale_factor);
281  fprintf(fp, "x_offset := %g\n", h->x_offset);
282  fprintf(fp, "y_offset := %g\n", h->y_offset);
283  fprintf(fp, "x_radius := %g\n", h->x_radius);
284  fprintf(fp, "y_radius := %g\n", h->y_radius);
285  fprintf(fp, "tilt_angle := %g\n", h->tilt_angle);
286  fprintf(fp, "attenuation_coeff := %E\n", h->attenuation_coeff);
287  fprintf(fp, "attenuation_min := %E\n", h->attenuation_min);
288  fprintf(fp, "attenuation_max := %E\n", h->attenuation_max);
289  fprintf(fp, "skull_thickness := %g\n", h->skull_thickness);
290  fprintf(fp, "num_additional_atten_coeff := %d\n", h->num_additional_atten_coeff);
291  fprintf(fp, "additional_atten_coeff :=");
292  for(i=0; i<8; i++) fprintf(fp, " %E", h->additional_atten_coeff[i]);
293  fprintf(fp, "\n");
294  fprintf(fp, "edge_finding_threshold := %g\n", h->edge_finding_threshold);
295  fprintf(fp, "storage_order := %d\n", h->storage_order);
296  fprintf(fp, "span := %d\n", h->span);
297  fprintf(fp, "z_elements :=");
298  for(i=0; i<64; i++) fprintf(fp, " %d", h->z_elements[i]);
299  fprintf(fp, "\n");
300 }
301 /*****************************************************************************/
302 
303 /*****************************************************************************/
311  int i;
312 
313  if(ECAT7_TEST) fprintf(stdout, "ecat7PrintPolmapheader()\n");
314  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
315  ecat7datatype(h->data_type) );
316  fprintf(fp, "polar_map_type := %d\n", h->polar_map_type);
317  fprintf(fp, "num_rings := %d\n", h->num_rings);
318  fprintf(fp, "sectors_per_ring :=");
319  for(i=0; i<32; i++) fprintf(fp, " %d", h->sectors_per_ring[i]);
320  fprintf(fp, "\n");
321  fprintf(fp, "ring_position :=");
322  for(i=0; i<32; i++) fprintf(fp, " %g", h->ring_position[i]);
323  fprintf(fp, "\n");
324  fprintf(fp, "ring_angle :=");
325  for(i=0; i<32; i++) fprintf(fp, " %d", h->ring_angle[i]);
326  fprintf(fp, "\n");
327  fprintf(fp, "start_angle := %d\n", h->start_angle);
328  fprintf(fp, "long_axis_left :=");
329  for(i=0; i<3; i++) fprintf(fp, " %d", h->long_axis_left[i]);
330  fprintf(fp, "\n");
331  fprintf(fp, "long_axis_right :=");
332  for(i=0; i<3; i++) fprintf(fp, " %d", h->long_axis_right[i]);
333  fprintf(fp, "\n");
334  fprintf(fp, "position_data := %d\n", h->position_data);
335  fprintf(fp, "image_min := %d\n", h->image_min);
336  fprintf(fp, "image_max := %d\n", h->image_max);
337  fprintf(fp, "scale_factor := %E\n", h->scale_factor);
338  fprintf(fp, "pixel_size := %g\n", h->pixel_size);
339  fprintf(fp, "frame_duration := %d\n", h->frame_duration);
340  fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
341  fprintf(fp, "processing_code := %d\n", h->processing_code);
342  fprintf(fp, "quant_units := %d\n", h->quant_units);
343  fprintf(fp, "annotation := %.40s\n", h->annotation);
344  fprintf(fp, "gate_duration := %d\n", h->gate_duration);
345  fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
346  fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
347  fprintf(fp, "polar_map_protocol := %.20s\n", h->polar_map_protocol);
348  fprintf(fp, "database_name := %.30s\n", h->database_name);
349 }
350 /*****************************************************************************/
351 
352 /*****************************************************************************/
360  int i;
361 
362  if(ECAT7_TEST) fprintf(stdout, "ecat7PrintNormheader()\n");
363  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
364  ecat7datatype(h->data_type) );
365  fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
366  fprintf(fp, "num_transaxial_crystals := %d\n", h->num_transaxial_crystals);
367  fprintf(fp, "num_crystal_rings := %d\n", h->num_crystal_rings);
368  fprintf(fp, "crystals_per_ring := %d\n", h->crystals_per_ring);
369  fprintf(fp, "num_geo_corr_planes := %d\n", h->num_geo_corr_planes);
370  fprintf(fp, "uld := %d\n", h->uld);
371  fprintf(fp, "lld := %d\n", h->lld);
372  fprintf(fp, "scatter_energy := %d\n", h->scatter_energy);
373  fprintf(fp, "norm_quality_factor := %g\n", h->norm_quality_factor);
374  fprintf(fp, "norm_quality_factor_code := %d\n", h->norm_quality_factor_code);
375  fprintf(fp, "ring_dtcor1 :=");
376  for(i=0; i<32; i++) fprintf(fp, " %E", h->ring_dtcor1[i]);
377  fprintf(fp, "\n");
378  fprintf(fp, "ring_dtcor2 :=");
379  for(i=0; i<32; i++) fprintf(fp, " %E", h->ring_dtcor2[i]);
380  fprintf(fp, "\n");
381  fprintf(fp, "crystal_dtcor :=");
382  for(i=0; i<8; i++) fprintf(fp, " %E", h->crystal_dtcor[i]);
383  fprintf(fp, "\n");
384  fprintf(fp, "span := %d\n", h->span);
385  fprintf(fp, "max_ring_diff := %d\n", h->max_ring_diff);
386 }
387 /*****************************************************************************/
388 
389 /*****************************************************************************/
397  int i;
398 
399  if(ECAT7_TEST) fprintf(stdout, "ecat7Print2DScanheader()\n");
400  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
401  ecat7datatype(h->data_type) );
402  fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
403  fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
404  fprintf(fp, "num_angles := %d\n", h->num_angles);
405  fprintf(fp, "corrections_applied := %d\n", h->corrections_applied);
406  fprintf(fp, "num_z_elements := %d\n", h->num_z_elements);
407  fprintf(fp, "ring_difference := %d\n", h->ring_difference);
408  fprintf(fp, "x_resolution := %g\n", h->x_resolution);
409  fprintf(fp, "y_resolution := %g\n", h->y_resolution);
410  fprintf(fp, "z_resolution := %g\n", h->z_resolution);
411  fprintf(fp, "w_resolution := %g\n", h->w_resolution);
412  fprintf(fp, "gate_duration := %d\n", h->gate_duration);
413  fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
414  fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
415  fprintf(fp, "scale_factor := %E\n", h->scale_factor);
416  fprintf(fp, "scan_min := %d\n", h->scan_min);
417  fprintf(fp, "scan_max := %d\n", h->scan_max);
418  fprintf(fp, "prompts := %d\n", h->prompts);
419  fprintf(fp, "delayed := %d\n", h->delayed);
420  fprintf(fp, "multiples := %d\n", h->multiples);
421  fprintf(fp, "net_trues := %d\n", h->net_trues);
422  fprintf(fp, "cor_singles :=");
423  for(i=0; i<16; i++) fprintf(fp, " %g", h->cor_singles[i]);
424  fprintf(fp, "\n");
425  fprintf(fp, "uncor_singles :=");
426  for(i=0; i<16; i++) fprintf(fp, " %g", h->uncor_singles[i]);
427  fprintf(fp, "\n");
428  fprintf(fp, "tot_avg_cor := %g\n", h->tot_avg_cor);
429  fprintf(fp, "tot_avg_uncor := %g\n", h->tot_avg_uncor);
430  fprintf(fp, "total_coin_rate := %d\n", h->total_coin_rate);
431  fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
432  fprintf(fp, "frame_duration := %d\n", h->frame_duration);
433  fprintf(fp, "deadtime_correction_factor := %E\n", h->deadtime_correction_factor);
434  fprintf(fp, "physical_planes :=");
435  for(i=0; i<8; i++) fprintf(fp, " %d", h->physical_planes[i]);
436  fprintf(fp, "\n");
437 }
438 /*****************************************************************************/
439 
440 /*****************************************************************************/
448  int i;
449 
450  if(ECAT7_TEST) fprintf(stdout, "ecat7Print2DNormheader()\n");
451  fprintf(fp, "data_type := %d (%s)\n", h->data_type,
452  ecat7datatype(h->data_type) );
453  fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
454  fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
455  fprintf(fp, "num_angles := %d\n", h->num_angles);
456  fprintf(fp, "num_z_elements := %d\n", h->num_z_elements);
457  fprintf(fp, "ring_difference := %d\n", h->ring_difference);
458  fprintf(fp, "scale_factor := %E\n", h->scale_factor);
459  fprintf(fp, "norm_min := %g\n", h->norm_min);
460  fprintf(fp, "norm_max := %g\n", h->norm_max);
461  fprintf(fp, "fov_source_width := %g\n", h->fov_source_width);
462  fprintf(fp, "norm_quality_factor := %g\n", h->norm_quality_factor);
463  fprintf(fp, "norm_quality_factor_code := %d\n", h->norm_quality_factor_code);
464  fprintf(fp, "storage_order := %d\n", h->storage_order);
465  fprintf(fp, "span := %d\n", h->span);
466  fprintf(fp, "z_elements :=");
467  for(i=0; i<64; i++) fprintf(fp, " %d", h->z_elements[i]);
468  fprintf(fp, "\n");
469 }
470 /*****************************************************************************/
471 
472 /*****************************************************************************/
479 char* ecat7filetype(short int file_type) {
480  static char *info[] = {
481  "unknown", "2D sinogram", "image-16", "attenuation correction",
482  "2D normalization", "polar map", "volume 8", "volume 16",
483  "projection 8", "projection 16", "image 8", "3D sinogram 16",
484  "3D sinogram 8", "3D normalization", "3D sinogram fit",
485  0};
486  if(file_type>=0 && file_type<=14) return((char*)info[file_type]);
487  else return((char*)info[0]);
488 }
489 /*****************************************************************************/
490 
491 /*****************************************************************************/
498 char* ecat7acquisitiontype(short int acquisition_type) {
499  static char *info[] = {
500  "undefined", "blank", "transmission", "static emission",
501  "dynamic emission", "gated emission", "transmission rectilinear",
502  "emission rectilinear",
503  0};
504  if(acquisition_type>=0 && acquisition_type<=7)
505  return((char*)info[acquisition_type]);
506  else return((char*)info[0]);
507 }
508 /*****************************************************************************/
509 
510 /*****************************************************************************/
517 char* ecat7datatype(short int data_type) {
518  static char *info[] = {
519  "unknown", "byte", "VAX 2 byte integer", "VAX 4 byte integer",
520  "VAX 4 byte float", "IEEE 4 byte float", "SUN 2 byte integer",
521  "SUN 4 byte integer",
522  0};
523  if(data_type>=0 && data_type<=7) return((char*)info[data_type]);
524  else return((char*)info[0]);
525 }
526 /*****************************************************************************/
527 
528 /*****************************************************************************/
534  ECAT7_mainheader mh,
536  FILE *fp,
538  int plane,
540  int frame,
542  FILE *ofp
543 ) {
544  int mi, ret, nr=0;
545  ECAT7_imageheader image_header;
546  ECAT7_scanheader scan_header;
547  ECAT7_2Dscanheader scan2D_header;
548  ECAT7_2Dnormheader norm2D_header;
549  ECAT7_normheader norm_header;
550  ECAT7_attenheader atten_header;
551  ECAT7_polmapheader polmap_header;
552  static ECAT7_MATRIXLIST mlist;
553  ECAT7_Matval matval;
554 
555 
556  /*
557  * Read matrix list
558  */
559  ecat7InitMatlist(&mlist);
560  ret=ecat7ReadMatlist(fp, &mlist);
561  if(ret) {
562  fprintf(stderr, "Error (%d): cannot read matrix list.\n", ret);
563  return(2);
564  }
565  if(mlist.matrixNr<=0) {
566  fprintf(stderr, "Error: matrix list is empty.\n");
567  return(2);
568  }
569  if(ECAT7_TEST>1) ecat7PrintMatlist(&mlist);
570 
571  /*
572  * Read and print subheaders one at a time
573  */
574  for(mi=nr=0; mi<mlist.matrixNr; mi++) {
575  /* Get frame nr */
576  ecat7_id_to_val(mlist.matdir[mi].id, &matval);
577  /* Check if this is supposed to be listed or not */
578  if(frame>=0 && frame!=matval.frame) continue;
579  if(plane>=0 && plane!=matval.plane) continue;
580  fprintf(fp, "Matrix: plane %d frame %d gate %d bed %d\n",
581  matval.plane, matval.frame, matval.gate, matval.bed);
582  /* Read and print subheader */
583  ret=0;
584  switch(mh.file_type) {
585  case ECAT7_ATTEN:
586  ret=ecat7ReadAttenheader(fp, mlist.matdir[mi].strtblk, &atten_header);
587  if(ret==0) ecat7PrintAttenheader(&atten_header, stdout);
588  break;
589  case ECAT7_3DNORM:
590  ret=ecat7ReadNormheader(fp, mlist.matdir[mi].strtblk, &norm_header);
591  if(ret==0) ecat7PrintNormheader(&norm_header, stdout);
592  break;
593  case ECAT7_IMAGE8:
594  case ECAT7_IMAGE16:
595  case ECAT7_VOLUME8:
596  case ECAT7_VOLUME16:
597  ret=ecat7ReadImageheader(fp, mlist.matdir[mi].strtblk, &image_header);
598  if(ret==0) ecat7PrintImageheader(&image_header, stdout);
599  break;
600  case ECAT7_3DSCAN:
601  case ECAT7_3DSCAN8:
602  case ECAT7_3DSCANFIT:
603  ret=ecat7ReadScanheader(fp, mlist.matdir[mi].strtblk, &scan_header);
604  if(ret==0) ecat7PrintScanheader(&scan_header, stdout);
605  break;
606  case ECAT7_POLARMAP:
607  ret=ecat7ReadPolmapheader(fp, mlist.matdir[mi].strtblk, &polmap_header);
608  if(ret==0) ecat7PrintPolmapheader(&polmap_header, stdout);
609  break;
610  case ECAT7_2DSCAN:
611  ret=ecat7Read2DScanheader(fp, mlist.matdir[mi].strtblk, &scan2D_header);
612  if(ret==0) ecat7Print2DScanheader(&scan2D_header, stdout);
613  break;
614  case ECAT7_2DNORM:
615  ret=ecat7Read2DNormheader(fp, mlist.matdir[mi].strtblk, &norm2D_header);
616  if(ret==0) ecat7Print2DNormheader(&norm2D_header, stdout);
617  break;
618  default:
619  fprintf(stderr, "Error: matrix filetype %d is not yet supported.\n",
620  mh.file_type);
621  ecat7EmptyMatlist(&mlist);
622  return(8);
623  }
624  if(ret) {
625  fprintf(stderr, "Error %d in reading subheader.\n", ret);
626  ecat7EmptyMatlist(&mlist); return(5);
627  }
628  nr++; // counter
629  } /* next matrix */
630  ecat7EmptyMatlist(&mlist);
631 
632  if(nr==0 && (plane>=0 || frame>=0)) {
633  fprintf(stderr, "Error: specified matrices not found.\n");
634  return(11);
635  }
636 
637  return(0);
638 }
639 /*****************************************************************************/
640 
641 /*****************************************************************************/
642