TPCCLIB
Loading...
Searching...
No Matches
dftunit.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpccurveio.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
11void dftUnitToDFT(DFT *dft, int dunit)
12{
13 strcpy(dft->unit, dftUnit(dunit));
14}
15/*****************************************************************************/
16
17/*****************************************************************************/
27 DFT *dft,
29 int dunit
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}
97/*****************************************************************************/
98
99/*****************************************************************************/
103int dftTimeunitToDFT(DFT *dft, const char *timeunit)
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}
110/*****************************************************************************/
111
112/*****************************************************************************/
121 DFT *dft,
123 int tunit
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}
141/*****************************************************************************/
142
143/*****************************************************************************/
145void dftMin2sec(DFT *dft)
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}
156/*****************************************************************************/
157
158/*****************************************************************************/
160void dftSec2min(DFT *dft)
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}
171/*****************************************************************************/
172
173/*****************************************************************************/
void dftUnitToDFT(DFT *dft, int dunit)
Definition dftunit.c:11
void dftSec2min(DFT *dft)
Definition dftunit.c:160
int dftUnitConversion(DFT *dft, int dunit)
Definition dftunit.c:25
int dftTimeunitConversion(DFT *dft, int tunit)
Definition dftunit.c:119
int dftTimeunitToDFT(DFT *dft, const char *timeunit)
Definition dftunit.c:103
void dftMin2sec(DFT *dft)
Definition dftunit.c:145
Header file for libtpccurveio.
int petCunitId(const char *unit)
Definition petunits.c:74
int petTunitId(const char *timeunit)
Definition petunits.c:187
Voi * voi
int timeunit
double * x1
int voiNr
double * x2
int frameNr
double * x
char unit[MAX_UNITS_LEN+1]
double * y2
double * y
double * y3