My Project
Functions
ecat63w.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/ecat63.h"
Include dependency graph for ecat63w.c:

Go to the source code of this file.

Functions

int ecat63WriteMainheader (FILE *fp, ECAT63_mainheader *h)
 
int ecat63WriteImageheader (FILE *fp, int block, ECAT63_imageheader *h)
 
int ecat63WriteAttnheader (FILE *fp, int block, ECAT63_attnheader *h)
 
int ecat63WriteScanheader (FILE *fp, int block, ECAT63_scanheader *h)
 
int ecat63WriteNormheader (FILE *fp, int block, ECAT63_normheader *h)
 
FILE * ecat63Create (const char *fname, ECAT63_mainheader *h)
 
int ecat63WriteImage (FILE *fp, int matnum, ECAT63_imageheader *h, void *data)
 
int ecat63WriteScan (FILE *fp, int matnum, ECAT63_scanheader *h, void *data)
 
int ecat63WriteNorm (FILE *fp, int matnum, ECAT63_normheader *h, void *data)
 
int ecat63WriteAttn (FILE *fp, int matnum, ECAT63_attnheader *h, void *data)
 
int ecat63WriteMatdata (FILE *fp, int strtblk, char *data, int pxlNr, int pxlSize)
 
int ecat63_is_scaling_needed (float amax, float *data, int nr)
 
int ecat63WriteImageMatrix (FILE *fp, int matnum, ECAT63_imageheader *h, float *fdata)
 
int ecat63WriteScanMatrix (FILE *fp, int matnum, ECAT63_scanheader *h, float *fdata)
 
void ecat63wFloat (float *bufi, void *bufo, int tovax, int islittle)
 
void ecat63wInt (int *bufi, void *bufo, int tovax, int islittle)
 

Function Documentation

◆ ecat63_is_scaling_needed()

int ecat63_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
nrnumber of float values in flaot array
Returns
1 if scaling is necessary, and 0 if not.

Definition at line 672 of file ecat63w.c.

Referenced by ecat63WriteImageMatrix(), and ecat63WriteScanMatrix().

Here is the caller graph for this function:

◆ ecat63Create()

FILE* ecat63Create ( const char *  fname,
ECAT63_mainheader h 
)

Create a new ECAT 6.3 file and return file pointer or NULL in case of an error. If file exists, it is renamed as fname% if possible. Directory list is written in big endian byte order.

Parameters
fnamefile name
hEcat 6.3 main header
Returns
opened file pointer, or NULL in case of failure

Definition at line 386 of file ecat63w.c.

References BACKUP_EXTENSION, ECAT63_TEST, ecat63WriteMainheader(), MatBLKSIZE, and MatFirstDirBlk.

Referenced by ecat63AddImg(), ecat63WriteAllImg(), and imgWriteEcat63Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63wFloat()

void ecat63wFloat ( float *  bufi,
void *  bufo,
int  tovax,
int  islittle 
)

Writing ECAT 6.3 floats

Parameters
bufipointer to 4-byte long input (float data)
bufopointer to 4-byte long output
tovax1 for VAX format
islittle1 for little endian

Definition at line 863 of file ecat63w.c.

Referenced by ecat63WriteAttnheader(), ecat63WriteImageheader(), ecat63WriteMainheader(), ecat63WriteNormheader(), and ecat63WriteScanheader().

Here is the caller graph for this function:

◆ ecat63wInt()

void ecat63wInt ( int *  bufi,
void *  bufo,
int  tovax,
int  islittle 
)

Writing ECAT 6.3 32-bit ints. 32-bit int format is same in VAX and i386

Parameters
bufipointer to 4-byte long input (integer data)
bufopointer to 4-byte long output
tovax1 for VAX format
islittle1 for little endian

Definition at line 885 of file ecat63w.c.

Referenced by ecat63WriteImageheader(), and ecat63WriteScanheader().

Here is the caller graph for this function:

◆ ecat63WriteAttn()

int ecat63WriteAttn ( FILE *  fp,
int  matnum,
ECAT63_attnheader h,
void *  data 
)

Write ECAT 6.3 attenuation matrix header and data

Parameters
fptarget file pointer
matnummatrix number [1..number of matrixes]
hEcat 6.3 attenuation header
datapointer to data that is written
Returns
0 if ok, 1 invalid input or invalid image dimensions, 2 failed to resolve data type 3 too little data size, 4 failed to resolve next block size in file

Definition at line 576 of file ecat63w.c.

References BYTE_TYPE, ecat63_attnheader::data_type, ecat63_attnheader::dimension_1, ecat63_attnheader::dimension_2, ECAT63_TEST, ecat63Matenter(), ecat63WriteAttnheader(), ecat63WriteMatdata(), IEEE_R4, MatBLKSIZE, SUN_I2, SUN_I4, VAX_I2, VAX_I4, and VAX_R4.

Here is the call graph for this function:

◆ ecat63WriteAttnheader()

int ecat63WriteAttnheader ( FILE *  fp,
int  block,
ECAT63_attnheader h 
)

Write ECAT 6.3 attenuation header

Parameters
fptarget file pointer
blockblock number [>=3]
hEcat 6.3 attenuation header
Returns
0 if ok, 1 invalid input, 2 failed to find block, 3 failed to write block

Definition at line 221 of file ecat63w.c.

References ecat63_attnheader::attenuation_coeff, ecat63_attnheader::attenuation_type, ecat63_attnheader::data_type, ecat63_attnheader::dimension_1, ecat63_attnheader::dimension_2, ECAT63_TEST, ecat63wFloat(), MatBLKSIZE, ecat63_attnheader::sample_distance, ecat63_attnheader::scale_factor, ecat63_attnheader::tilt_angle, VAX_I2, VAX_I4, VAX_R4, ecat63_attnheader::x_origin, ecat63_attnheader::x_radius, ecat63_attnheader::y_origin, and ecat63_attnheader::y_radius.

Referenced by ecat63WriteAttn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteImage()

int ecat63WriteImage ( FILE *  fp,
int  matnum,
ECAT63_imageheader h,
void *  data 
)

Write ECAT 6.3 image matrix header and data

Parameters
fptarget file pointer
matnummatrix number [1..number of matrixes]
hEcat 6.3 image header
datapointer to data that is written
Returns
0 if ok, 1 invalid input or invalid image dimensions, 2 failed to resolve data type 3 too little data size, 4 failed to resolve next block size in file

Definition at line 429 of file ecat63w.c.

References BYTE_TYPE, ecat63_imageheader::data_type, ecat63_imageheader::dimension_1, ecat63_imageheader::dimension_2, ECAT63_TEST, ecat63Matenter(), ecat63WriteImageheader(), ecat63WriteMatdata(), IEEE_R4, MatBLKSIZE, SUN_I2, SUN_I4, VAX_I2, VAX_I4, and VAX_R4.

Referenced by ecat63AddImg(), and ecat63WriteAllImg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteImageheader()

int ecat63WriteImageheader ( FILE *  fp,
int  block,
ECAT63_imageheader h 
)

Write ECAT 6.3 image header

Parameters
fptarget file pointer
blockblock number [>= 3]
hEcat 6.3 image header
Returns
0, if ok, 1 invalid input, 2 failed to find block, 3 failed to write block

Definition at line 150 of file ecat63w.c.

References ecat63_imageheader::annotation, ecat63_imageheader::atten_cor_mat_num, ecat63_imageheader::data_type, ecat63_imageheader::decay_corr_fctr, ecat63_imageheader::dimension_1, ecat63_imageheader::dimension_2, ECAT63_TEST, ecat63wFloat(), ecat63wInt(), ecat63_imageheader::ecat_calibration_fctr, ecat63_imageheader::fill1, ecat63_imageheader::fill2, ecat63_imageheader::filter_code, ecat63_imageheader::filter_params, ecat63_imageheader::frame_duration, ecat63_imageheader::frame_start_time, ecat63_imageheader::image_max, ecat63_imageheader::image_min, ecat63_imageheader::image_rotation, ecat63_imageheader::intrinsic_tilt, ecat63_imageheader::loss_corr_fctr, MatBLKSIZE, ecat63_imageheader::norm_matrix_num, ecat63_imageheader::num_dimensions, ecat63_imageheader::pixel_size, ecat63_imageheader::plane_eff_corr_fctr, ecat63_imageheader::processing_code, ecat63_imageheader::quant_scale, ecat63_imageheader::quant_units, ecat63_imageheader::recon_scale, ecat63_imageheader::recon_start_day, ecat63_imageheader::recon_start_hour, ecat63_imageheader::recon_start_min, ecat63_imageheader::recon_start_month, ecat63_imageheader::recon_start_sec, ecat63_imageheader::recon_start_year, ecat63_imageheader::scan_matrix_num, ecat63_imageheader::slice_location, ecat63_imageheader::slice_width, VAX_I2, VAX_I4, VAX_R4, ecat63_imageheader::well_counter_cal_fctr, ecat63_imageheader::x_origin, and ecat63_imageheader::y_origin.

Referenced by ecat63WriteImage(), and ecat63WriteImageMatrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteImageMatrix()

int ecat63WriteImageMatrix ( FILE *  fp,
int  matnum,
ECAT63_imageheader h,
float *  fdata 
)

Write ECAT 6.3 image matrix header and data

Parameters
fptarget file pointer
matnum
hEcat 6.3 image header
fdata
Returns
0 if ok, 1 invalid input, 3 invalid matrix dimensions, 4 invalid block number, 5 failed to allocate memory, 8 failed to resolve new matrix block number, 10 failed to write image sub header, 13 failed to write matrix data

Definition at line 700 of file ecat63w.c.

References ecat63_imageheader::data_type, ecat63_imageheader::dimension_1, ecat63_imageheader::dimension_2, ecat63_is_scaling_needed(), ECAT63_TEST, ecat63errmsg, ecat63Matenter(), ecat63pxlbytes(), ecat63WriteImageheader(), ecat63WriteMatdata(), ecat63_imageheader::image_max, ecat63_imageheader::image_min, MatBLKSIZE, and ecat63_imageheader::quant_scale.

Referenced by imgWriteEcat63Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteMainheader()

int ecat63WriteMainheader ( FILE *  fp,
ECAT63_mainheader h 
)

Write ECAT 6.3 main header.

Parameters
fptarget file pointer
hEcat 6.3 main header
Returns
0, if ok, 1 invalid input, 2 failed to find block, 3 failed to write block

Definition at line 73 of file ecat63w.c.

References ecat63_mainheader::acquisition_type, ecat63_mainheader::axial_fov, ecat63_mainheader::axial_samp_mode, ecat63_mainheader::bed_elevation, ecat63_mainheader::bed_offset, ecat63_mainheader::bed_type, ecat63_mainheader::calibration_factor, ecat63_mainheader::calibration_units, ecat63_mainheader::coin_samp_mode, ecat63_mainheader::compression_code, ecat63_mainheader::data_type, ECAT63_TEST, ecat63wFloat(), ecat63_mainheader::facility_name, ecat63_mainheader::file_type, ecat63_mainheader::fill1, ecat63_mainheader::fill2, ecat63_mainheader::gantry_rotation, ecat63_mainheader::gantry_tilt, ecat63_mainheader::init_bed_position, ecat63_mainheader::isotope_code, ecat63_mainheader::isotope_halflife, ecat63_mainheader::lwr_sctr_thres, ecat63_mainheader::lwr_true_thres, MatBLKSIZE, ecat63_mainheader::node_id, ecat63_mainheader::num_bed_pos, ecat63_mainheader::num_frames, ecat63_mainheader::num_gates, ecat63_mainheader::num_planes, ecat63_mainheader::operator_name, ecat63_mainheader::original_file_name, ecat63_mainheader::patient_age, ecat63_mainheader::patient_dexterity, ecat63_mainheader::patient_height, ecat63_mainheader::patient_id, ecat63_mainheader::patient_name, ecat63_mainheader::patient_sex, ecat63_mainheader::patient_weight, ecat63_mainheader::physician_name, ecat63_mainheader::plane_separation, ecat63_mainheader::radiopharmaceutical, ecat63_mainheader::rot_source_speed, ecat63_mainheader::scan_start_day, ecat63_mainheader::scan_start_hour, ecat63_mainheader::scan_start_minute, ecat63_mainheader::scan_start_month, ecat63_mainheader::scan_start_second, ecat63_mainheader::scan_start_year, ecat63_mainheader::septa_type, ecat63_mainheader::study_description, ecat63_mainheader::study_name, ecat63_mainheader::sw_version, ecat63_mainheader::system_type, ecat63_mainheader::transaxial_fov, ecat63_mainheader::transaxial_samp_mode, ecat63_mainheader::transm_source_type, ecat63_mainheader::upr_true_thres, ecat63_mainheader::user_process_code, VAX_I2, VAX_I4, VAX_R4, and ecat63_mainheader::wobble_speed.

Referenced by ecat63AddImg(), ecat63Create(), and imgWriteEcat63Frame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteMatdata()

int ecat63WriteMatdata ( FILE *  fp,
int  strtblk,
char *  data,
int  pxlNr,
int  pxlSize 
)

Write ECAT 6.3 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. Give also nr of pixels and byte size of one pixel.

Parameters
fptarget file pointer
strtblkstarting image block [>=1]
datapointer to data that is written
pxlNrnumber of items to be written [>=1]
pxlSizesize of one data item in bytes [>=1]
Returns
0 if ok, 1 invalid input, 2 failed to find starting block, 3 failed to write data

Definition at line 629 of file ecat63w.c.

References ECAT63_TEST, and MatBLKSIZE.

Referenced by ecat63WriteAttn(), ecat63WriteImage(), ecat63WriteImageMatrix(), ecat63WriteNorm(), ecat63WriteScan(), and ecat63WriteScanMatrix().

Here is the caller graph for this function:

◆ ecat63WriteNorm()

int ecat63WriteNorm ( FILE *  fp,
int  matnum,
ECAT63_normheader h,
void *  data 
)

Write ECAT 6.3 normalization matrix header and data

Parameters
fptarget file pointer
matnummatrix number [1..number of matrixes]
hEcat 6.3 normalization header
datapointer to data that is written
Returns
0 if ok, 1 invalid input or invalid image dimensions, 2 failed to resolve data type 3 too little data size, 4 failed to resolve next block size in file

Definition at line 527 of file ecat63w.c.

References BYTE_TYPE, ecat63_normheader::data_type, ecat63_normheader::dimension_1, ecat63_normheader::dimension_2, ECAT63_TEST, ecat63Matenter(), ecat63WriteMatdata(), ecat63WriteNormheader(), IEEE_R4, MatBLKSIZE, SUN_I2, SUN_I4, VAX_I2, VAX_I4, and VAX_R4.

Here is the call graph for this function:

◆ ecat63WriteNormheader()

int ecat63WriteNormheader ( FILE *  fp,
int  block,
ECAT63_normheader h 
)

Write ECAT 6.3 normalization header

Parameters
fptarget file pointer
blockblock number [>=3]
hEcat 6.3 normalization header
Returns
0 if ok, 1 invalid input, 2 failed to find block, 3 failed to write block

Definition at line 336 of file ecat63w.c.

References ecat63_normheader::data_type, ecat63_normheader::dimension_1, ecat63_normheader::dimension_2, ECAT63_TEST, ecat63wFloat(), ecat63_normheader::fov_source_width, MatBLKSIZE, ecat63_normheader::norm_day, ecat63_normheader::norm_hour, ecat63_normheader::norm_minute, ecat63_normheader::norm_month, ecat63_normheader::norm_second, ecat63_normheader::norm_year, ecat63_normheader::scale_factor, VAX_I2, VAX_I4, and VAX_R4.

Referenced by ecat63WriteNorm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteScan()

int ecat63WriteScan ( FILE *  fp,
int  matnum,
ECAT63_scanheader h,
void *  data 
)

Write ECAT 6.3 sinogram matrix header and data

Parameters
fptarget file pointer
matnummatrix number [1..number of matrixes]
hEcat 6.3 scan header
datapointer to data that is written
Returns
0 if ok, 1 invalid input or invalid image dimensions, 2 failed to resolve data type 3 too little data size, 4 failed to resolve next block size in file

Definition at line 478 of file ecat63w.c.

References BYTE_TYPE, ecat63_scanheader::data_type, ecat63_scanheader::dimension_1, ecat63_scanheader::dimension_2, ECAT63_TEST, ecat63Matenter(), ecat63WriteMatdata(), ecat63WriteScanheader(), IEEE_R4, MatBLKSIZE, SUN_I2, SUN_I4, VAX_I2, VAX_I4, and VAX_R4.

Referenced by ecat63AddImg(), and ecat63WriteAllImg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecat63WriteScanheader()

int ecat63WriteScanheader ( FILE *  fp,
int  block,
ECAT63_scanheader h 
)

◆ ecat63WriteScanMatrix()

int ecat63WriteScanMatrix ( FILE *  fp,
int  matnum,
ECAT63_scanheader h,
float *  fdata 
)

Write ECAT 6.3 sinogram matrix header and data

Parameters
fptarget file pointer
matnummatrix number [1..number of matrixes]
hEcat 6.3 scan header
fdatamatrix data
Returns
0 if ok, 1 invalid input, 3 invalid matrix dimension, 4 invalid block number, 5 failed to allocate memory for data, 8 failed to resolve next block number, 10 cannot write sub header, 13 failed to write data

Definition at line 784 of file ecat63w.c.

References ecat63_scanheader::data_type, ecat63_scanheader::dimension_1, ecat63_scanheader::dimension_2, ecat63_is_scaling_needed(), ECAT63_TEST, ecat63errmsg, ecat63Matenter(), ecat63pxlbytes(), ecat63WriteMatdata(), ecat63WriteScanheader(), MatBLKSIZE, ecat63_scanheader::scale_factor, ecat63_scanheader::scan_max, and ecat63_scanheader::scan_min.

Referenced by imgWriteEcat63Frame().

Here is the call graph for this function:
Here is the caller graph for this function: