8#include "tpcclibConfig.h"
24static char *info[] = {
25 "Extrapolation of the decreasing tail of PET input curve to given time.",
26 "This is accomplished by fitting line to the end-part of the plot of the",
27 "natural logarithm of tracer concentration against time.",
28 "This approach may be applied to TACs which approach zero; thus this",
29 "works best for metabolite-corrected input TACs, and cannot be used with",
30 "tracers with very slow clearance, such as radiowater.",
32 "Usage: @P [Options] inputfile time outputfile",
35 " -e[nd]=<Fit end time>",
36 " Start the search to fit end time; by default, the search for the best",
37 " line fit is started from the last sample.",
38 " -minnr=<Minimum nr of samples>",
39 " Set the minimum number of samples used in searching the best fit;",
41 " -maxnr=<Maximum nr of samples>",
42 " Set the maximum number of samples used in searching the best fit;",
43 " by default all samples.",
44 " -mintime=<Minimum time>",
45 " Set a minimum time range used in searching the best fit.",
47 " Measured and extrapolated TACs are plotted in specified SVG file.",
50 "Input TAC file must contain a time column, and one or more concentration",
51 "columns. The extrapolation time must be given in same units as are the sample",
52 "times in the datafile.",
54 "See also: paucinf, avgbolus, fit_dexp, fit_feng, fit2dat, tacln",
56 "Keywords: input, plasma, TAC, modelling, simulation",
75int main(
int argc,
char **argv)
77 int ai, help=0, version=0, verbose=1;
78 char inpfile[FILENAME_MAX], outfile[FILENAME_MAX], svgfile[FILENAME_MAX];
79 char temp[FILENAME_MAX], *cptr;
81 double extr_to=-1.0, fittime=-1.0, mintime=-1.0;
82 int ri, n, ret, min_nr=3, max_nr=-1;
89 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
90 inpfile[0]=outfile[0]=svgfile[0]=(char)0;
94 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
95 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
97 if(strncasecmp(cptr,
"E=", 2)==0) {
98 fittime=
atof_dpi(cptr+2);
if(fittime>0.0)
continue;
99 }
else if(strncasecmp(cptr,
"END=", 4)==0) {
100 fittime=
atof_dpi(cptr+4);
if(fittime>0.0)
continue;
101 }
else if(strncasecmp(cptr,
"MINNR=", 6)==0) {
102 min_nr=atoi(cptr+6);
if(min_nr>1)
continue;
103 }
else if(strncasecmp(cptr,
"MAXNR=", 6)==0) {
104 max_nr=atoi(cptr+6);
if(max_nr>1)
continue;
105 }
else if(strncasecmp(cptr,
"MINTIME=", 8)==0) {
106 mintime=
atof_dpi(cptr+8);
if(mintime>0.0)
continue;
107 }
else if(strncasecmp(cptr,
"SVG=", 4)==0) {
108 strcpy(svgfile, cptr+4);
if(strlen(svgfile)>0)
continue;
110 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
115 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
120 for(; ai<argc; ai++) {
122 strcpy(inpfile, argv[ai]);
continue;
123 }
else if(extr_to<0.0) {
124 extr_to=
atof_dpi(argv[ai]);
if(extr_to>0.0)
continue;
125 fprintf(stderr,
"Error: invalid extrapolation time: '%s'.\n", argv[ai]);
127 }
else if(!outfile[0]) {
128 strcpy(outfile, argv[ai]);
continue;
131 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
137 fprintf(stderr,
"Error: missing file name for extrapolated data.\n");
144 printf(
"inpfile := %s\n", inpfile);
145 printf(
"outfile := %s\n", outfile);
146 printf(
"extr_to := %g\n", extr_to);
147 printf(
"svgfile := %s\n", svgfile);
148 printf(
"fittime := %g\n", fittime);
149 printf(
"mintime := %g\n", mintime);
150 printf(
"min_nr := %d\n", min_nr);
151 printf(
"max_nr := %d\n", max_nr);
158 if(verbose>1) printf(
"reading %s\n", inpfile);
160 fprintf(stderr,
"Error in reading '%s': %s\n", inpfile,
dfterrmsg);
168 for(ri=0, n=0; ri<dft.
voiNr; ri++) {
170 if(strcasecmp(dft.
voi[ri].
voiname,
"SD")==0) {
171 dft.
voi[ri].
sw=1; n++;
continue;}
173 dft.
voi[ri].
sw=1; n++;
continue;}
175 if(n>0 && n<dft.
voiNr) {
180 printf(
" TAC '%s' is not extrapolated\n", dft.
voi[ri].
name);
187 fprintf(stderr,
"Error: file does not contain data for extrapolation.\n");
195 if(verbose>1) printf(
"extrapolation\n");
196 if(verbose>2) logfp=stdout;
else logfp=NULL;
198 &dft, &fittime, &min_nr, max_nr, mintime, extr_to, &ext, logfp, temp
201 fprintf(stderr,
"Error in extrapolation: %s\n", temp);
208 if(verbose>1) printf(
"writing %s\n", outfile);
211 snprintf(temp, FILENAME_MAX-1,
"# extrapolated: %s %g\n", inpfile, extr_to);
217 fprintf(stderr,
"Error (%d) in writing '%s': %s\n", ret, outfile,
dfterrmsg);
225 if(verbose>1) printf(
"saving SVG plot\n");
226 sprintf(temp,
"Extrapolation ");
230 fprintf(stderr,
"Error (%d) in writing '%s'.\n", ret, svgfile);
234 if(verbose>=0) printf(
"Plots written in %s\n", svgfile);
double atof_dpi(char *str)
void dftSetComments(DFT *dft)
int dftDelete(DFT *dft, int voi)
int dftRead(char *filename, DFT *data)
int dftWrite(DFT *data, char *filename)
Header file for libtpccurveio.
#define DFT_FORMAT_STANDARD
Header file for libtpcmisc.
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)
Header file for libtpcmodel.
Header file for libtpcmodext.
int plot_fit_svg(DFT *dft1, DFT *dft2, char *main_title, char *fname, int verbose)
Header file for libtpcsvg.
char studynr[MAX_STUDYNR_LEN+1]
char comments[_DFT_COMMENT_LEN+1]
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]