TPCCLIB
Loading...
Searching...
No Matches
dftunit.c File Reference

Setting DFT calibration unit. More...

#include "libtpccurveio.h"

Go to the source code of this file.

Functions

void dftUnitToDFT (DFT *dft, int dunit)
 
int dftUnitConversion (DFT *dft, int dunit)
 
int dftTimeunitToDFT (DFT *dft, const char *timeunit)
 
int dftTimeunitConversion (DFT *dft, int tunit)
 
void dftMin2sec (DFT *dft)
 
void dftSec2min (DFT *dft)
 

Detailed Description

Setting DFT calibration unit.

Author
Vesa Oikonen

Definition in file dftunit.c.

Function Documentation

◆ dftMin2sec()

void dftMin2sec ( DFT * dft)

Change time unit from min to sec, without checking original unit.

Definition at line 145 of file dftunit.c.

146{
147 int i;
148
149 for(i=0; i<dft->frameNr; i++) {
150 if(!isnan(dft->x[i])) dft->x[i]*=60.;
151 if(!isnan(dft->x1[i])) dft->x1[i]*=60.;
152 if(!isnan(dft->x1[i])) dft->x2[i]*=60.;
153 }
154 dft->timeunit=TUNIT_SEC;
155}
int timeunit
double * x1
double * x2
int frameNr
double * x

Referenced by copy_times_from_img_to_dft(), cptWrite(), and dftTimeunitConversion().

◆ dftSec2min()

void dftSec2min ( DFT * dft)

Change time unit from sec to min, without checking original unit.

Definition at line 160 of file dftunit.c.

161{
162 int i;
163
164 for(i=0; i<dft->frameNr; i++) {
165 if(!isnan(dft->x[i])) dft->x[i]/=60.;
166 if(!isnan(dft->x1[i])) dft->x1[i]/=60.;
167 if(!isnan(dft->x1[i])) dft->x2[i]/=60.;
168 }
169 dft->timeunit=TUNIT_MIN;
170}

Referenced by copy_times_from_img_to_dft(), cptReadOne(), and dftTimeunitConversion().

◆ dftTimeunitConversion()

int dftTimeunitConversion ( DFT * dft,
int tunit )

Conversion of the DFT timeunit. Changes both data values and timeunit code. Currently available conversions are: min <-> sec

Returns
Returns 0 if conversion was successful, and <> 0 if failed.
Parameters
dftPointer to existing DFT data, whose timeunit is to be changed
tunitNew timeunit code

Definition at line 119 of file dftunit.c.

124 {
125 /* Check the input */
126 if(dft==NULL || tunit<0) return(1);
127
128 /* Check if unit already is as required */
129 if(dft->timeunit==tunit) return(0);
130
131 /* Do the conversion, if supported */
132 if(dft->timeunit==TUNIT_MIN && tunit==TUNIT_SEC)
133 dftMin2sec(dft);
134 else if(dft->timeunit==TUNIT_SEC && tunit==TUNIT_MIN)
135 dftSec2min(dft);
136 else
137 return(2);
138
139 return(0);
140}
void dftSec2min(DFT *dft)
Definition dftunit.c:160
void dftMin2sec(DFT *dft)
Definition dftunit.c:145

Referenced by dftInterpolateCheckEnd(), dftInterpolateCheckStart(), dftMatchTimeunits(), dftReadinput(), dftReadModelingData(), dftReadReference(), img_logan(), img_patlak(), and imgReadModelingData().

◆ dftTimeunitToDFT()

int dftTimeunitToDFT ( DFT * dft,
const char * timeunit )

Set DFT timeunit; does not change the sample times.

Returns
Returns 0 if successful, and <> 0 if invalid timeunit.

Definition at line 103 of file dftunit.c.

104{
105 if(dft==NULL || timeunit==NULL) return(1);
106 int tunit=petTunitId(timeunit);
107 if(tunit<0) return(2); else dft->timeunit=tunit;
108 return(0);
109}
int petTunitId(const char *timeunit)
Definition petunits.c:187

Referenced by tsvRead().

◆ dftUnitConversion()

int dftUnitConversion ( DFT * dft,
int dunit )

Conversion of the DFT calibration unit. Changes both data values and unit string. Currently available conversions are: MBq/cc <-> kBq/cc <-> Bq/cc <-> nCi/cc <-> uCi/cc Bq <-> kBq <-> MBq <-> GBq <-> nCi <-> uCi <-> mCi

Returns
Returns 0 if conversion was successful, and <> 0 if failed.
Parameters
dftPointer to existing DFT data, whose calibration unit is to be changed
dunitNew unit code

Definition at line 25 of file dftunit.c.

30 {
31 int current_dunit=CUNIT_UNKNOWN;
32 double f=1.0;
33 int ri, fi;
34 int unit_type=0; /* 0=unknown; 1=concentration; 2=dose */
35
36 /* Check the input */
37 if(dft==NULL || dunit<0) return(1);
38
39 /* Identify the current unit */
40 current_dunit=petCunitId(dft->unit);
41 if(current_dunit==CUNIT_UNKNOWN) return(2);
42 /* If unit is already the requested one, then return */
43 if(current_dunit==dunit) return(0);
44
45 /* Determine the conversion factor to kBq/cc or MBq */
46 switch(current_dunit) {
47 case CUNIT_BQ_PER_ML: f*=0.001; unit_type=1; break;
48 case CUNIT_KBQ_PER_ML: f*=1.0; unit_type=1; break;
49 case CUNIT_MBQ_PER_ML: f*=1000.0; unit_type=1; break;
50 case CUNIT_NCI_PER_ML: f*=0.037; unit_type=1; break;
51 case CUNIT_UCI_PER_ML: f*=37.0; unit_type=1; break;
52 case CUNIT_BQ: f*=0.000001; unit_type=2; break;
53 case CUNIT_KBQ: f*=0.001; unit_type=2; break;
54 case CUNIT_MBQ: f*=1.0; unit_type=2; break;
55 case CUNIT_GBQ: f*=1000.0; unit_type=2; break;
56 case CUNIT_NCI: f*=0.000037; unit_type=2; break;
57 case CUNIT_UCI: f*=0.037; unit_type=2; break;
58 case CUNIT_MCI: f*=37.0; unit_type=2; break;
59 default: return(2);
60 }
61
62 /* Determine the conversion factor from kBq/cc or MBq to the required unit */
63 if(unit_type==1) switch(dunit) { // concentrations
64 case CUNIT_BQ_PER_ML: f*=1000.0; break;
65 case CUNIT_KBQ_PER_ML: f*=1.0; break;
66 case CUNIT_MBQ_PER_ML: f*=0.001; break;
67 case CUNIT_NCI_PER_ML: f/=0.037; break;
68 case CUNIT_UCI_PER_ML: f/=37.0; break;
69 default: return(3);
70 } else if(unit_type==2) switch(dunit) { // doses
71 case CUNIT_BQ: f*=1000000.0; break;
72 case CUNIT_KBQ: f*=1000.0; break;
73 case CUNIT_MBQ: f*=1.0; break;
74 case CUNIT_GBQ: f*=0.001; break;
75 case CUNIT_NCI: f/=0.000037; break;
76 case CUNIT_UCI: f/=0.037; break;
77 case CUNIT_MCI: f/=37.0; break;
78 default: return(3);
79 } else
80 return(3);
81
82 /* Convert the data values */
83 if(f==1.0) return(0);
84 for(fi=0; fi<dft->frameNr; fi++) {
85 for(ri=0; ri<dft->voiNr; ri++) {
86 if(!isnan(dft->voi[ri].y[fi])) dft->voi[ri].y[fi]*=f;
87 if(!isnan(dft->voi[ri].y2[fi])) dft->voi[ri].y2[fi]*=f;
88 if(!isnan(dft->voi[ri].y3[fi])) dft->voi[ri].y3[fi]*=f;
89 }
90 }
91
92 /* Set the new unit string */
93 dftUnitToDFT(dft, dunit);
94
95 return(0);
96}
void dftUnitToDFT(DFT *dft, int dunit)
Definition dftunit.c:11
int petCunitId(const char *unit)
Definition petunits.c:74
Voi * voi
int voiNr
char unit[MAX_UNITS_LEN+1]
double * y2
double * y
double * y3

Referenced by cunit_check_dft_vs_img(), dftReadinput(), dftReadModelingData(), and dftReadReference().

◆ dftUnitToDFT()

void dftUnitToDFT ( DFT * dft,
int dunit )

Set DFT calibration unit string

Definition at line 11 of file dftunit.c.

12{
13 strcpy(dft->unit, dftUnit(dunit));
14}

Referenced by csv2dft_a(), csv2dft_b(), csv2dft_linkset(), csv2dft_mat(), dftUnitConversion(), and tsvRead().