9#include "tpcclibConfig.h"
21static char *info[] = {
22 "Converts TAC radioactivity concentrations into standardized uptake values",
23 "(SUV, DUR, DAR) or PID/L, using administered radioligand dose and subject",
24 "weight. Injected dose must be given in units MBq at the time of injection.",
25 "Subject weight must be given in kg or litres.",
26 "Instead of SUV, the percentage of injected dose per tissue volume ",
27 "(PID/L, %i.d./L) is calculated, if the subject weight is set to 0.",
29 "Usage: @P [Options] tacfile dose weight [outputfile]",
34 "TAC file must be correct for physical decay to the injection time.",
35 "If the units of radioactivity concentrations are not specified inside",
36 "the TAC file, the units are assumed to be in kBq/mL;",
37 "units can be specified by adding line(s) to the end of the TAC file,",
42 "If name for output file is not given, then TAC file is overwritten.",
45 " @P uia15.dat 330 77 uia15suv.dat",
47 "See also: tacunit, tactime, taccalc, dftinteg, dftsuv, imgsuv",
49 "Keywords: TAC, SUV, PID, dose, modelling",
68int main(
int argc,
char **argv)
70 int ai, help=0, version=0, verbose=1;
71 char tacfile[FILENAME_MAX], outfile[FILENAME_MAX];
72 double weight=nan(
""), dose=nan(
"");
77 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
78 tacfile[0]=outfile[0]=(char)0;
80 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
83 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
92 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
97 if(ai<argc) {
strlcpy(tacfile, argv[ai], FILENAME_MAX); ai++;}
99 if(
atofCheck(argv[ai], &dose) || !(dose>0.0)) {
100 fprintf(stderr,
"Error: invalid dose '%s'.\n", argv[ai]);
108 fprintf(stderr,
"Error: invalid weight '%s'.\n", argv[ai]);
111 if(v>1.0E-100) weight=v;
113 }
else {fprintf(stderr,
"Error: missing weight.\n");
return(1);}
114 if(ai<argc) {
strlcpy(outfile, argv[ai], FILENAME_MAX); ai++;}
116 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
122 fprintf(stderr,
"Error: missing dose.\n");
125 if(!outfile[0]) strcpy(outfile, tacfile);
129 printf(
"tacfile := %s\n", tacfile);
130 printf(
"outfile := %s\n", outfile);
131 printf(
"dose := %g MBq\n", dose);
132 if(!isnan(weight)) printf(
"weight := %g kg\n", weight);
140 if(verbose>1) printf(
"reading TAC data in %s\n", tacfile);
148 printf(
"tacNr := %d\n", tac.
tacNr);
149 printf(
"sampleNr := %d\n", tac.
sampleNr);
161 int ret=1, oldunit=tac.
cunit;
165 fprintf(stderr,
"Error: cannot convert units %s\n",
unitName(tac.
tunit));
169 printf(
"%s: units converted from '%s' to '%s'\n",
181 if(verbose>1) printf(
"calculating SUV TAC\n");
184 if(verbose>1) printf(
"calculating PID TAC\n");
190 if(verbose>2) {printf(
"conversion factor := %g\n", f); fflush(stdout);}
192 for(
int i=0; i<tac.
tacNr; i++)
for(
int j=0; j<tac.
sampleNr; j++) tac.
c[i].
y[j]/=f;
205 if(verbose>1) printf(
"writing %s\n", outfile);
206 FILE *fp; fp=fopen(outfile,
"w");
208 fprintf(stderr,
"Error: cannot open file for writing.\n");
221 if(!isnan(weight)) strcpy(tmp,
"SUV");
else strcpy(tmp,
"%i.d.");
222 printf(
"%s written in %s\n", tmp, outfile);
int atofCheck(const char *s, double *v)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
char * tacFormattxt(tacformat c)
int tacWrite(TAC *tac, FILE *fp, tacformat format, int extra, TPCSTATUS *status)
int tacYUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
Header file for library libtpcextensions.
@ UNIT_PID_PER_L
Percent of injected dose / L.
@ UNIT_UNKNOWN
Unknown unit.
@ UNIT_PID_PER_KG
Percent of injected dose / kg.
char * unitName(int unit_code)
int unitDividerHasVolume(int u)
int unitDividerHasMass(int u)
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.