8#include "tpcclibConfig.h"
27double *petmeas, *petsim;
28double fVa=-1.0, fK1k2=-1.0, fDelay;
31double wss_wo_penalty=0.0;
33double *ca, *cs, *cs2, *simdc, *petdc, *weight, *cpet, *csim, *wres;
35double waterFunc(
int parNr,
double *p,
void*);
39static char *info[] = {
40 "Non-linear fitting of one-tissue compartmental water model to regional",
41 "dynamic PET [O-15]H2O study data.",
42 "The model parameters are blood flow (F), partition coefficient",
43 "(pWater, K1/k2), arterial blood volume (Va) and time delay (delayT) between",
44 "tissue and blood time-activity curves (TTAC and BTAC, respectively).",
45 "Venous radioactivity is assumed to be the same as the tissue concentration.",
46 "Extraction factor of water is assumed to be 1.0.",
50 " | Ca | ---> | C1 | ",
51 " |______| |______| ",
55 "The blood flow obtained using PET [O-15]H2O techniques reflects tissue",
56 "perfusion, since the method is dependent on the tissue exchange of",
57 "labelled water. Non-nutritive flow (blood flowing through arteriovenous",
58 "shunts) is not measured (Lammertsma & Jones, 1983).",
60 "Usage: @P [Options] btacfile ttacfile endtime resultfile",
64 " Specify the constraints for model parameters;",
65 " This file with default values can be created by giving this",
66 " option as the only command-line argument to this program.",
67 " Without filename the default values are printed on screen.",
68 " Parameter can be fixed to a certain value by setting its",
69 " lower and upper limit to that value.",
71 " In results the units of F and Va will be given per mL or per dL,",
72 " respectively. By default, units are per dL.",
74 " Blood flow (perfusion) is reported per tissue volume (PET volume minus",
75 " vascular volume), that is, F=K1. By default, perfusion is reported",
76 " per PET volume, that is, F=(1-Va)*K1.",
78 " Standard deviations are calculated and saved in results (Y, default),",
79 " or not calculated (n).",
80 " Program runs a lot faster if SD and CL are not calculated.",
82 " 95% Confidence limits are calculated and saved in results (y), or",
83 " not calculated (N, default).",
85 " Enter a fixed Va; fitted by default.",
86 " -Delay=<Time delay (s)>",
87 " Enter a fixed time delay; fitted by default.",
88 " Positive time delay means that BTAC is moved forward in time.",
89 " -pH2O=<Partition coefficient for water>",
90 " Enter a fixed pH2O; fitted by default.",
92 " Fitted regional TACs are written in DFT format.",
94 " Input TAC sample times are corrected by the median of fitted time",
95 " delay values and saved; resulting input file can be used with imgflow,",
96 " or as input to this program to have common time delay for all regions.",
98 " Weighted residual curves are written in DFT format.",
100 " Fitted and measured TACs are plotted in specified SVG file.",
102 " Save k2 in result file.",
106 " @P uo1234bl.kbq uo1234.dft 999 uo1234f.res",
108 "See also: b2t_h2o, imgflow, arlkup, water_input, fitk2, bfmh2o",
110 "Keywords: TAC, modelling, perfusion, blood flow, 1TCM",
129int main(
int argc,
char **argv)
131 int ai, help=0, version=0, verbose=1;
133 char btacfile[FILENAME_MAX], ttacfile[FILENAME_MAX],
134 limfile[FILENAME_MAX], resfile[FILENAME_MAX],
135 fitfile[FILENAME_MAX], residfile[FILENAME_MAX],
136 inputfile[FILENAME_MAX], svgfile[FILENAME_MAX];
137 int doBootstrap=0, doSD=0, doCL=0;
139 int flow_per_tissue=0;
146 char *cptr, tmp[FILENAME_MAX];
148 int sim_index, simpet_index, bs_index;
158 def_pmin[0]=0.0; def_pmax[0]=600.0;
159 def_pmin[1]=0.30; def_pmax[1]=1.0;
160 def_pmin[2]=0.0; def_pmax[2]=25.0;
161 def_pmin[3]=-60.0; def_pmax[3]=+60.0;
166 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
167 limfile[0]=btacfile[0]=ttacfile[0]=resfile[0]=inputfile[0]=(char)0;
168 svgfile[0]=fitfile[0]=residfile[0]=(char)0;
173 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
174 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
176 if(strncasecmp(cptr,
"CL", 2)==0) {
177 if(strlen(cptr)==2) {doCL=1;
continue;}
178 cptr+=2;
if(*cptr==
'=') {
180 if(*cptr==
'Y' || *cptr==
'y') {doCL=1;
continue;}
181 if(*cptr==
'N' || *cptr==
'n') {doCL=0;
continue;}
183 }
else if(strncasecmp(cptr,
"SD", 2)==0) {
184 if(strlen(cptr)==2) {doSD=1;
continue;}
185 cptr+=2;
if(*cptr==
'=') {
187 if(*cptr==
'Y' || *cptr==
'y') {doSD=1;
continue;}
188 if(*cptr==
'N' || *cptr==
'n') {doSD=0;
continue;}
190 }
else if(strncasecmp(cptr,
"LIM=", 4)==0 && strlen(cptr)>4) {
191 strlcpy(limfile, cptr+4, FILENAME_MAX);
continue;
192 }
else if(strncasecmp(cptr,
"I=", 2)==0 && strlen(cptr)>2) {
193 strlcpy(limfile, cptr+2, FILENAME_MAX);
continue;
194 }
else if(strcasecmp(cptr,
"LIM")==0) {
195 strcpy(limfile,
"stdout");
continue;
196 }
else if(strcasecmp(cptr,
"I")==0) {
197 strcpy(limfile,
"stdout");
continue;
198 }
else if(strcasecmp(cptr,
"DL")==0) {
200 }
else if(strcasecmp(cptr,
"ML")==0) {
202 }
else if(strcasecmp(cptr,
"FPT")==0) {
203 flow_per_tissue=1;
continue;
204 }
else if(strcasecmp(cptr,
"K2")==0) {
206 }
if(strncasecmp(cptr,
"INPUT=", 6)==0) {
207 strlcpy(inputfile, cptr+6, FILENAME_MAX);
208 if(strlen(inputfile)>0)
continue;
209 }
else if(strncasecmp(cptr,
"SVG=", 4)==0) {
210 strlcpy(svgfile, cptr+4, FILENAME_MAX);
211 if(strlen(svgfile)>0)
continue;
212 }
else if(strncasecmp(cptr,
"FIT=", 4)==0) {
213 strlcpy(fitfile, cptr+4, FILENAME_MAX);
214 if(strlen(fitfile)>0)
continue;
215 }
else if(strncasecmp(cptr,
"RESID=", 6)==0) {
216 strlcpy(residfile, cptr+6, FILENAME_MAX);
217 if(strlen(residfile)>0)
continue;
218 }
else if((strncasecmp(cptr,
"Va=", 3)==0 || strncasecmp(cptr,
"Vb=", 3)==0) && strlen(cptr)>3) {
220 if(fVa>=0.0 && fVa<100.0) {
221 def_pmin[2]=def_pmax[2]=fVa;
222 if(fVa>0.0 && fVa<0.5)
223 fprintf(stderr,
"Warning: Va was set to %g%%\n", fVa);
226 }
else if(strncasecmp(cptr,
"pH2O=", 5)==0 && strlen(cptr)>5) {
227 fK1k2=
atof_dpi(cptr+5);
if(fK1k2>0.0)
continue;
228 }
else if(strncasecmp(cptr,
"delay=", 6)==0 && strlen(cptr)>6) {
230 if(fDelay>-120.0 && fDelay<120.0) {
231 if(fDelay!=0.0 && fabs(fDelay)<1.0)
232 fprintf(stderr,
"Warning: Delay was set to %g sec\n", fDelay);
236 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
241 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
246 if(ai<argc) {
strlcpy(btacfile, argv[ai++], FILENAME_MAX);}
247 if(ai<argc) {
strlcpy(ttacfile, argv[ai++], FILENAME_MAX);}
250 fprintf(stderr,
"Error: invalid fit time '%s'.\n", argv[ai]);
return(1);}
253 if(ai<argc) {
strlcpy(resfile, argv[ai++], FILENAME_MAX);}
254 if(ai<argc) {fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
return(1);}
255 if(doSD || doCL) doBootstrap=1;
else doBootstrap=0;
259 printf(
"limfile := %s\n", limfile);
260 printf(
"btacfile := %s\n", btacfile);
261 printf(
"ttacfile := %s\n", ttacfile);
262 printf(
"resfile := %s\n", resfile);
263 printf(
"fitfile := %s\n", fitfile);
264 printf(
"svgfile := %s\n", svgfile);
265 printf(
"residfile := %s\n", residfile);
266 printf(
"inputfile := %s\n", inputfile);
267 printf(
"per_dl := %d\n", per_dl);
268 printf(
"flow_per_tissue := %d\n", flow_per_tissue);
269 printf(
"doBootstrap := %d\n", doBootstrap);
270 printf(
"doSD := %d\n", doSD);
271 printf(
"doCL := %d\n", doCL);
272 if(fitdur>=0.0) printf(
"required_fitdur := %g\n", fitdur);
273 if(fVa>=0.0) printf(
"required_fVa := %g\n", fVa);
274 if(fK1k2>=0.0) printf(
"required_fK1k2 := %g\n", fK1k2);
275 if(!isnan(fDelay)) printf(
"required_fDelay := %g\n", fDelay);
276 printf(
"save_k2 := %d\n", save_k2);
277 printf(
"lambda := %g [1/s]\n", lambda);
283 if(limfile[0] && !btacfile[0]) {
285 if(strcasecmp(limfile,
"stdout")!=0 && access(limfile, 0) != -1) {
286 fprintf(stderr,
"Error: parameter constraint file %s exists.\n", limfile);
289 if(verbose>1) printf(
"writing parameter constraints file\n");
297 iftPutDouble(&ift,
"Delay_lower", def_pmin[3], NULL, 0);
298 iftPutDouble(&ift,
"Delay_upper", def_pmax[3], NULL, 0);
300 fprintf(stderr,
"Error in writing '%s': %s\n", limfile, ift.
status);
303 if(strcasecmp(limfile,
"stdout")!=0)
304 fprintf(stdout,
"Parameter file %s with initial values written.\n", limfile);
309 if(fitdur==0) fitdur=1.0E+100;
310 else if(fitdur<0) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
312 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
322 if(verbose>1) printf(
"reading %s\n", limfile);
323 if(
iftRead(&ift, limfile, 1, 0)) {
324 fprintf(stderr,
"Error in reading '%s': %s\n", limfile, ift.
status);
327 if(verbose>10)
iftWrite(&ift,
"stdout", 0);
342 if(n==0) {fprintf(stderr,
"Error: invalid parameter file.\n");
return(9);}
347 for(pi=0; pi<parNr; pi++) {
348 if(def_pmin[pi]<0.0 && pi!=3) ret++;
349 if(def_pmax[pi]<def_pmin[pi]) ret++;
350 if(def_pmax[pi]>def_pmin[pi]) n++;
353 fprintf(stderr,
"Error: invalid parameter constraints.\n");
357 fprintf(stderr,
"Error: no model parameters left free for fitting.\n");
362 if(fVa>=0.0) def_pmin[2]=def_pmax[2]=fVa;
363 else if(def_pmin[2]==def_pmax[2]) fVa=def_pmin[2];
365 if(fVa>=0.0) printf(
"fVa := %g\n", fVa);
368 if(fK1k2>=0.0) def_pmin[1]=def_pmax[1]=fK1k2;
369 else if(def_pmin[1]==def_pmax[1]) fK1k2=def_pmin[1];
371 if(fK1k2>=0.0) printf(
"fK1k2 := %g\n", fK1k2);
374 if(!isnan(fDelay)) def_pmin[3]=def_pmax[3]=fDelay;
375 else if(def_pmin[3]==def_pmax[3]) fDelay=def_pmin[3];
377 if(!isnan(fDelay)) printf(
"fDelay := %g\n", fDelay);
380 def_pmin[0]/=6000.; def_pmax[0]/=6000.;
381 def_pmin[2]/=100.; def_pmax[2]/=100.;
383 fflush(stdout); printf(
"Parameter constraints:\n");
384 for(
int pi=0; pi<parNr; pi++) {
385 printf(
"def_pmin[%d] := %g\n", pi+1, def_pmin[pi]);
386 printf(
"def_pmax[%d] := %g\n", pi+1, def_pmax[pi]);
394 if(verbose>1) printf(
"reading tissue and input data\n");
398 &fitframeNr, &ttac, &btac, stdout, verbose-2, tmp)!=0)
400 fprintf(stderr,
"Error: %s\n", tmp);
403 if(fitframeNr<4 || btac.
frameNr<4) {
405 fprintf(stdout,
"Error: check the time units in data files.\n");
407 fprintf(stderr,
"Error: too few samples in specified fit duration.\n");
410 sim_index=btac.
voiNr-1;
414 fprintf(stderr,
"Error: cannot setup memory for simulation.\n");
417 simpet_index=ttac.
voiNr; bs_index=ttac.
voiNr+1;
418 strcpy(ttac.
voi[simpet_index].
voiname,
"Sim");
419 strcpy(ttac.
voi[simpet_index].
name,
"Sim");
421 strcpy(ttac.
voi[bs_index].
name,
"BS");
424 if(verbose>1) printf(
"converting data times to sec\n");
432 if(verbose>1) printf(
"assuming that data times are in min.\n");
439 if(ttac.
x1[0]>27.0 && ttac.
voi[0].
y[0]>0.0) {
440 fprintf(stderr,
"Error: TACs must start at time zero.\n");
443 if(ttac.
x1[0]>5.0 && ttac.
voi[0].
y[0]>0.0) {
444 fprintf(stderr,
"Warning: TACs should start at time zero.\n");
447 if(btac.
x[0]>90.0 && ttac.
voi[0].
y[0]>0.0) {
448 fprintf(stderr,
"Error: input TAC must start at time zero.\n");
451 if(btac.
x[0]>20.0 && ttac.
voi[0].
y[0]>0.0) {
452 fprintf(stderr,
"Warning: input TAC should start at time zero.\n");
456 fprintf(stderr,
"Note: data is not weighted.\n");
460 fprintf(stdout,
"common_data_weights := %.3f", ttac.
w[fi++]);
461 for(; fi<ttac.
frameNr; fi++) fprintf(stdout,
", %.3f", ttac.
w[fi]);
462 fprintf(stdout,
"\n");
470 if(verbose>1) printf(
"initializing result data\n");
472 fprintf(stderr,
"Error: cannot setup memory for results.\n");
481 if(fVa>=0.0) res.
Vb=fVa;
491 if(save_k2) res.
parNr++;
494 pi=0; strcpy(res.
parname[pi],
"Flow");
495 if(per_dl==0) strcpy(res.
parunit[pi],
"ml/(min*ml)");
496 else strcpy(res.
parunit[pi],
"ml/(min*dl)");
497 pi++; strcpy(res.
parname[pi],
"pWater"); strcpy(res.
parunit[pi],
"");
498 pi++; strcpy(res.
parname[pi],
"Va");
499 if(per_dl==0) strcpy(res.
parunit[pi],
"ml/ml");
500 else strcpy(res.
parunit[pi],
"%");
501 pi++; strcpy(res.
parname[pi],
"delayT"); strcpy(res.
parunit[pi],
"sec");
502 if(save_k2) {pi++; strcpy(res.
parname[pi],
"k2"); strcpy(res.
parunit[pi],
"1/min");}
503 pi++; strcpy(res.
parname[pi],
"WSS"); strcpy(res.
parunit[pi],
"");
510 if(verbose>1) printf(
"starting regional fitting\n");
511 int tgoNr=0, neighNr=5, iterNr=0;
512 double *sd, *cl1, *cl2;
515 fprintf(stdout,
"%-20s %-6s %-6s %-6s %-6s %-9s\n",
516 "Region",
"Flow",
"pWater",
"Va(%)",
"delayT",
"WSS");
518 fprintf(stdout,
"%-20s %-6s %-6s %-6s %-6s %-9s\n",
519 "Region",
"Flow",
"pWater",
"Va",
"delayT",
"WSS");
523 simdc=btac.
voi[sim_index].
y3;
524 for(
int fi=0; fi<btac.
frameNr; fi++)
528 petdc=ttac.
voi[simpet_index].
y;
529 for(
int fi=0; fi<ttac.
frameNr; fi++) {
537 fprintf(stdout,
"fitting regional TACs: ");
538 if(verbose>1) fprintf(stdout,
"\n");
541 for(
int ri=0; ri<ttac.
voiNr; ri++) {
543 if(verbose>2) fprintf(stdout,
"\n%s [%d] :\n", ttac.
voi[ri].
name, ri+1);
547 cs=btac.
voi[sim_index].
y; cs2=btac.
voi[sim_index].
y2;
552 for(pi=0; pi<parNr; pi++) {
553 pmin[pi]=def_pmin[pi]; pmax[pi]=def_pmax[pi];
555 for(pi=fittedparNr=0; pi<parNr; pi++)
if(pmax[pi]>pmin[pi]) fittedparNr++;
557 printf(
" constraints :=");
558 for(pi=0; pi<parNr; pi++) printf(
" [%g,%g]", pmin[pi], pmax[pi]);
560 printf(
"fittedparNr := %d\n", fittedparNr);
564 if(verbose>2) printf(
" fitting\n");
568 tgoNr=50+25*fittedparNr;
569 neighNr=6*fittedparNr;
572 pmin, pmax, waterFunc, NULL, parNr, neighNr,
576 fprintf(stderr,
"\nError in optimization (%d).\n", ret);
585 printf(
" -> WSS=%g\n", wss); fflush(stdout);
591 if(verbose>2) printf(
"\n bootstrapping\n");
593 cpet=ttac.
voi[bs_index].
y;
594 csim=ttac.
voi[bs_index].
y2;
595 wres=ttac.
voi[bs_index].
y3;
596 if(doSD) sd=res.
voi[ri].
sd;
else sd=NULL;
597 if(doCL) {cl1=res.
voi[ri].
cl1; cl2=res.
voi[ri].
cl2;}
else cl1=cl2=NULL;
599 0, cl1, cl2, sd, res.
voi[ri].
parameter, pmin, pmax, fitframeNr,
606 parNr, ttac.
w, waterFunc, tmp, verbose-5
609 fprintf(stderr,
"\nError in bootstrap: %s\n", tmp);
610 for(pi=0; pi<parNr; pi++) {
611 if(doSD) sd[pi]=nan(
"");
612 if(doCL) cl1[pi]=cl2[pi]=nan(
"");
617 cpet=ttac.
voi[ri].
y; csim=ttac.
voi[ri].
y2;
622 double F, pWater, Va, delayT, f=60.;
627 if(flow_per_tissue==0) f*=(1.0-res.
voi[ri].
parameter[2]);
631 if(!isnan(res.
voi[ri].
sd[0])) res.
voi[ri].
sd[0]*=f;
634 if(!isnan(res.
voi[ri].
cl1[0])) res.
voi[ri].
cl1[0]*=100.;
635 if(!isnan(res.
voi[ri].
cl2[0])) res.
voi[ri].
cl2[0]*=100.;
636 if(!isnan(res.
voi[ri].
sd[0])) res.
voi[ri].
sd[0]*=100.;
644 if(!isnan(res.
voi[ri].
cl1[2])) res.
voi[ri].
cl1[2]*=100.;
645 if(!isnan(res.
voi[ri].
cl2[2])) res.
voi[ri].
cl2[2]*=100.;
646 if(!isnan(res.
voi[ri].
sd[2])) res.
voi[ri].
sd[2]*=100.;
653 fprintf(stdout,
"%-20s %6.2f %6.3f %6.2f %6.2f %8.2e\n",
654 ttac.
voi[ri].
name, F, pWater, Va, delayT, wss);
658 if(ttac.
voiNr>2 && verbose==1) {fprintf(stdout,
"."); fflush(stdout);}
661 if(verbose>0) {fprintf(stdout,
"\n"); fflush(stdout);}
666 if(verbose>0) {
resPrint(&res); fprintf(stdout,
"\n");}
672 if(verbose>1) printf(
"saving results\n");
673 if(
resWrite(&res, resfile, verbose-3)!=0) {
674 fprintf(stderr,
"Error in writing '%s': %s\n", resfile,
reserrmsg);
678 if(verbose>1) fprintf(stdout,
"Model parameters written in %s\n", resfile);
684 if(svgfile[0] || fitfile[0]) {
694 fprintf(stderr,
"Error: cannot save fitted curves.\n");
698 for(ri=0; ri<ttac.
voiNr; ri++)
for(fi=0; fi<fitframeNr; fi++)
704 if(verbose>1) printf(
"saving SVG plot\n");
705 sprintf(tmp,
"Radiowater fit ");
708 0.0, nan(
""), svgfile, verbose-8);
710 fprintf(stderr,
"Error (%d) in writing '%s'.\n", ret, svgfile);
714 if(verbose>0) printf(
"Plots written in %s\n", svgfile);
719 if(verbose>1) printf(
"saving fitted curves\n");
721 sprintf(dft2.
comments,
"# program := %s\n", tmp);
723 fprintf(stderr,
"Error in writing '%s': %s\n", fitfile,
dfterrmsg);
727 if(verbose>0) printf(
"Fitted TACs written in %s\n", fitfile);
737 if(verbose>1) printf(
"saving weighted residuals\n");
740 for(ri=0; ri<ttac.
voiNr; ri++)
for(fi=0; fi<fitframeNr; fi++)
743 sprintf(ttac.
comments,
"# Residual curves from %s\n", tmp);
746 fprintf(stderr,
"Error in writing '%s': %s\n", residfile,
dfterrmsg);
750 if(verbose>0) fprintf(stdout,
"Residual curves written in %s\n", residfile);
759 double *darr, time_diff;
761 if(verbose>1) printf(
"saving time delay corrected input curve\n");
763 darr=(
double*)calloc(res.
voiNr,
sizeof(
double));
764 for(ri=0; ri<res.
voiNr; ri++) {
766 if(verbose>4) printf(
"darr[%d]=%g\n", ri, darr[ri]);
770 if(verbose>1) printf(
"time_diff := %g\n", time_diff);
772 for(fi=0; fi<btac.
frameNr; fi++) {
773 btac.
x[fi]+=time_diff;
774 btac.
x1[fi]+=time_diff; btac.
x2[fi]+=time_diff;
780 sprintf(tmp,
"# time_delay := %g [s]\n", time_diff);
784 fprintf(stderr,
"Error in writing '%s': %s\n", inputfile,
dfterrmsg);
788 if(verbose>0) fprintf(stdout,
"Input TAC written in %s\n", inputfile);
803double waterFunc(
int parNr,
double *p,
void *fdata)
806 double wss, d, k1, pWater, k2, Va, delayT;
816 pWater=pa[1]; Va=pa[2]; delayT=pa[3];
817 if(pWater>0.0) k2=k1/pWater;
else k2=0.;
821 ret=
simC3vs(btac.
x, ca, ca, btac.
frameNr, k1, k2, 0., 0., 0., 0.,
823 cs, NULL, NULL, NULL, NULL, NULL);
825 printf(
"error %d in simulation\n", ret);
830 if(fabs(delayT)>1.0E-06) {
832 for(fi=0; fi<btac.
frameNr; fi++) dx[fi]=btac.
x[fi]+delayT;
834 cs2, NULL, NULL, btac.
frameNr);
836 printf(
"error %d in interpolation\n", ret);
839 for(fi=0; fi<btac.
frameNr; fi++) cs[fi]=cs2[fi];
842 for(fi=0; fi<btac.
frameNr; fi++) cs[fi]*=simdc[fi];
846 csim, NULL, NULL, fitframeNr);
849 csim, NULL, NULL, fitframeNr);
851 printf(
"error %d in interpolation\n", ret);
855 for(fi=0; fi<fitframeNr; fi++) csim[fi]*=petdc[fi];
858 for(fi=0, wss=0.; fi<fitframeNr; fi++) {
862 if(weight[fi]>0.0) wss+=weight[fi]*d*d;
864 if(weight[fi]>0.0) wres[fi]=sqrt(weight[fi])*d;
else wres[fi]=0.0;
int bootstrap(int iterNr, double *cLim1, double *cLim2, double *SD, double *parameter, double *lowlim, double *uplim, int frameNr, double *origTac, double *fitTac, double *bsTac, int parNr, double *weight, double(*objf)(int, double *, void *), char *status, int verbose)
int modelCheckParameters(int par_nr, double *lower_p, double *upper_p, double *test_p, double *accept_p, double *penalty)
int atof_with_check(char *double_as_string, double *result_value)
double atof_dpi(char *str)
int dftdup(DFT *dft1, DFT *dft2)
int dftAddmem(DFT *dft, int voiNr)
void dftSetComments(DFT *dft)
int dftWrite(DFT *data, char *filename)
int res_allocate_with_dft(RES *res, DFT *dft)
void dftSec2min(DFT *dft)
void dftMin2sec(DFT *dft)
double hl2lambda(double halflife)
double hlLambda2factor(double lambda, double frametime, double framedur)
int iftPutDouble(IFT *ift, char *key, double value, char *cmt_type, int verbose)
int iftRead(IFT *ift, char *filename, int is_key_required, int verbose)
int iftWrite(IFT *ift, char *filename, int verbose)
int iftGetDoubleValue(IFT *ift, int si, const char *key, double *value, int verbose)
int interpolate(double *x, double *y, int nr, double *newx, double *newy, double *newyi, double *newyii, int newnr)
Linear interpolation and integration.
int interpolate4pet(double *x, double *y, int nr, double *newx1, double *newx2, double *newy, double *newyi, double *newyii, int newnr)
Interpolate and integrate TAC to PET frames.
Header file for libtpccurveio.
int resWrite(RES *res, char *filename, int verbose)
#define DFT_TIME_STARTEND
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
void tpcProgramName(const char *program, int version, int copyright, char *prname, int n)
char * petTunit(int tunit)
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.
int simC3vs(double *t, double *ca, double *cb, int nr, double k1, double k2, double k3, double k4, double k5, double k6, double f, double vb, double fa, double *cpet, double *cta, double *ctb, double *ctc, double *ctab, double *ctvb)
int tgo(double *lowlim, double *uplim, double(*objf)(int, double *, void *), void *objfData, int dim, int neighNr, double *fmin, double *gmin, int samNr, int tgoNr, int verbose)
double dmedian(double *data, int n)
Header file for libtpcmodext.
int plot_fitrange_svg(DFT *dft1, DFT *dft2, char *main_title, double x1, double x2, double y1, double y2, char *fname, int verbose)
Header file for libtpcsvg.
char comments[_DFT_COMMENT_LEN+1]
char studynr[MAX_STUDYNR_LEN+1]
char parname[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]
char datafile[FILENAME_MAX]
char parunit[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]
char bloodfile[FILENAME_MAX]
double parameter[MAX_RESPARAMS]
double cl2[MAX_RESPARAMS]
double cl1[MAX_RESPARAMS]
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]