My Project
Functions
ecat7w.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include "swap.h"
#include "petc99.h"
#include "include/ecat7.h"
Include dependency graph for ecat7w.c:

Go to the source code of this file.

Functions

int ecat7WriteMainheader (FILE *fp, ECAT7_mainheader *h)
 
int ecat7WriteImageheader (FILE *fp, int blk, ECAT7_imageheader *h)
 
int ecat7WriteAttenheader (FILE *fp, int blk, ECAT7_attenheader *h)
 
int ecat7WritePolmapheader (FILE *fp, int blk, ECAT7_polmapheader *h)
 
int ecat7WriteNormheader (FILE *fp, int blk, ECAT7_normheader *h)
 
int ecat7WriteScanheader (FILE *fp, int blk, ECAT7_scanheader *h)
 
int ecat7Write2DScanheader (FILE *fp, int blk, ECAT7_2Dscanheader *h)
 
int ecat7Write2DNormheader (FILE *fp, int blk, ECAT7_2Dnormheader *h)
 
FILE * ecat7Create (const char *fname, ECAT7_mainheader *h)
 
int ecat7_is_scaling_needed (float amax, float *data, int nr)
 
int ecat7WriteImageMatrix (FILE *fp, int matrix_id, ECAT7_imageheader *h, float *fdata)
 
int ecat7Write2DScanMatrix (FILE *fp, int matrix_id, ECAT7_2Dscanheader *h, float *fdata)
 
int ecat7WriteScanMatrix (FILE *fp, int matrix_id, ECAT7_scanheader *h, float *fdata)
 
int ecat7WritePolarmapMatrix (FILE *fp, int matrix_id, ECAT7_polmapheader *h, float *fdata)
 
int ecat7WriteMatrixdata (FILE *fp, int start_block, char *data, int pxl_nr, int pxl_size)
 

Function Documentation

◆ ecat7_is_scaling_needed()

int ecat7_is_scaling_needed ( float  amax,
float *  data,
int  nr 
)

Check if pixel float values need to be scaled to be saved as short ints, or if they are already all very close to integers.

Parameters
amaxabsolute maximum value
datafloat array
nrfloat array size
Returns
1, if scaling is necessary, and 0 if not.

Definition at line 657 of file ecat7w.c.

Referenced by ecat7Write2DScanMatrix(), ecat7WriteImageMatrix(), ecat7WritePolarmapMatrix(), and ecat7WriteScanMatrix().

◆ ecat7Create()

FILE* ecat7Create ( const char *  fname,
ECAT7_mainheader h 
)

Create a new ECAT 7.x file. If file exists, it is renamed as fname% if possible. Directory list is written in big endian byte order.

Parameters
fnamefilename
hEcat7 main header
Returns
file pointer or NULL in case of an error.

Definition at line 616 of file ecat7w.c.

References BACKUP_EXTENSION, ECAT7_TEST, ecat7WriteMainheader(), MatBLKSIZE, and MatFirstDirBlk.

Referenced by imgWrite2DEcat7(), imgWriteEcat7(), imgWriteEcat7Frame(), and imgWritePolarmap().

Here is the call graph for this function:

◆ ecat7Write2DNormheader()

int ecat7Write2DNormheader ( FILE *  fp,
int  blk,
ECAT7_2Dnormheader h 
)

◆ ecat7Write2DScanheader()

int ecat7Write2DScanheader ( FILE *  fp,
int  blk,
ECAT7_2Dscanheader h 
)

Write ECAT 7.x 2D scan header

Parameters
fpoutput file pointer
blkheader block number, blk >= 2
hEcat7 2D scan header
Returns
0 in case of success, 1 == invalid parameters, 4 == file pointer is at wrong position, 5 == writing of MatBLKSIZE bytes was not success

Definition at line 499 of file ecat7w.c.

References ecat7_2Dscanheader::cor_singles, ecat7_2Dscanheader::corrections_applied, ecat7_2Dscanheader::data_type, ecat7_2Dscanheader::deadtime_correction_factor, ecat7_2Dscanheader::delayed, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7_2Dscanheader::fill_cti, ecat7_2Dscanheader::fill_gate, ecat7_2Dscanheader::fill_user, ecat7_2Dscanheader::frame_duration, ecat7_2Dscanheader::frame_start_time, ecat7_2Dscanheader::gate_duration, MatBLKSIZE, ecat7_2Dscanheader::multiples, ecat7_2Dscanheader::net_trues, ecat7_2Dscanheader::num_accepted_beats, ecat7_2Dscanheader::num_angles, ecat7_2Dscanheader::num_dimensions, ecat7_2Dscanheader::num_r_elements, ecat7_2Dscanheader::num_z_elements, ecat7_2Dscanheader::physical_planes, ecat7_2Dscanheader::prompts, ecat7_2Dscanheader::r_wave_offset, ecat7_2Dscanheader::ring_difference, ecat7_2Dscanheader::scale_factor, ecat7_2Dscanheader::scan_max, ecat7_2Dscanheader::scan_min, ecat7_2Dscanheader::tot_avg_cor, ecat7_2Dscanheader::tot_avg_uncor, ecat7_2Dscanheader::total_coin_rate, ecat7_2Dscanheader::uncor_singles, ecat7_2Dscanheader::w_resolution, ecat7_2Dscanheader::x_resolution, ecat7_2Dscanheader::y_resolution, and ecat7_2Dscanheader::z_resolution.

Referenced by ecat7Write2DScanMatrix().

◆ ecat7Write2DScanMatrix()

int ecat7Write2DScanMatrix ( FILE *  fp,
int  matrix_id,
ECAT7_2Dscanheader h,
float *  fdata 
)

Write ECAT 7.x 2D sinogram matrix header and data

Parameters
fpoutput file pointer
matrix_idcoded matrix id
hEcat7 2D image scan header
fdatafloat data to be written
Returns
0 if ok.

Definition at line 767 of file ecat7w.c.

References ecat7_2Dscanheader::data_type, ecat7_is_scaling_needed(), ECAT7_SUNI2, ECAT7_TEST, ecat7EnterMatrix(), ecat7errmsg, ecat7pxlbytes(), ecat7Write2DScanheader(), ecat7WriteMatrixdata(), MatBLKSIZE, ecat7_2Dscanheader::num_angles, ecat7_2Dscanheader::num_dimensions, ecat7_2Dscanheader::num_r_elements, ecat7_2Dscanheader::num_z_elements, ecat7_2Dscanheader::scale_factor, ecat7_2Dscanheader::scan_max, and ecat7_2Dscanheader::scan_min.

Referenced by imgWrite2DEcat7(), and imgWriteEcat7Frame().

Here is the call graph for this function:

◆ ecat7WriteAttenheader()

int ecat7WriteAttenheader ( FILE *  fp,
int  blk,
ECAT7_attenheader h 
)

◆ ecat7WriteImageheader()

int ecat7WriteImageheader ( FILE *  fp,
int  blk,
ECAT7_imageheader h 
)

Write ECAT 7.x image header. Changes data type to big endian.

Parameters
fpoutput file pointer
blkheader block number, blk >= 2
hEcat7 image header
Returns
0 in case of success, 1 == invalid parameters, 4 == file pointer is at wrong position, 5 == writing of MatBLKSIZE bytes was not success

Definition at line 164 of file ecat7w.c.

References ecat7_imageheader::annotation, ecat7_imageheader::data_type, ecat7_imageheader::decay_corr_fctr, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7_imageheader::fill_cti, ecat7_imageheader::fill_user, ecat7_imageheader::filter_code, ecat7_imageheader::filter_cutoff_frequency, ecat7_imageheader::filter_order, ecat7_imageheader::filter_ramp_slope, ecat7_imageheader::filter_resolution, ecat7_imageheader::filter_scatter_fraction, ecat7_imageheader::filter_scatter_slope, ecat7_imageheader::frame_duration, ecat7_imageheader::frame_start_time, ecat7_imageheader::gate_duration, ecat7_imageheader::image_max, ecat7_imageheader::image_min, MatBLKSIZE, ecat7_imageheader::mt_1_1, ecat7_imageheader::mt_1_2, ecat7_imageheader::mt_1_3, ecat7_imageheader::mt_1_4, ecat7_imageheader::mt_2_1, ecat7_imageheader::mt_2_2, ecat7_imageheader::mt_2_3, ecat7_imageheader::mt_2_4, ecat7_imageheader::mt_3_1, ecat7_imageheader::mt_3_2, ecat7_imageheader::mt_3_3, ecat7_imageheader::mt_3_4, ecat7_imageheader::num_accepted_beats, ecat7_imageheader::num_angles, ecat7_imageheader::num_dimensions, ecat7_imageheader::num_r_elements, ecat7_imageheader::processing_code, ecat7_imageheader::r_wave_offset, ecat7_imageheader::recon_type, ecat7_imageheader::recon_views, ecat7_imageheader::recon_zoom, ecat7_imageheader::rfilter_code, ecat7_imageheader::rfilter_cutoff, ecat7_imageheader::rfilter_order, ecat7_imageheader::rfilter_resolution, ecat7_imageheader::scale_factor, ecat7_imageheader::scatter_type, ecat7_imageheader::x_dimension, ecat7_imageheader::x_offset, ecat7_imageheader::x_pixel_size, ecat7_imageheader::x_resolution, ecat7_imageheader::y_dimension, ecat7_imageheader::y_offset, ecat7_imageheader::y_pixel_size, ecat7_imageheader::y_resolution, ecat7_imageheader::z_dimension, ecat7_imageheader::z_offset, ecat7_imageheader::z_pixel_size, ecat7_imageheader::z_resolution, ecat7_imageheader::z_rotation_angle, ecat7_imageheader::zfilter_code, ecat7_imageheader::zfilter_cutoff, ecat7_imageheader::zfilter_order, and ecat7_imageheader::zfilter_resolution.

Referenced by ecat7WriteImageMatrix().

◆ ecat7WriteImageMatrix()

int ecat7WriteImageMatrix ( FILE *  fp,
int  matrix_id,
ECAT7_imageheader h,
float *  fdata 
)

Write ECAT 7.x image or volume matrix header and data

Parameters
fpoutput file pointer
matrix_idcoded matrix id
hEcat7 image header
fdatafloat data to be written
Returns
0 if ok.

Definition at line 682 of file ecat7w.c.

References ecat7_imageheader::data_type, ecat7_is_scaling_needed(), ECAT7_SUNI2, ECAT7_TEST, ecat7EnterMatrix(), ecat7errmsg, ecat7pxlbytes(), ecat7WriteImageheader(), ecat7WriteMatrixdata(), ecat7_imageheader::image_max, ecat7_imageheader::image_min, MatBLKSIZE, ecat7_imageheader::num_dimensions, ecat7_imageheader::scale_factor, ecat7_imageheader::x_dimension, ecat7_imageheader::y_dimension, and ecat7_imageheader::z_dimension.

Referenced by imgWrite2DEcat7(), imgWriteEcat7(), and imgWriteEcat7Frame().

Here is the call graph for this function:

◆ ecat7WriteMainheader()

int ecat7WriteMainheader ( FILE *  fp,
ECAT7_mainheader h 
)

Write ECAT 7.x main header.

Parameters
fpoutput file pointer
hEcat7 main header Writes header always in big endian byte order.
Returns
0 in case of success, 1 == invalid parameters, 4 == file pointer is at wrong position, 5 == writing of MatBLKSIZE bytes was not success

Definition at line 73 of file ecat7w.c.

References ecat7_mainheader::acquisition_mode, ecat7_mainheader::acquisition_type, ecat7_mainheader::angular_compression, ecat7_mainheader::axial_samp_mode, ecat7_mainheader::bed_elevation, ecat7_mainheader::bed_position, ecat7_mainheader::bin_size, ecat7_mainheader::branching_fraction, ecat7_mainheader::calibration_units, ecat7_mainheader::calibration_units_label, ecat7_mainheader::coin_samp_mode, ecat7_mainheader::compression_code, ecat7_mainheader::data_units, ecat7_mainheader::distance_scanned, ecat7_mainheader::dosage, ecat7_mainheader::dose_start_time, ECAT7_TEST, ecat7_mainheader::ecat_calibration_factor, ecat7_mainheader::facility_name, ecat7_mainheader::file_type, ecat7_mainheader::fill_cti, ecat7_mainheader::gantry_rotation, ecat7_mainheader::gantry_tilt, ecat7_mainheader::init_bed_position, ecat7_mainheader::intrinsic_tilt, ecat7_mainheader::isotope_halflife, ecat7_mainheader::isotope_name, ecat7_mainheader::lwr_sctr_thres, ecat7_mainheader::lwr_true_thres, ecat7_mainheader::magic_number, MatBLKSIZE, ecat7_mainheader::num_bed_pos, ecat7_mainheader::num_frames, ecat7_mainheader::num_gates, ecat7_mainheader::num_planes, ecat7_mainheader::operator_name, ecat7_mainheader::original_file_name, ecat7_mainheader::patient_age, ecat7_mainheader::patient_birth_date, ecat7_mainheader::patient_dexterity, ecat7_mainheader::patient_height, ecat7_mainheader::patient_id, ecat7_mainheader::patient_name, ecat7_mainheader::patient_orientation, ecat7_mainheader::patient_sex, ecat7_mainheader::patient_weight, ecat7_mainheader::physician_name, ecat7_mainheader::plane_separation, ecat7_mainheader::radiopharmaceutical, ecat7_mainheader::scan_start_time, ecat7_mainheader::septa_state, ecat7_mainheader::serial_number, ecat7_mainheader::study_description, ecat7_mainheader::study_type, ecat7_mainheader::sw_version, ecat7_mainheader::system_type, ecat7_mainheader::transaxial_fov, ecat7_mainheader::transm_source_type, ecat7_mainheader::upr_true_thres, ecat7_mainheader::user_process_code, ecat7_mainheader::well_counter_corr_factor, and ecat7_mainheader::wobble_speed.

Referenced by ecat7Create(), and imgWriteEcat7Frame().

◆ ecat7WriteMatrixdata()

int ecat7WriteMatrixdata ( FILE *  fp,
int  start_block,
char *  data,
int  pxl_nr,
int  pxl_size 
)

Write ECAT 7.x matrix data to a specified file position. Data does not need to be allocated for full blocks. Data must be represented in current machines byte order, and it is always saved in big endian byte order.

Parameters
fpPointer to an opened ECAT file
start_blockBlock number where matrix data is written
dataPointer to matrix data
pxl_nrNumber of pixels
pxl_sizeSize of data for one pixel in bytes
Returns
>0 in case of an error.

Definition at line 1027 of file ecat7w.c.

References ECAT7_TEST, and MatBLKSIZE.

Referenced by ecat7Write2DScanMatrix(), ecat7WriteImageMatrix(), ecat7WritePolarmapMatrix(), and ecat7WriteScanMatrix().

◆ ecat7WriteNormheader()

int ecat7WriteNormheader ( FILE *  fp,
int  blk,
ECAT7_normheader h 
)

◆ ecat7WritePolarmapMatrix()

int ecat7WritePolarmapMatrix ( FILE *  fp,
int  matrix_id,
ECAT7_polmapheader h,
float *  fdata 
)

Write ECAT 7.x polarmap matrix header and data

Parameters
fpoutput file pointer
matrix_idcoded matrix information
hEcat7 polar map header
fdatafloat data
Returns
0 if ok.

Definition at line 939 of file ecat7w.c.

References ecat7_polmapheader::data_type, ecat7_is_scaling_needed(), ECAT7_SUNI2, ECAT7_TEST, ecat7EnterMatrix(), ecat7errmsg, ecat7pxlbytes(), ecat7WriteMatrixdata(), ecat7WritePolmapheader(), ecat7_polmapheader::image_max, ecat7_polmapheader::image_min, MatBLKSIZE, ecat7_polmapheader::num_rings, ecat7_polmapheader::scale_factor, and ecat7_polmapheader::sectors_per_ring.

Referenced by imgWriteEcat7Frame(), and imgWritePolarmap().

Here is the call graph for this function:

◆ ecat7WritePolmapheader()

int ecat7WritePolmapheader ( FILE *  fp,
int  blk,
ECAT7_polmapheader h 
)

◆ ecat7WriteScanheader()

int ecat7WriteScanheader ( FILE *  fp,
int  blk,
ECAT7_scanheader h 
)

Write ECAT 7.x 3D scan header (512 bytes) Changes data type to big endian.

Parameters
fppointer to output file
blkblock number, blk >= 2
hEcat7 scan header
Returns
0 in case of success, 1 == invalid parameters, 4 == file pointer is at wrong position, 5 == writing of MatBLKSIZE bytes was not success

Definition at line 433 of file ecat7w.c.

References ecat7_scanheader::axial_compression, ecat7_scanheader::corrections_applied, ecat7_scanheader::data_type, ecat7_scanheader::deadtime_correction_factor, ecat7_scanheader::delayed, ECAT7_IEEER4, ECAT7_SUNI2, ECAT7_SUNI4, ECAT7_TEST, ECAT7_VAXI2, ECAT7_VAXI4, ECAT7_VAXR4, ecat7_scanheader::fill_cti, ecat7_scanheader::fill_gate, ecat7_scanheader::fill_user, ecat7_scanheader::frame_duration, ecat7_scanheader::frame_start_time, ecat7_scanheader::gate_duration, MatBLKSIZE, ecat7_scanheader::multiples, ecat7_scanheader::net_trues, ecat7_scanheader::num_accepted_beats, ecat7_scanheader::num_angles, ecat7_scanheader::num_dimensions, ecat7_scanheader::num_r_elements, ecat7_scanheader::num_z_elements, ecat7_scanheader::prompts, ecat7_scanheader::r_wave_offset, ecat7_scanheader::ring_difference, ecat7_scanheader::scale_factor, ecat7_scanheader::scan_max, ecat7_scanheader::scan_min, ecat7_scanheader::storage_order, ecat7_scanheader::tot_avg_cor, ecat7_scanheader::tot_avg_uncor, ecat7_scanheader::total_coin_rate, ecat7_scanheader::uncor_singles, ecat7_scanheader::v_resolution, ecat7_scanheader::w_resolution, ecat7_scanheader::x_resolution, and ecat7_scanheader::z_resolution.

Referenced by ecat7WriteScanMatrix().

◆ ecat7WriteScanMatrix()

int ecat7WriteScanMatrix ( FILE *  fp,
int  matrix_id,
ECAT7_scanheader h,
float *  fdata 
)

Write ECAT 7.x 3D sinogram matrix header and data

Parameters
fpoutput file pointer
matrix_idcoded matrix id
hEcat7 scan header
fdatafloat data
Returns
0 if ok.

Definition at line 852 of file ecat7w.c.

References ecat7_scanheader::data_type, ecat7_is_scaling_needed(), ECAT7_SUNI2, ECAT7_TEST, ecat7EnterMatrix(), ecat7errmsg, ecat7pxlbytes(), ecat7WriteMatrixdata(), ecat7WriteScanheader(), MatBLKSIZE, ecat7_scanheader::num_angles, ecat7_scanheader::num_r_elements, ecat7_scanheader::num_z_elements, ecat7_scanheader::scale_factor, ecat7_scanheader::scan_max, and ecat7_scanheader::scan_min.

Referenced by imgWriteEcat7(), and imgWriteEcat7Frame().

Here is the call graph for this function: