5#include "tpcclibConfig.h"
22typedef struct TPC_UNIT {
36static TPC_UNIT tpc_unit[]={
149 while(strlen(tpc_unit[n].name)>0) n++;
150 if(unit_code<1 || unit_code>n-1)
153 return(tpc_unit[unit_code].name);
169 while(strlen(tpc_unit[n].name)>0) n++;
171 if(strcasecmp(tpc_unit[i].name, s)==0)
return i;
174 if( strcasecmp(s,
"ms")==0)
return UNIT_MSEC;
175 else if(strcasecmp(s,
"s")==0)
return UNIT_SEC;
176 else if(strcasecmp(s,
"second")==0)
return UNIT_SEC;
177 else if(strcasecmp(s,
"seconds")==0)
return UNIT_SEC;
178 else if(strcasecmp(s,
"mins")==0)
return UNIT_MIN;
179 else if(strcasecmp(s,
"minute")==0)
return UNIT_MIN;
180 else if(strcasecmp(s,
"minutes")==0)
return UNIT_MIN;
181 else if(strcasecmp(s,
"hours")==0)
return UNIT_HOUR;
182 else if(strcasecmp(s,
"days")==0)
return UNIT_DAY;
183 else if(strcasecmp(s,
"months")==0)
return UNIT_MONTH;
184 else if(strcasecmp(s,
"years")==0)
return UNIT_YEAR;
185 else if(strcasecmp(s,
"yrs")==0)
return UNIT_YEAR;
186 else if(strcasecmp(s,
"microm")==0)
return UNIT_UM;
187 else if(strcasecmp(s,
"millim")==0)
return UNIT_MM;
188 else if(strcasecmp(s,
"microl")==0)
return UNIT_UL;
189 else if(strcasecmp(s,
"mm^3")==0)
return UNIT_UL;
190 else if(strcasecmp(s,
"cc")==0)
return UNIT_ML;
191 else if(strcasecmp(s,
"liter")==0)
return UNIT_L;
192 else if(strcasecmp(s,
"microgram")==0)
return UNIT_UG;
193 else if(strcasecmp(s,
"milligram")==0)
return UNIT_MG;
194 else if(strcasecmp(s,
"gram")==0)
return UNIT_G;
195 else if(strcasecmp(s,
"100 g")==0)
return UNIT_100G;
196 else if(strcasecmp(s,
"kilogram")==0)
return UNIT_KG;
197 else if(strcasecmp(s,
"micromol")==0)
return UNIT_UMOL;
198 else if(strcasecmp(s,
"micromoles")==0)
return UNIT_UMOL;
199 else if(strcasecmp(s,
"millimol")==0)
return UNIT_MMOL;
200 else if(strcasecmp(s,
"millimoles")==0)
return UNIT_MMOL;
201 else if(strcasecmp(s,
"mole")==0)
return UNIT_MOL;
202 else if(strcasecmp(s,
"moles")==0)
return UNIT_MOL;
203 else if(strcasecmp(s,
"cnts")==0)
return UNIT_COUNTS;
205 else if(strcasecmp(s,
"becquerels")==0)
return UNIT_BQ;
206 else if(strcasecmp(s,
"kbecquerels")==0)
return UNIT_KBQ;
207 else if(strcasecmp(s,
"cnts/s")==0)
return UNIT_CPS;
208 else if(strcasecmp(s,
"counts/s")==0)
return UNIT_CPS;
209 else if(strcasecmp(s,
"counts/sec")==0)
return UNIT_CPS;
210 else if(strcasecmp(s,
"ECAT counts/sec")==0)
return UNIT_CPS;
211 else if(strcasecmp(s,
"kcounts/s")==0)
return UNIT_KCPS;
212 else if(strcasecmp(s,
"kcounts/sec")==0)
return UNIT_KCPS;
213 else if(strcasecmp(s,
"counts/min")==0)
return UNIT_CPM;
214 else if(strcasecmp(s,
"kcounts/min")==0)
return UNIT_KCPM;
279 else if(strcasecmp(s,
"% ID")==0)
return UNIT_PID;
280 else if(strcasecmp(s,
"%i.d.")==0)
return UNIT_PID;
281 else if(strcasecmp(s,
"PID")==0)
return UNIT_PID;
297 else if(strcasecmp(s,
"Hounsfield Unit")==0)
return UNIT_HU;
298 else if(strcasecmp(s,
"HU")==0)
return UNIT_HU;
317 for(
int i=0; i<2; i++) {
319 {cptr=strrchr((
char*)s,
'.');
if(cptr==NULL) {cptr=(
char*)s; i++;}}
496 if(u1==u2)
return 1.0;
504 else if(u1==
UNIT_DAY) cf=24.0*36000.0;
506 else if(u1==
UNIT_YEAR) cf=365.0*30.0*24.0*36000.0;
511 else if(u2==
UNIT_DAY) cf/=24.0*36000.0;
512 else if(u2==
UNIT_MONTH) cf/=30.0*24.0*36000.0;
513 else if(u2==
UNIT_YEAR) cf/=365.0*30.0*24.0*36000.0;
521 else if(u1==
UNIT_MM) cf=1.0E-3;
522 else if(u1==
UNIT_CM) cf=1.0E-2;
523 else if(u1==
UNIT_M) cf=1.0;
525 else if(u2==
UNIT_MM) cf/=1.0E-3;
526 else if(u2==
UNIT_CM) cf/=1.0E-2;
527 else if(u2==
UNIT_M) cf/=1.0;
535 else if(u1==
UNIT_ML) cf=1.0E-3;
536 else if(u1==
UNIT_DL) cf=1.0E-1;
537 else if(u1==
UNIT_L) cf=1.0;
539 else if(u2==
UNIT_ML) cf/=1.0E-3;
540 else if(u2==
UNIT_DL) cf/=1.0E-1;
541 else if(u2==
UNIT_L) cf/=1.0;
549 else if(u1==
UNIT_MG) cf=1.0E-3;
550 else if(u1==
UNIT_G) cf=1.0;
552 else if(u1==
UNIT_KG) cf=1.0E+3;
554 else if(u2==
UNIT_MG) cf/=1.0E-3;
555 else if(u2==
UNIT_G) cf/=1.0;
557 else if(u2==
UNIT_KG) cf/=1.0E+3;
587 else if(u1==
UNIT_CI) cf=3.7E+10;
595 else if(u2==
UNIT_CI) cf/=3.7E+10;
757 while(strlen(tpc_unit[n].name)>0) n++;
759 if(!((u1==tpc_unit[i].u1 && u2==tpc_unit[i].u2) || (u1==tpc_unit[i].u2 && u2==tpc_unit[i].u1)))
761 if(!((v1==tpc_unit[i].v1 && v2==tpc_unit[i].v2) || (v1==tpc_unit[i].v2 && v2==tpc_unit[i].v1)))
781 if(
unitIsVolume(tpc_unit[u].v1)) {uo=tpc_unit[u].v1; uoo=tpc_unit[u].v2;}
782 else if(
unitIsVolume(tpc_unit[u].v2)) {uo=tpc_unit[u].v2; uoo=tpc_unit[u].v1;}
791 if(
unitIsMass(tpc_unit[u].v1)) {uo=tpc_unit[u].v1; uoo=tpc_unit[u].v2;}
792 else if(
unitIsMass(tpc_unit[u].v2)) {uo=tpc_unit[u].v2; uoo=tpc_unit[u].v1;}
817 int n=0;
while(strlen(tpc_unit[n].name)>0) n++;
821 int u[4], v[4], nu=0, nv=0;
833 for(
int i=0; i<nu; i++) printf(
" %s",
unitName(u[i]));
835 for(
int j=0; j<nv; j++) printf(
" %s",
unitName(v[j]));
841 for(
int i=0; i<nu; i++)
for(
int j=0; j<nv; j++)
if(u[i]==v[j]) {u[i]=v[i]=
UNIT_UNITLESS; cn++;}
844 printf(
"units after cancelling: (");
845 for(
int i=0; i<nu; i++) printf(
" %s",
unitName(u[i]));
847 for(
int j=0; j<nv; j++) printf(
" %s",
unitName(v[j]));
852 int s=u[i]; u[i]=u[j]; u[j]=s;
856 int s=v[i]; v[i]=v[j]; v[j]=s;
860 printf(
"units after removing gaps: (");
861 for(
int i=0; i<nu; i++) printf(
" %s",
unitName(u[i]));
863 for(
int j=0; j<nv; j++) printf(
" %s",
unitName(v[j]));
size_t strnlen(const char *s, size_t n)
char * strcasestr(const char *haystack, const char *needle)
Header file for library libtpcextensions.
@ UNIT_UMOL_PER_DL_MIN
umol/(dL*min)
@ UNIT_MMOL_PER_DL_MIN
mmol/(dL*min)
@ UNIT_MMOL_PER_G_MIN
mmol/(g*min)
@ UNIT_MMOL_PER_100G_MIN
mmol/(100g*min)
@ UNIT_ML_PER_ML_MIN
mL/(mL*min)
@ UNIT_UMOL_PER_ML_MIN
umol/(mL*min)
@ UNIT_PID_PER_L
Percent of injected dose / L.
@ UNIT_UNKNOWN
Unknown unit.
@ UNIT_KCPM
kilocounts/min
@ UNIT_PID_PER_G
Percent of injected dose / g.
@ UNIT_ML_PER_G_MIN
mL/(g*min)
@ UNIT_ML_PER_DL_MIN
mL/(dL*min)
@ UNIT_PID_PER_ML
Percent of injected dose / mL.
@ UNIT_MMOL_PER_ML_MIN
mmol/(mL*min)
@ UNIT_PID
Percent of injected dose.
@ UNIT_PID_PER_KG
Percent of injected dose / kg.
@ UNIT_ML_PER_ML_SEC
mL/(mL*sec)
@ UNIT_UMOL_PER_G_MIN
umol/(g*min)
@ UNIT_SEC_KBQ_PER_ML
s*kBq/mL
@ UNIT_HU
Hounsfield Unit.
@ UNIT_UMOL_PER_100G_MIN
umol/(100g*min)
@ UNIT_PERCENTAGE
Percentage (%)
#define MAX_UNITS_LEN
Define max units string length.
int unitDividendHasRadioactivity(int u)
int unitIdentify(const char *s)
int unitIdentifyFilename(const char *s)
int unitIsRadioactivity(int u)
double unitConversionFactor(const int u1, const int u2)
char * unitName(int unit_code)
int unitCombination(const int u1, const int u2, const int v1, const int v2)
int unitIsCombinatorial(int u)
int unitIsDistance(int u)
int unitDividerHasVolume(int u)
int unitDividerMassVolumeConversion(int u)
int unitMultiply(int ua, int ub)
int unitDividerHasMass(int u)