00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <locale.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <math.h>
00032 #include <ctype.h>
00033 #include <string.h>
00034 #include <unistd.h>
00035 #include <time.h>
00036
00037 #include <swap.h>
00038 #include <datetime.h>
00039 #include "include/ecat7.h"
00040
00041
00042
00049 void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp) {
00050 int i;
00051 char tmp[64];
00052 struct tm *st;
00053 time_t lt;
00054
00055 if(ECAT7_TEST) fprintf(stdout, "ecat7PrintMainheader()\n");
00056 fprintf(fp, "magic_number := %.14s\n", h->magic_number);
00057 fprintf(fp, "original_file_name := %.32s\n", h->original_file_name);
00058 fprintf(fp, "sw_version := %d\n", h->sw_version);
00059 fprintf(fp, "system_type := %d\n", h->system_type);
00060 fprintf(fp, "file_type := %d (%s)\n", h->file_type, ecat7filetype(h->file_type) );
00061 fprintf(fp, "serial_number := %.10s\n", h->serial_number);
00062 lt=(time_t)h->scan_start_time; st=localtime(<);
00063 if(st!=NULL) strftime(tmp, 32, "%Y-%m-%d %H:%M:%S", st);
00064 else strcpy(tmp, "1900-01-01 00:00:00");
00065 fprintf(fp, "scan_start_time := %s\n", tmp);
00066 fprintf(fp, "isotope_name := %.8s\n", h->isotope_name);
00067 fprintf(fp, "isotope_halflife := %E sec\n", h->isotope_halflife);
00068 fprintf(fp, "radiopharmaceutical := %.32s\n", h->radiopharmaceutical);
00069 fprintf(fp, "gantry_tilt := %g\n", h->gantry_tilt);
00070 fprintf(fp, "gantry_rotation := %g\n", h->gantry_rotation);
00071 fprintf(fp, "bed_elevation := %g\n", h->bed_elevation);
00072 fprintf(fp, "intrinsic_tilt := %g\n", h->intrinsic_tilt);
00073 fprintf(fp, "wobble_speed := %d\n", h->wobble_speed);
00074 fprintf(fp, "transm_source_type := %d\n", h->transm_source_type);
00075 fprintf(fp, "distance_scanned := %g\n", h->distance_scanned);
00076 fprintf(fp, "transaxial_fov := %g\n", h->transaxial_fov);
00077 fprintf(fp, "angular_compression := %d\n", h->angular_compression);
00078 fprintf(fp, "coin_samp_mode := %d\n", h->coin_samp_mode);
00079 fprintf(fp, "axial_samp_mode := %d\n", h->axial_samp_mode);
00080 fprintf(fp, "ecat_calibration_factor := %E\n", h->ecat_calibration_factor);
00081 fprintf(fp, "calibration_units := %d\n", h->calibration_units);
00082 fprintf(fp, "calibration_units_label := %d\n", h->calibration_units_label);
00083 fprintf(fp, "compression_code := %d\n", h->compression_code);
00084 fprintf(fp, "study_type := %.12s\n", h->study_type);
00085 fprintf(fp, "patient_id := %.16s\n", h->patient_id);
00086 fprintf(fp, "patient_name := %.32s\n", h->patient_name);
00087 fprintf(fp, "patient_sex := %c\n", (h->patient_sex!=0)?h->patient_sex:(char)32);
00088 fprintf(fp, "patient_dexterity := %c\n", (h->patient_dexterity!=0)?h->patient_dexterity:(char)32 );
00089 fprintf(fp, "patient_age := %g\n", h->patient_age);
00090 fprintf(fp, "patient_height := %g\n", h->patient_height);
00091 fprintf(fp, "patient_weight := %g\n", h->patient_weight);
00092 fprintf(fp, "patient_birth_date := %d\n", h->patient_birth_date);
00093 fprintf(fp, "physician_name := %.32s\n", h->physician_name);
00094 fprintf(fp, "operator_name := %.32s\n", h->operator_name);
00095 fprintf(fp, "study_description := %.32s\n", h->study_description);
00096 fprintf(fp, "acquisition_type := %d (%s)\n", h->acquisition_type,
00097 ecat7acquisitiontype(h->acquisition_type));
00098 fprintf(fp, "patient_orientation := %d\n", h->patient_orientation);
00099 fprintf(fp, "facility_name := %.20s\n", h->facility_name);
00100 fprintf(fp, "num_planes := %d\n", h->num_planes);
00101 fprintf(fp, "num_frames := %d\n", h->num_frames);
00102 fprintf(fp, "num_gates := %d\n", h->num_gates);
00103 fprintf(fp, "num_bed_pos := %d\n", h->num_bed_pos);
00104 fprintf(fp, "init_bed_position := %g\n", h->init_bed_position);
00105 fprintf(fp, "bed_position :=");
00106 for(i=0; i<15; i++) fprintf(fp, " %g", h->bed_position[i]);
00107 fprintf(fp, "\n");
00108 fprintf(fp, "plane_separation := %g cm\n", h->plane_separation);
00109 fprintf(fp, "lwr_sctr_thres := %d\n", h->lwr_sctr_thres);
00110 fprintf(fp, "lwr_true_thres := %d\n", h->lwr_true_thres);
00111 fprintf(fp, "upr_true_thres := %d\n", h->upr_true_thres);
00112 fprintf(fp, "user_process_code := %.10s\n", h->user_process_code);
00113 fprintf(fp, "acquisition_mode := %d\n", h->acquisition_mode);
00114 fprintf(fp, "bin_size := %g cm\n", h->bin_size);
00115 fprintf(fp, "branching_fraction := %g\n", h->branching_fraction);
00116 lt=(time_t)h->dose_start_time; st=localtime(<);
00117 if(st!=NULL) strftime(tmp, 32, "%Y-%m-%d %H:%M:%S", st);
00118 else strcpy(tmp, "1900-01-01 00:00:00");
00119 fprintf(fp, "dose_start_time := %s\n", tmp);
00120 fprintf(fp, "dosage := %g\n", h->dosage);
00121 fprintf(fp, "well_counter_corr_factor := %E\n", h->well_counter_corr_factor);
00122 fprintf(fp, "data_units := %.32s\n", h->data_units);
00123 fprintf(fp, "septa_state := %d\n", h->septa_state);
00124 fprintf(fp, "fill_cti :=");
00125 for(i=0; i<6; i++) fprintf(fp, " %d", h->fill_cti[i]);
00126 fprintf(fp, "\n");
00127 }
00128
00129
00130
00137 void ecat7PrintImageheader(ECAT7_imageheader *h, FILE *fp) {
00138 int i;
00139
00140 if(ECAT7_TEST) fprintf(stdout, "ecat7PrintImageheader()\n");
00141 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00142 ecat7datatype(h->data_type) );
00143 fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
00144 fprintf(fp, "x_dimension := %d\n", h->x_dimension);
00145 fprintf(fp, "y_dimension := %d\n", h->y_dimension);
00146 fprintf(fp, "z_dimension := %d\n", h->z_dimension);
00147 fprintf(fp, "x_offset := %g\n", h->x_offset);
00148 fprintf(fp, "y_offset := %g\n", h->y_offset);
00149 fprintf(fp, "z_offset := %g\n", h->z_offset);
00150 fprintf(fp, "recon_zoom := %g\n", h->recon_zoom);
00151 fprintf(fp, "scale_factor := %E\n", h->scale_factor);
00152 fprintf(fp, "image_min := %d\n", h->image_min);
00153 fprintf(fp, "image_max := %d\n", h->image_max);
00154 fprintf(fp, "x_pixel_size := %g\n", h->x_pixel_size);
00155 fprintf(fp, "y_pixel_size := %g\n", h->y_pixel_size);
00156 fprintf(fp, "z_pixel_size := %g\n", h->z_pixel_size);
00157 fprintf(fp, "frame_duration := %d\n", h->frame_duration);
00158 fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
00159 fprintf(fp, "filter_code := %d\n", h->filter_code);
00160 fprintf(fp, "x_resolution := %g\n", h->x_resolution);
00161 fprintf(fp, "y_resolution := %g\n", h->y_resolution);
00162 fprintf(fp, "z_resolution := %g\n", h->z_resolution);
00163 fprintf(fp, "num_r_elements := %g\n", h->num_r_elements);
00164 fprintf(fp, "num_angles := %g\n", h->num_angles);
00165 fprintf(fp, "z_rotation_angle := %g\n", h->z_rotation_angle);
00166 fprintf(fp, "decay_corr_fctr := %g\n", h->decay_corr_fctr);
00167 fprintf(fp, "processing_code := %d\n", h->processing_code);
00168 fprintf(fp, "gate_duration := %d\n", h->gate_duration);
00169 fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
00170 fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
00171 fprintf(fp, "filter_cutoff_frequency := %E\n", h->filter_cutoff_frequency);
00172 fprintf(fp, "filter_resolution := %E\n", h->filter_resolution);
00173 fprintf(fp, "filter_ramp_slope := %E\n", h->filter_ramp_slope);
00174 fprintf(fp, "filter_order := %d\n", h->filter_order);
00175 fprintf(fp, "filter_scatter_fraction := %E\n", h->filter_scatter_fraction);
00176 fprintf(fp, "filter_scatter_slope := %E\n", h->filter_scatter_slope);
00177 fprintf(fp, "annotation := %.40s\n", h->annotation);
00178 fprintf(fp, "mt_1_1 := %g\n", h->mt_1_1);
00179 fprintf(fp, "mt_1_2 := %g\n", h->mt_1_2);
00180 fprintf(fp, "mt_1_3 := %g\n", h->mt_1_3);
00181 fprintf(fp, "mt_2_1 := %g\n", h->mt_2_1);
00182 fprintf(fp, "mt_2_2 := %g\n", h->mt_2_2);
00183 fprintf(fp, "mt_2_3 := %g\n", h->mt_2_3);
00184 fprintf(fp, "mt_3_1 := %g\n", h->mt_3_1);
00185 fprintf(fp, "mt_3_2 := %g\n", h->mt_3_2);
00186 fprintf(fp, "mt_3_3 := %g\n", h->mt_3_3);
00187 fprintf(fp, "rfilter_cutoff := %g\n", h->rfilter_cutoff);
00188 fprintf(fp, "rfilter_resolution := %g\n", h->rfilter_resolution);
00189 fprintf(fp, "rfilter_code := %d\n", h->rfilter_code);
00190 fprintf(fp, "rfilter_order := %d\n", h->rfilter_order);
00191 fprintf(fp, "zfilter_cutoff := %g\n", h->zfilter_cutoff);
00192 fprintf(fp, "zfilter_resolution := %g\n", h->zfilter_resolution);
00193 fprintf(fp, "zfilter_code := %d\n", h->zfilter_code);
00194 fprintf(fp, "zfilter_order := %d\n", h->zfilter_order);
00195 fprintf(fp, "mt_1_4 := %g\n", h->mt_1_4);
00196 fprintf(fp, "mt_2_4 := %g\n", h->mt_2_4);
00197 fprintf(fp, "mt_3_4 := %g\n", h->mt_3_4);
00198 fprintf(fp, "scatter_type := %d\n", h->scatter_type);
00199 fprintf(fp, "recon_type := %d\n", h->recon_type);
00200 fprintf(fp, "recon_views := %d\n", h->recon_views);
00201 fprintf(fp, "fill_cti :=");
00202 for(i=0; i<87; i++) fprintf(fp, " %d", h->fill_cti[i]); fprintf(fp, "\n");
00203 fprintf(fp, "fill_user :=");
00204 for(i=0; i<49; i++) fprintf(fp, " %d", h->fill_user[i]); fprintf(fp, "\n");
00205 }
00206
00207
00208
00215 void ecat7PrintScanheader(ECAT7_scanheader *h, FILE *fp) {
00216 int i;
00217
00218 if(ECAT7_TEST) fprintf(stdout, "ecat7PrintScanheader()\n");
00219 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00220 ecat7datatype(h->data_type) );
00221 fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
00222 fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
00223 fprintf(fp, "num_angles := %d\n", h->num_angles);
00224 fprintf(fp, "corrections_applied := %d\n", h->corrections_applied);
00225 fprintf(fp, "num_z_elements :=");
00226 for(i=0; i<64; i++) fprintf(fp, " %d", h->num_z_elements[i]);
00227 fprintf(fp, "\n");
00228 fprintf(fp, "ring_difference := %d\n", h->ring_difference);
00229 fprintf(fp, "storage_order := %d\n", h->storage_order);
00230 fprintf(fp, "axial_compression := %d (span)\n", h->axial_compression);
00231 fprintf(fp, "x_resolution := %g cm\n", h->x_resolution);
00232 fprintf(fp, "v_resolution := %g rad\n", h->v_resolution);
00233 fprintf(fp, "z_resolution := %g cm\n", h->z_resolution);
00234 fprintf(fp, "w_resolution := %g\n", h->w_resolution);
00235 fprintf(fp, "gate_duration := %d\n", h->gate_duration);
00236 fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
00237 fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
00238 fprintf(fp, "scale_factor := %E\n", h->scale_factor);
00239 fprintf(fp, "scan_min := %d\n", h->scan_min);
00240 fprintf(fp, "scan_max := %d\n", h->scan_max);
00241 fprintf(fp, "prompts := %d\n", h->prompts);
00242 fprintf(fp, "delayed := %d\n", h->delayed);
00243 fprintf(fp, "multiples := %d\n", h->multiples);
00244 fprintf(fp, "net_trues := %d\n", h->net_trues);
00245 fprintf(fp, "tot_avg_cor := %g\n", h->tot_avg_cor);
00246 fprintf(fp, "tot_avg_uncor := %g\n", h->tot_avg_uncor);
00247 fprintf(fp, "total_coin_rate := %d\n", h->total_coin_rate);
00248 fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
00249 fprintf(fp, "frame_duration := %d\n", h->frame_duration);
00250 fprintf(fp, "deadtime_correction_factor := %g\n", h->deadtime_correction_factor);
00251 fprintf(fp, "uncor_singles :=");
00252 for(i=0; i<128; i++) fprintf(fp, " %g", h->uncor_singles[i]);
00253 fprintf(fp, "\n");
00254 }
00255
00256
00257
00264 void ecat7PrintAttenheader(ECAT7_attenheader *h, FILE *fp) {
00265 int i;
00266
00267 if(ECAT7_TEST) fprintf(stdout, "ecat7PrintAttenheader()\n");
00268 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00269 ecat7datatype(h->data_type) );
00270 fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
00271 fprintf(fp, "attenuation_type := %d\n", h->attenuation_type);
00272 fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
00273 fprintf(fp, "num_angles := %d\n", h->num_angles);
00274 fprintf(fp, "num_z_elements := %d\n", h->num_z_elements);
00275 fprintf(fp, "ring_difference := %d\n", h->ring_difference);
00276 fprintf(fp, "x_resolution := %g\n", h->x_resolution);
00277 fprintf(fp, "y_resolution := %g\n", h->y_resolution);
00278 fprintf(fp, "z_resolution := %g\n", h->z_resolution);
00279 fprintf(fp, "w_resolution := %g\n", h->w_resolution);
00280 fprintf(fp, "scale_factor := %E\n", h->scale_factor);
00281 fprintf(fp, "x_offset := %g\n", h->x_offset);
00282 fprintf(fp, "y_offset := %g\n", h->y_offset);
00283 fprintf(fp, "x_radius := %g\n", h->x_radius);
00284 fprintf(fp, "y_radius := %g\n", h->y_radius);
00285 fprintf(fp, "tilt_angle := %g\n", h->tilt_angle);
00286 fprintf(fp, "attenuation_coeff := %E\n", h->attenuation_coeff);
00287 fprintf(fp, "attenuation_min := %E\n", h->attenuation_min);
00288 fprintf(fp, "attenuation_max := %E\n", h->attenuation_max);
00289 fprintf(fp, "skull_thickness := %g\n", h->skull_thickness);
00290 fprintf(fp, "num_additional_atten_coeff := %d\n", h->num_additional_atten_coeff);
00291 fprintf(fp, "additional_atten_coeff :=");
00292 for(i=0; i<8; i++) fprintf(fp, " %E", h->additional_atten_coeff[i]);
00293 fprintf(fp, "\n");
00294 fprintf(fp, "edge_finding_threshold := %g\n", h->edge_finding_threshold);
00295 fprintf(fp, "storage_order := %d\n", h->storage_order);
00296 fprintf(fp, "span := %d\n", h->span);
00297 fprintf(fp, "z_elements :=");
00298 for(i=0; i<64; i++) fprintf(fp, " %d", h->z_elements[i]);
00299 fprintf(fp, "\n");
00300 }
00301
00302
00303
00310 void ecat7PrintPolmapheader(ECAT7_polmapheader *h, FILE *fp) {
00311 int i;
00312
00313 if(ECAT7_TEST) fprintf(stdout, "ecat7PrintPolmapheader()\n");
00314 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00315 ecat7datatype(h->data_type) );
00316 fprintf(fp, "polar_map_type := %d\n", h->polar_map_type);
00317 fprintf(fp, "num_rings := %d\n", h->num_rings);
00318 fprintf(fp, "sectors_per_ring :=");
00319 for(i=0; i<32; i++) fprintf(fp, " %d", h->sectors_per_ring[i]);
00320 fprintf(fp, "\n");
00321 fprintf(fp, "ring_position :=");
00322 for(i=0; i<32; i++) fprintf(fp, " %g", h->ring_position[i]);
00323 fprintf(fp, "\n");
00324 fprintf(fp, "ring_angle :=");
00325 for(i=0; i<32; i++) fprintf(fp, " %d", h->ring_angle[i]);
00326 fprintf(fp, "\n");
00327 fprintf(fp, "start_angle := %d\n", h->start_angle);
00328 fprintf(fp, "long_axis_left :=");
00329 for(i=0; i<3; i++) fprintf(fp, " %d", h->long_axis_left[i]);
00330 fprintf(fp, "\n");
00331 fprintf(fp, "long_axis_right :=");
00332 for(i=0; i<3; i++) fprintf(fp, " %d", h->long_axis_right[i]);
00333 fprintf(fp, "\n");
00334 fprintf(fp, "position_data := %d\n", h->position_data);
00335 fprintf(fp, "image_min := %d\n", h->image_min);
00336 fprintf(fp, "image_max := %d\n", h->image_max);
00337 fprintf(fp, "scale_factor := %E\n", h->scale_factor);
00338 fprintf(fp, "pixel_size := %g\n", h->pixel_size);
00339 fprintf(fp, "frame_duration := %d\n", h->frame_duration);
00340 fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
00341 fprintf(fp, "processing_code := %d\n", h->processing_code);
00342 fprintf(fp, "quant_units := %d\n", h->quant_units);
00343 fprintf(fp, "annotation := %.40s\n", h->annotation);
00344 fprintf(fp, "gate_duration := %d\n", h->gate_duration);
00345 fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
00346 fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
00347 fprintf(fp, "polar_map_protocol := %.20s\n", h->polar_map_protocol);
00348 fprintf(fp, "database_name := %.30s\n", h->database_name);
00349 }
00350
00351
00352
00359 void ecat7PrintNormheader(ECAT7_normheader *h, FILE *fp) {
00360 int i;
00361
00362 if(ECAT7_TEST) fprintf(stdout, "ecat7PrintNormheader()\n");
00363 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00364 ecat7datatype(h->data_type) );
00365 fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
00366 fprintf(fp, "num_transaxial_crystals := %d\n", h->num_transaxial_crystals);
00367 fprintf(fp, "num_crystal_rings := %d\n", h->num_crystal_rings);
00368 fprintf(fp, "crystals_per_ring := %d\n", h->crystals_per_ring);
00369 fprintf(fp, "num_geo_corr_planes := %d\n", h->num_geo_corr_planes);
00370 fprintf(fp, "uld := %d\n", h->uld);
00371 fprintf(fp, "lld := %d\n", h->lld);
00372 fprintf(fp, "scatter_energy := %d\n", h->scatter_energy);
00373 fprintf(fp, "norm_quality_factor := %g\n", h->norm_quality_factor);
00374 fprintf(fp, "norm_quality_factor_code := %d\n", h->norm_quality_factor_code);
00375 fprintf(fp, "ring_dtcor1 :=");
00376 for(i=0; i<32; i++) fprintf(fp, " %E", h->ring_dtcor1[i]);
00377 fprintf(fp, "\n");
00378 fprintf(fp, "ring_dtcor2 :=");
00379 for(i=0; i<32; i++) fprintf(fp, " %E", h->ring_dtcor2[i]);
00380 fprintf(fp, "\n");
00381 fprintf(fp, "crystal_dtcor :=");
00382 for(i=0; i<8; i++) fprintf(fp, " %E", h->crystal_dtcor[i]);
00383 fprintf(fp, "\n");
00384 fprintf(fp, "span := %d\n", h->span);
00385 fprintf(fp, "max_ring_diff := %d\n", h->max_ring_diff);
00386 }
00387
00388
00389
00396 void ecat7Print2DScanheader(ECAT7_2Dscanheader *h, FILE *fp) {
00397 int i;
00398
00399 if(ECAT7_TEST) fprintf(stdout, "ecat7Print2DScanheader()\n");
00400 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00401 ecat7datatype(h->data_type) );
00402 fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
00403 fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
00404 fprintf(fp, "num_angles := %d\n", h->num_angles);
00405 fprintf(fp, "corrections_applied := %d\n", h->corrections_applied);
00406 fprintf(fp, "num_z_elements := %d\n", h->num_z_elements);
00407 fprintf(fp, "ring_difference := %d\n", h->ring_difference);
00408 fprintf(fp, "x_resolution := %g\n", h->x_resolution);
00409 fprintf(fp, "y_resolution := %g\n", h->y_resolution);
00410 fprintf(fp, "z_resolution := %g\n", h->z_resolution);
00411 fprintf(fp, "w_resolution := %g\n", h->w_resolution);
00412 fprintf(fp, "gate_duration := %d\n", h->gate_duration);
00413 fprintf(fp, "r_wave_offset := %d\n", h->r_wave_offset);
00414 fprintf(fp, "num_accepted_beats := %d\n", h->num_accepted_beats);
00415 fprintf(fp, "scale_factor := %E\n", h->scale_factor);
00416 fprintf(fp, "scan_min := %d\n", h->scan_min);
00417 fprintf(fp, "scan_max := %d\n", h->scan_max);
00418 fprintf(fp, "prompts := %d\n", h->prompts);
00419 fprintf(fp, "delayed := %d\n", h->delayed);
00420 fprintf(fp, "multiples := %d\n", h->multiples);
00421 fprintf(fp, "net_trues := %d\n", h->net_trues);
00422 fprintf(fp, "cor_singles :=");
00423 for(i=0; i<16; i++) fprintf(fp, " %g", h->cor_singles[i]);
00424 fprintf(fp, "\n");
00425 fprintf(fp, "uncor_singles :=");
00426 for(i=0; i<16; i++) fprintf(fp, " %g", h->uncor_singles[i]);
00427 fprintf(fp, "\n");
00428 fprintf(fp, "tot_avg_cor := %g\n", h->tot_avg_cor);
00429 fprintf(fp, "tot_avg_uncor := %g\n", h->tot_avg_uncor);
00430 fprintf(fp, "total_coin_rate := %d\n", h->total_coin_rate);
00431 fprintf(fp, "frame_start_time := %d\n", h->frame_start_time);
00432 fprintf(fp, "frame_duration := %d\n", h->frame_duration);
00433 fprintf(fp, "deadtime_correction_factor := %E\n", h->deadtime_correction_factor);
00434 fprintf(fp, "physical_planes :=");
00435 for(i=0; i<8; i++) fprintf(fp, " %d", h->physical_planes[i]);
00436 fprintf(fp, "\n");
00437 }
00438
00439
00440
00447 void ecat7Print2DNormheader(ECAT7_2Dnormheader *h, FILE *fp) {
00448 int i;
00449
00450 if(ECAT7_TEST) fprintf(stdout, "ecat7Print2DNormheader()\n");
00451 fprintf(fp, "data_type := %d (%s)\n", h->data_type,
00452 ecat7datatype(h->data_type) );
00453 fprintf(fp, "num_dimensions := %d\n", h->num_dimensions);
00454 fprintf(fp, "num_r_elements := %d\n", h->num_r_elements);
00455 fprintf(fp, "num_angles := %d\n", h->num_angles);
00456 fprintf(fp, "num_z_elements := %d\n", h->num_z_elements);
00457 fprintf(fp, "ring_difference := %d\n", h->ring_difference);
00458 fprintf(fp, "scale_factor := %E\n", h->scale_factor);
00459 fprintf(fp, "norm_min := %g\n", h->norm_min);
00460 fprintf(fp, "norm_max := %g\n", h->norm_max);
00461 fprintf(fp, "fov_source_width := %g\n", h->fov_source_width);
00462 fprintf(fp, "norm_quality_factor := %g\n", h->norm_quality_factor);
00463 fprintf(fp, "norm_quality_factor_code := %d\n", h->norm_quality_factor_code);
00464 fprintf(fp, "storage_order := %d\n", h->storage_order);
00465 fprintf(fp, "span := %d\n", h->span);
00466 fprintf(fp, "z_elements :=");
00467 for(i=0; i<64; i++) fprintf(fp, " %d", h->z_elements[i]);
00468 fprintf(fp, "\n");
00469 }
00470
00471
00472
00479 char* ecat7filetype(short int file_type) {
00480 static char *info[] = {
00481 "unknown", "2D sinogram", "image-16", "attenuation correction",
00482 "2D normalization", "polar map", "volume 8", "volume 16",
00483 "projection 8", "projection 16", "image 8", "3D sinogram 16",
00484 "3D sinogram 8", "3D normalization", "3D sinogram fit",
00485 0};
00486 if(file_type>=0 && file_type<=14) return((char*)info[file_type]);
00487 else return((char*)info[0]);
00488 }
00489
00490
00491
00498 char* ecat7acquisitiontype(short int acquisition_type) {
00499 static char *info[] = {
00500 "undefined", "blank", "transmission", "static emission",
00501 "dynamic emission", "gated emission", "transmission rectilinear",
00502 "emission rectilinear",
00503 0};
00504 if(acquisition_type>=0 && acquisition_type<=7)
00505 return((char*)info[acquisition_type]);
00506 else return((char*)info[0]);
00507 }
00508
00509
00510
00517 char* ecat7datatype(short int data_type) {
00518 static char *info[] = {
00519 "unknown", "byte", "VAX 2 byte integer", "VAX 4 byte integer",
00520 "VAX 4 byte float", "IEEE 4 byte float", "SUN 2 byte integer",
00521 "SUN 4 byte integer",
00522 0};
00523 if(data_type>=0 && data_type<=7) return((char*)info[data_type]);
00524 else return((char*)info[0]);
00525 }
00526
00527
00528
00532 int ecat7PrintSubheader(
00534 ECAT7_mainheader mh,
00536 FILE *fp,
00538 int plane,
00540 int frame,
00542 FILE *ofp
00543 ) {
00544 int mi, ret, nr=0;
00545 ECAT7_imageheader image_header;
00546 ECAT7_scanheader scan_header;
00547 ECAT7_2Dscanheader scan2D_header;
00548 ECAT7_2Dnormheader norm2D_header;
00549 ECAT7_normheader norm_header;
00550 ECAT7_attenheader atten_header;
00551 ECAT7_polmapheader polmap_header;
00552 static ECAT7_MATRIXLIST mlist;
00553 ECAT7_Matval matval;
00554
00555
00556
00557
00558
00559 ecat7InitMatlist(&mlist);
00560 ret=ecat7ReadMatlist(fp, &mlist);
00561 if(ret) {
00562 fprintf(stderr, "Error (%d): cannot read matrix list.\n", ret);
00563 return(2);
00564 }
00565 if(mlist.matrixNr<=0) {
00566 fprintf(stderr, "Error: matrix list is empty.\n");
00567 return(2);
00568 }
00569 if(ECAT7_TEST>1) ecat7PrintMatlist(&mlist);
00570
00571
00572
00573
00574 for(mi=nr=0; mi<mlist.matrixNr; mi++) {
00575
00576 ecat7_id_to_val(mlist.matdir[mi].id, &matval);
00577
00578 if(frame>=0 && frame!=matval.frame) continue;
00579 if(plane>=0 && plane!=matval.plane) continue;
00580 fprintf(fp, "Matrix: plane %d frame %d gate %d bed %d\n",
00581 matval.plane, matval.frame, matval.gate, matval.bed);
00582
00583 ret=0;
00584 switch(mh.file_type) {
00585 case ECAT7_ATTEN:
00586 ret=ecat7ReadAttenheader(fp, mlist.matdir[mi].strtblk, &atten_header);
00587 if(ret==0) ecat7PrintAttenheader(&atten_header, stdout);
00588 break;
00589 case ECAT7_3DNORM:
00590 ret=ecat7ReadNormheader(fp, mlist.matdir[mi].strtblk, &norm_header);
00591 if(ret==0) ecat7PrintNormheader(&norm_header, stdout);
00592 break;
00593 case ECAT7_IMAGE8:
00594 case ECAT7_IMAGE16:
00595 case ECAT7_VOLUME8:
00596 case ECAT7_VOLUME16:
00597 ret=ecat7ReadImageheader(fp, mlist.matdir[mi].strtblk, &image_header);
00598 if(ret==0) ecat7PrintImageheader(&image_header, stdout);
00599 break;
00600 case ECAT7_3DSCAN:
00601 case ECAT7_3DSCAN8:
00602 case ECAT7_3DSCANFIT:
00603 ret=ecat7ReadScanheader(fp, mlist.matdir[mi].strtblk, &scan_header);
00604 if(ret==0) ecat7PrintScanheader(&scan_header, stdout);
00605 break;
00606 case ECAT7_POLARMAP:
00607 ret=ecat7ReadPolmapheader(fp, mlist.matdir[mi].strtblk, &polmap_header);
00608 if(ret==0) ecat7PrintPolmapheader(&polmap_header, stdout);
00609 break;
00610 case ECAT7_2DSCAN:
00611 ret=ecat7Read2DScanheader(fp, mlist.matdir[mi].strtblk, &scan2D_header);
00612 if(ret==0) ecat7Print2DScanheader(&scan2D_header, stdout);
00613 break;
00614 case ECAT7_2DNORM:
00615 ret=ecat7Read2DNormheader(fp, mlist.matdir[mi].strtblk, &norm2D_header);
00616 if(ret==0) ecat7Print2DNormheader(&norm2D_header, stdout);
00617 break;
00618 default:
00619 fprintf(stderr, "Error: matrix filetype %d is not yet supported.\n",
00620 mh.file_type);
00621 ecat7EmptyMatlist(&mlist);
00622 return(8);
00623 }
00624 if(ret) {
00625 fprintf(stderr, "Error %d in reading subheader.\n", ret);
00626 ecat7EmptyMatlist(&mlist); return(5);
00627 }
00628 nr++;
00629 }
00630 ecat7EmptyMatlist(&mlist);
00631
00632 if(nr==0 && (plane>=0 || frame>=0)) {
00633 fprintf(stderr, "Error: specified matrices not found.\n");
00634 return(11);
00635 }
00636
00637 return(0);
00638 }
00639
00640
00641
00642