TPCCLIB
Loading...
Searching...
No Matches
ecat7h.c
Go to the documentation of this file.
1
5/*****************************************************************************/
7char ecat7errmsg[128];
8/*****************************************************************************/
9#include "libtpcimgio.h"
10/*****************************************************************************/
11
12/*****************************************************************************/
20 char *field,
22 char *value,
24 int verbose
25) {
26 int yy, mm, dd;
27 short int si;
28 float f;
29
30 if(verbose>0) printf("ecat7EditMHeader('%s', '%s')\n", field, value);
31 si=atoi(value); f=atof(value);
32 if(strcmp(field, "magic_number")==0) {
33 strlcpy(h->magic_number, value, 14);
34 } else if(strcmp(field, "original_file_name")==0) {
35 strlcpy(h->original_file_name, value, 32);
36 } else if(strcmp(field, "sw_version")==0) {
37 if(si<=0) return(2); else h->sw_version=si;
38 } else if(strcmp(field, "system_type")==0) {
39 if(si<0) return(2); else h->system_type=si;
40 } else if(strcmp(field, "file_type")==0) {
41 if(si<0) return(2); else h->file_type=si;
42 } else if(strcmp(field, "serial_number")==0) {
43 strlcpy(h->serial_number, value, 10);
44 } else if(strcmp(field, "scan_start_time")==0) {
45 struct tm stm;
46 time_t t;
47 if(get_datetime(value, &stm, verbose-1)!=0) return(2);
48 if(verbose>3) printf(" year=%d\n", stm.tm_year);
49 if(verbose>1) printf(" hour=%d\n", stm.tm_hour);
50 /* ECAT 7 main header saves int, not time_t (long int),
51 therefore checking whether time can be saved correctly */
52 t=timegm(&stm);
53 h->scan_start_time=timegm(&stm);
54 if(t!=(time_t)h->scan_start_time) {
55 /* no it can't be saved as required; set negative time as time base */
56 if(t<(time_t)0) h->scan_start_time=0;
57 else return(2); /* if too far in future, return error */
58 }
59 if(verbose>1) printf(" scan_start_time := %d\n", h->scan_start_time);
60 if(h->scan_start_time==-1) h->scan_start_time=0; //return(2);
61 } else if(strcmp(field, "isotope_name")==0) {
62 strlcpy(h->isotope_name, value, 8);
63 } else if(strcmp(field, "isotope_halflife")==0) {
64 if(f<=1.0E-3) return(2); else h->isotope_halflife=f;
65 } else if(strcmp(field, "radiopharmaceutical")==0) {
66 strlcpy(h->radiopharmaceutical, value, 32);
67 } else if(strcmp(field, "gantry_tilt")==0) {
68 h->gantry_tilt=f;
69 } else if(strcmp(field, "gantry_rotation")==0) {
70 h->gantry_rotation=f;
71 } else if(strcmp(field, "bed_elevation")==0) {
72 h->bed_elevation=f;
73 } else if(strcmp(field, "intrinsic_tilt")==0) {
74 h->intrinsic_tilt=f;
75 } else if(strcmp(field, "wobble_speed")==0) {
76 h->wobble_speed=si;
77 } else if(strcmp(field, "transm_source_type")==0) {
79 } else if(strcmp(field, "distance_scanned")==0) {
81 } else if(strcmp(field, "transaxial_fov")==0) {
82 h->transaxial_fov=f;
83 } else if(strcmp(field, "angular_compression")==0) {
85 } else if(strcmp(field, "coin_samp_mode")==0) {
86 h->coin_samp_mode=si;
87 } else if(strcmp(field, "axial_samp_mode")==0) {
88 h->axial_samp_mode=si;
89 } else if(strcmp(field, "ecat_calibration_factor")==0) {
91 } else if(strcmp(field, "calibration_units")==0) {
93 } else if(strcmp(field, "calibration_units_label")==0) {
95 } else if(strcmp(field, "compression_code")==0) {
96 h->compression_code=si;
97 } else if(strcmp(field, "study_type")==0) {
98 strlcpy(h->study_type, value, 12);
99 } else if(strcmp(field, "patient_id")==0) {
100 strlcpy(h->patient_id, value, 16);
101 } else if(strcmp(field, "patient_name")==0) {
102 strlcpy(h->patient_name, value, 32);
103 } else if(strcmp(field, "patient_sex")==0) {
104 h->patient_sex=value[0];
105 } else if(strcmp(field, "patient_dexterity")==0) {
106 h->patient_dexterity=value[0];
107 } else if(strcmp(field, "patient_age")==0) {
108 h->patient_age=f;
109 } else if(strcmp(field, "patient_height")==0) {
110 h->patient_height=f;
111 } else if(strcmp(field, "patient_weight")==0) {
112 h->patient_weight=f;
113 } else if(strcmp(field, "patient_birth_date")==0) {
114 struct tm st;
115 time_t timet;
116 timet=time(NULL); gmtime_r(&timet, &st);
117 if(sscanf(value, "%d-%d-%d", &yy, &mm, &dd)!=3) return(2);
118 st.tm_mday=dd; st.tm_mon=mm-1; st.tm_year=yy-1900;
119 st.tm_hour=12; st.tm_min=0; st.tm_sec=0; st.tm_isdst=-1;
121 } else if(strcmp(field, "physician_name")==0) {
122 strlcpy(h->physician_name, value, 32);
123 } else if(strcmp(field, "operator_name")==0) {
124 strlcpy(h->operator_name, value, 32);
125 } else if(strcmp(field, "study_description")==0) {
126 strlcpy(h->study_description, value, 32);
127 } else if(strcmp(field, "acquisition_type")==0) {
128 h->acquisition_type=si;
129 } else if(strcmp(field, "patient_orientation")==0) {
131 } else if(strcmp(field, "facility_name")==0) {
132 strlcpy(h->facility_name, value, 20);
133 } else if(strcmp(field, "num_planes")==0) {
134 h->num_planes=si;
135 } else if(strcmp(field, "num_frames")==0) {
136 h->num_frames=si;
137 } else if(strcmp(field, "num_gates")==0) {
138 h->num_gates=si;
139 } else if(strcmp(field, "num_bed_pos")==0) {
140 h->num_bed_pos=si;
141 } else if(strcmp(field, "init_bed_position")==0) {
143 } else if(strcmp(field, "bed_position")==0) {
144 sscanf(value, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
145 h->bed_position+0, h->bed_position+1, h->bed_position+2,
146 h->bed_position+3, h->bed_position+4, h->bed_position+5,
147 h->bed_position+6, h->bed_position+7, h->bed_position+8,
148 h->bed_position+9, h->bed_position+10, h->bed_position+11,
149 h->bed_position+12, h->bed_position+13, h->bed_position+14
150 );
151 } else if(strcmp(field, "plane_separation")==0) {
152 h->plane_separation=f;
153 } else if(strcmp(field, "lwr_sctr_thres")==0) {
154 h->lwr_sctr_thres=si;
155 } else if(strcmp(field, "lwr_true_thres")==0) {
156 h->lwr_true_thres=si;
157 } else if(strcmp(field, "upr_true_thres")==0) {
158 h->upr_true_thres=si;
159 } else if(strcmp(field, "user_process_code")==0) {
160 strlcpy(h->user_process_code, value, 10);
161 } else if(strcmp(field, "acquisition_mode")==0) {
162 h->acquisition_mode=si;
163 } else if(strcmp(field, "bin_size")==0) {
164 h->bin_size=f;
165 } else if(strcmp(field, "branching_fraction")==0) {
167 } else if(strcmp(field, "dose_start_time")==0) {
168 struct tm stm;
169 if(get_datetime(value, &stm, verbose-1)!=0) return(2);
170 h->dose_start_time=timegm(&stm);
171 } else if(strcmp(field, "dosage")==0) {
172 h->dosage=f;
173 } else if(strcmp(field, "well_counter_corr_factor")==0) {
175 } else if(strcmp(field, "data_units")==0) {
176 strlcpy(h->data_units, value, 32);
177 } else if(strcmp(field, "septa_state")==0) {
178 h->septa_state=si;
179 } else if(strncasecmp(field, "FILL_CTI", 8)==0) {
180 char *cptr;
181 cptr=strtok(value, " \t,;\n\r");
182 for(int i=0; i<6; i++) {
183 if(cptr==NULL) break;
184 h->fill_cti[i]=(short int)atoi(cptr);
185 cptr=strtok(NULL, " \t,;\n\r");
186 }
187 } else
188 return(1);
189
190 return(0);
191}
192/*****************************************************************************/
193
194/*****************************************************************************/
203 char *field,
205 char *value,
207 int verbose
208) {
209 int i, ii;
210 short int si;
211 float f;
212 char *cptr;
213
214 if(verbose>0) printf("ecat7EditSHeader('%s', '%s')\n", field, value);
215
216 si=atoi(value); ii=atoi(value); f=atof(value);
217
218 if(strcasecmp(field, "DATA_TYPE")==0) {
219 h->data_type=si;
220 } else if(strcasecmp(field, "NUM_DIMENSIONS")==0) {
221 h->num_dimensions=si;
222 } else if(strcasecmp(field, "NUM_R_ELEMENTS")==0) {
223 h->num_r_elements=si;
224 } else if(strcasecmp(field, "NUM_ANGLES")==0) {
225 h->num_angles=si;
226 } else if(strcasecmp(field, "CORRECTIONS_APPLIED")==0) {
228 } else if(strncasecmp(field, "NUM_Z_ELEMENTS", 14)==0) {
229 cptr=strtok(value, " \t,;\n\r");
230 for(i=0; i<64; i++) {
231 if(cptr==NULL) break;
232 h->num_z_elements[i]=(short int)atoi(cptr);
233 cptr=strtok(NULL, " \t,;\n\r");
234 }
235 } else if(strcasecmp(field, "RING_DIFFERENCE")==0) {
236 h->ring_difference=si;
237 } else if(strcasecmp(field, "STORAGE_ORDER")==0) {
238 h->storage_order=si;
239 } else if(strcasecmp(field, "AXIAL_COMPRESSION")==0) {
240 h->axial_compression=si;
241 } else if(strcasecmp(field, "X_RESOLUTION")==0) {
242 h->x_resolution=f;
243 } else if(strcasecmp(field, "V_RESOLUTION")==0) {
244 h->v_resolution=f;
245 } else if(strcasecmp(field, "Z_RESOLUTION")==0) {
246 h->z_resolution=f;
247 } else if(strcasecmp(field, "W_RESOLUTION")==0) {
248 h->w_resolution=f;
249 } else if(strncasecmp(field, "FILL_GATE", 9)==0) {
250 cptr=strtok(value, " \t,;\n\r");
251 for(i=0; i<6; i++) {
252 if(cptr==NULL) break;
253 h->fill_gate[i]=(short int)atoi(cptr);
254 cptr=strtok(NULL, " \t,;\n\r");
255 }
256 } else if(strcasecmp(field, "GATE_DURATION")==0) {
257 h->gate_duration=ii;
258 } else if(strcasecmp(field, "R_WAVE_OFFSET")==0) {
259 h->r_wave_offset=ii;
260 } else if(strcasecmp(field, "NUM_ACCEPTED_BEATS")==0) {
261 h->num_accepted_beats=ii;
262 } else if(strcasecmp(field, "SCALE_FACTOR")==0) {
263 h->scale_factor=f;
264 } else if(strcasecmp(field, "SCAN_MIN")==0) {
265 h->scan_min=si;
266 } else if(strcasecmp(field, "SCAN_MAX")==0) {
267 h->scan_max=si;
268 } else if(strcasecmp(field, "PROMPTS")==0) {
269 h->prompts=ii;
270 } else if(strcasecmp(field, "DELAYED")==0) {
271 h->delayed=ii;
272 } else if(strcasecmp(field, "MULTIPLES")==0) {
273 h->multiples=ii;
274 } else if(strcasecmp(field, "NET_TRUES")==0) {
275 h->net_trues=ii;
276 } else if(strcasecmp(field, "TOT_AVG_COR")==0) {
277 h->tot_avg_cor=f;
278 } else if(strcasecmp(field, "TOT_AVG_UNCOR")==0) {
279 h->tot_avg_uncor=f;
280 } else if(strcasecmp(field, "TOTAL_COIN_RATE")==0) {
281 h->total_coin_rate=ii;
282 } else if(strcasecmp(field, "FRAME_START_TIME")==0) {
283 h->frame_start_time=ii;
284 } else if(strcasecmp(field, "FRAME_DURATION")==0) {
285 h->frame_duration=ii;
286 } else if(strcasecmp(field, "DEADTIME_CORRECTION_FACTOR")==0) {
288 } else if(strncasecmp(field, "FILL_CTI", 8)==0) {
289 cptr=strtok(value, " \t,;\n\r");
290 for(i=0; i<90; i++) {
291 if(cptr==NULL) break;
292 h->fill_cti[i]=(short int)atoi(cptr);
293 cptr=strtok(NULL, " \t,;\n\r");
294 }
295 } else if(strncasecmp(field, "FILL_USER", 9)==0) {
296 cptr=strtok(value, " \t,;\n\r");
297 for(i=0; i<50; i++) {
298 if(cptr==NULL) break;
299 h->fill_user[i]=(short int)atoi(cptr);
300 cptr=strtok(NULL, " \t,;\n\r");
301 }
302 } else if(strncasecmp(field, "UNCOR_SINGLES", 13)==0) {
303 cptr=strtok(value, " \t,;\n\r");
304 for(i=0; i<128; i++) {
305 if(cptr==NULL) break;
306 h->fill_user[i]=(float)atof(cptr);
307 cptr=strtok(NULL, " \t,;\n\r");
308 }
309 } else
310 return(1);
311 return(0);
312}
313/*****************************************************************************/
314
315/*****************************************************************************/
324 char *field,
326 char *value,
328 int verbose
329) {
330 int ii;
331 short int si;
332 float f;
333
334 if(verbose>0) printf("ecat7EditVHeader('%s', '%s')\n", field, value);
335
336 si=atoi(value); ii=atoi(value); f=atof(value);
337
338 if(strcasecmp(field, "DATA_TYPE")==0) {
339 h->data_type=si;
340 } else if(strcasecmp(field, "NUM_DIMENSIONS")==0) {
341 h->num_dimensions=si;
342 } else if(strcasecmp(field, "X_DIMENSION")==0) {
343 h->x_dimension=si;
344 } else if(strcasecmp(field, "Y_DIMENSION")==0) {
345 h->y_dimension=si;
346 } else if(strcasecmp(field, "Z_DIMENSION")==0) {
347 h->z_dimension=si;
348 } else if(strcasecmp(field, "X_OFFSET")==0) {
349 h->x_offset=f;
350 } else if(strcasecmp(field, "Y_OFFSET")==0) {
351 h->y_offset=f;
352 } else if(strcasecmp(field, "Z_OFFSET")==0) {
353 h->z_offset=f;
354 } else if(strcasecmp(field, "RECON_ZOOM")==0) {
355 h->recon_zoom=f;
356 } else if(strcasecmp(field, "SCALE_FACTOR")==0) {
357 h->scale_factor=f;
358 } else if(strcasecmp(field, "IMAGE_MIN")==0) {
359 h->image_min=si;
360 } else if(strcasecmp(field, "IMAGE_MAX")==0) {
361 h->image_max=si;
362 } else if(strcasecmp(field, "X_PIXEL_SIZE")==0) {
363 h->x_pixel_size=f;
364 } else if(strcasecmp(field, "Y_PIXEL_SIZE")==0) {
365 h->y_pixel_size=f;
366 } else if(strcasecmp(field, "Z_PIXEL_SIZE")==0) {
367 h->z_pixel_size=f;
368 } else if(strcasecmp(field, "FRAME_DURATION")==0) {
369 h->frame_duration=ii;
370 } else if(strcasecmp(field, "FRAME_START_TIME")==0) {
371 h->frame_start_time=ii;
372 } else if(strcasecmp(field, "FILTER_CODE")==0) {
373 h->filter_code=si;
374 } else if(strcasecmp(field, "X_RESOLUTION")==0) {
375 h->x_resolution=f;
376 } else if(strcasecmp(field, "Y_RESOLUTION")==0) {
377 h->y_resolution=f;
378 } else if(strcasecmp(field, "Z_RESOLUTION")==0) {
379 h->z_resolution=f;
380 } else if(strcasecmp(field, "NUM_R_ELEMENTS")==0) {
381 h->num_r_elements=f;
382 } else if(strcasecmp(field, "NUM_ANGLES")==0) {
383 h->num_angles=f;
384 } else if(strcasecmp(field, "Z_ROTATION_ANGLE")==0) {
385 h->z_rotation_angle=f;
386 } else if(strcasecmp(field, "DECAY_CORR_FCTR")==0) {
387 h->decay_corr_fctr=f;
388 } else if(strcasecmp(field, "PROCESSING_CODE")==0) {
389 h->processing_code=ii;
390 } else if(strcasecmp(field, "GATE_DURATION")==0) {
391 h->gate_duration=ii;
392 } else if(strcasecmp(field, "R_WAVE_OFFSET")==0) {
393 h->r_wave_offset=ii;
394 } else if(strcasecmp(field, "NUM_ACCEPTED_BEATS")==0) {
395 h->num_accepted_beats=ii;
396 } else if(strcasecmp(field, "FILTER_CUTOFF_FREQUENCY")==0) {
398 } else if(strcasecmp(field, "FILTER_RESOLUTION")==0) {
400 } else if(strcasecmp(field, "FILTER_RAMP_SLOPE")==0) {
402 } else if(strcasecmp(field, "FILTER_ORDER")==0) {
403 h->filter_order=f;
404 } else if(strcasecmp(field, "FILTER_SCATTER_FRACTION")==0) {
406 } else if(strcasecmp(field, "FILTER_SCATTER_SLOPE")==0) {
408 } else if(strcasecmp(field, "ANNOTATION")==0) {
409 strlcpy(h->annotation, value, 40);
410 } else if(strcasecmp(field, "MT_1_1")==0) {
411 h->mt_1_1=f;
412 } else if(strcasecmp(field, "MT_1_2")==0) {
413 h->mt_1_2=f;
414 } else if(strcasecmp(field, "MT_1_3")==0) {
415 h->mt_1_3=f;
416 } else if(strcasecmp(field, "MT_2_1")==0) {
417 h->mt_2_1=f;
418 } else if(strcasecmp(field, "MT_2_2")==0) {
419 h->mt_2_2=f;
420 } else if(strcasecmp(field, "MT_2_3")==0) {
421 h->mt_2_3=f;
422 } else if(strcasecmp(field, "MT_3_1")==0) {
423 h->mt_3_1=f;
424 } else if(strcasecmp(field, "MT_3_2")==0) {
425 h->mt_3_2=f;
426 } else if(strcasecmp(field, "MT_3_3")==0) {
427 h->mt_3_3=f;
428 } else if(strcasecmp(field, "RFILTER_CUTOFF")==0) {
429 h->rfilter_cutoff=f;
430 } else if(strcasecmp(field, "RFILTER_RESOLUTION")==0) {
432 } else if(strcasecmp(field, "RFILTER_CODE")==0) {
433 h->rfilter_code=si;
434 } else if(strcasecmp(field, "RFILTER_ORDER")==0) {
435 h->rfilter_order=si;
436 } else if(strcasecmp(field, "ZFILTER_CUTOFF")==0) {
437 h->zfilter_cutoff=f;
438 } else if(strcasecmp(field, "ZFILTER_RESOLUTION")==0) {
440 } else if(strcasecmp(field, "ZFILTER_CODE")==0) {
441 h->zfilter_code=si;
442 } else if(strcasecmp(field, "ZFILTER_ORDER")==0) {
443 h->zfilter_order=si;
444 } else if(strcasecmp(field, "MT_1_4")==0) {
445 h->mt_1_4=f;
446 } else if(strcasecmp(field, "MT_2_4")==0) {
447 h->mt_2_4=f;
448 } else if(strcasecmp(field, "MT_3_4")==0) {
449 h->mt_3_4=f;
450 } else if(strcasecmp(field, "SCATTER_TYPE")==0) {
451 h->scatter_type=si;
452 } else if(strcasecmp(field, "RECON_TYPE")==0) {
453 h->recon_type=si;
454 } else if(strcasecmp(field, "RECON_VIEWS")==0) {
455 h->recon_views=si;
456 } else if(strncasecmp(field, "FILL_CTI", 8)==0) {
457 char *cptr;
458 cptr=strtok(value, " \t,;\n\r");
459 for(int i=0; i<87; i++) {
460 if(cptr==NULL) break;
461 h->fill_cti[i]=(short int)atoi(cptr);
462 cptr=strtok(NULL, " \t,;\n\r");
463 }
464 } else if(strncasecmp(field, "FILL_USER", 9)==0) {
465 char *cptr;
466 cptr=strtok(value, " \t,;\n\r");
467 for(int i=0; i<50; i++) {
468 if(cptr==NULL) break;
469 h->fill_user[i]=(short int)atoi(cptr);
470 cptr=strtok(NULL, " \t,;\n\r");
471 }
472 } else
473 return(1);
474
475 return(0);
476}
477/*****************************************************************************/
478
479/*****************************************************************************/
480
int get_datetime(char *str, struct tm *date, int verbose)
Definition datetime.c:322
time_t timegm(struct tm *tm)
Inverse of gmtime, converting struct tm to time_t.
Definition datetime.c:69
struct tm * gmtime_r(const time_t *t, struct tm *tm)
Convert time_t to GMT struct tm.
Definition datetime.c:22
int ecat7EditMHeader(ECAT7_mainheader *h, char *field, char *value, int verbose)
Definition ecat7h.c:16
char ecat7errmsg[128]
Definition ecat7h.c:7
int ecat7EditSHeader(ECAT7_scanheader *h, char *field, char *value, int verbose)
Definition ecat7h.c:199
int ecat7EditVHeader(ECAT7_imageheader *h, char *field, char *value, int verbose)
Definition ecat7h.c:320
int ECAT7_TEST
Definition ecat7h.c:6
Header file for libtpcimgio.
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
short int fill_cti[87]
float filter_scatter_fraction
short int filter_code
short int image_max
short int image_min
short int zfilter_order
short int fill_user[49]
short int rfilter_code
float filter_cutoff_frequency
short int zfilter_code
short int filter_order
short int y_dimension
short int z_dimension
short int recon_type
short int scatter_type
short int recon_views
short int num_dimensions
short int rfilter_order
short int x_dimension
short int data_type
short int file_type
short int compression_code
float bed_position[15]
short int system_type
char facility_name[20]
short int num_frames
char operator_name[32]
short int coin_samp_mode
char data_units[32]
char magic_number[14]
float well_counter_corr_factor
char study_type[12]
char user_process_code[10]
short int angular_compression
short int calibration_units
char patient_name[32]
short int fill_cti[6]
short int septa_state
short int num_gates
short int num_planes
short int lwr_true_thres
char physician_name[32]
short int wobble_speed
short int acquisition_mode
short int calibration_units_label
char serial_number[10]
short int num_bed_pos
float ecat_calibration_factor
short int sw_version
short int transm_source_type
short int acquisition_type
char study_description[32]
short int axial_samp_mode
char patient_id[16]
char radiopharmaceutical[32]
short int patient_orientation
short int upr_true_thres
short int lwr_sctr_thres
char original_file_name[32]
short int scan_min
short int num_r_elements
short int num_angles
short int data_type
float deadtime_correction_factor
short int fill_cti[90]
short int num_dimensions
short int axial_compression
short int fill_gate[6]
short int storage_order
short int scan_max
short int num_z_elements[64]
short int fill_user[50]
short int ring_difference
short int corrections_applied