TPCCLIB
Loading...
Searching...
No Matches
fit_wcdf.c
Go to the documentation of this file.
1
9/*****************************************************************************/
10#include "tpcclibConfig.h"
11/*****************************************************************************/
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <math.h>
16/*****************************************************************************/
17#include "tpcextensions.h"
18#include "tpcift.h"
19#include "tpctac.h"
20#include "tpcpar.h"
21#include "tpctacmod.h"
22#include "tpcrand.h"
23#include "tpcnlopt.h"
24#include "tpcfileutil.h"
25/*****************************************************************************/
26
27/*****************************************************************************/
28/* Local functions */
29double func_wcdf(int parNr, double *p, void*);
30double func_wcdfd(int parNr, double *p, void*);
31/*****************************************************************************/
32
33/*****************************************************************************/
34typedef struct FITDATA {
36 unsigned int n;
38 double *x;
40 double *ymeas;
42 double *ysim;
44 double *w;
45} FITDATA;
46const int maxParNr=5;
47/*****************************************************************************/
48
49/*****************************************************************************/
50static char *info[] = {
51 "Non-linear fitting of the Weibull CDF and Weibull PDF sum function to PET",
52 "time-activity curves (TACs).",
53 " ",
54 "Function:",
55 " when x<=dT, f(x) = 0 ",
56 " when x>dT, f(x) = A * (n/B) * ((x-dT)/B)^(n-1) * exp(-((x-dT)/B)^n) +",
57 " k * A * (1-exp(-((x-dT)/B)^n))",
58 ", where A>=0, B>0, n>0 (usually n>1), k>=0, and dT>=0.",
59 " ",
60 "Usage: @P [Options] tacfile [parfile]",
61 " ",
62 "Options:",
63 " -CDF",
64 " WCDF function without WPDF (derivative of WCDF) is fitted:",
65 " when x>dT, f(x) = A * (1-exp(-((x-dT)/B)^n))",
66 " -w1",
67 " All weights are set to 1.0 (no weighting); by default, weights in",
68 " data file are used, if available.",
69 " -wf",
70 " Weight by sampling interval.",
71 " -lim[=<filename>]",
72 " Specify the constraints for function parameters;",
73 " This file with default values can be created by giving this option",
74 " as the only command-line argument to this program.",
75 " Without file name the default values are printed on screen.",
76 " -delay=<time>",
77 " Delay time (dT) is constrained to specified value (>=0).",
78 " -k=<value>",
79 " Parameter k is constrained to given value; setting k to zero causes",
80 " the function to approach zero.",
81 " -svg=<Filename>",
82 " Fitted and measured TACs are plotted in specified SVG file.",
83 " -stdoptions", // List standard options like --help, -v, etc
84 " ",
85 "See also: fit_sinf, fit_feng, fit_suri, fit_ratf, fit2dat, extrapol",
86 " ",
87 "Keywords: TAC, curve fitting",
88 0};
89/*****************************************************************************/
90
91/*****************************************************************************/
92/* Turn on the globbing of the command line, since it is disabled by default in
93 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
94 In Unix&Linux wildcard command line processing is enabled by default. */
95/*
96#undef _CRT_glob
97#define _CRT_glob -1
98*/
99int _dowildcard = -1;
100/*****************************************************************************/
101
102/*****************************************************************************/
106int main(int argc, char **argv)
107{
108 int ai, help=0, version=0, verbose=1;
109 char tacfile[FILENAME_MAX], parfile[FILENAME_MAX], svgfile[FILENAME_MAX];
110 char limfile[FILENAME_MAX];
111 int weights=0; // 0=default, 1=no weighting, 2=frequency
112 unsigned int model=0;
113 double fixed_delay=nan("");
114 double fixed_k=nan("");
115
116
117 /*
118 * Get arguments
119 */
120 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
121 tacfile[0]=parfile[0]=svgfile[0]=limfile[0]=(char)0;
122 model=modelCodeIndex("weibullcdfdd");
123 /* Options */
124 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
125 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
126 char *cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!*cptr) continue;
127 if(strcasecmp(cptr, "W1")==0) {
128 weights=1; continue;
129 } else if(strcasecmp(cptr, "WF")==0) {
130 weights=2; continue;
131 } else if(strcasecmp(cptr, "CDF")==0 || strcasecmp(cptr, "WCDF")==0) {
132 model=modelCodeIndex("weibullcdfd"); continue;
133 } else if(strcasecmp(cptr, "CDFD")==0 || strcasecmp(cptr, "WCDFD")==0) {
134 model=modelCodeIndex("weibullcdfdd"); continue;
135 } else if(strncasecmp(cptr, "DELAY=", 6)==0 && strlen(cptr)>6) {
136 if(!atofCheck(cptr+6, &fixed_delay) && fixed_delay>=0.0) continue;
137 } else if(strncasecmp(cptr, "DT=", 3)==0 && strlen(cptr)>3) {
138 if(!atofCheck(cptr+3, &fixed_delay) && fixed_delay>=0.0) continue;
139 } else if(strncasecmp(cptr, "K=", 2)==0 && strlen(cptr)>2) {
140 if(!atofCheck(cptr+2, &fixed_k) && fixed_k>=0.0) continue;
141 } else if(strncasecmp(cptr, "SVG=", 4)==0 && strlen(cptr)>4) {
142 strlcpy(svgfile, cptr+4, FILENAME_MAX); continue;
143 } else if(strncasecmp(cptr, "LIM=", 4)==0 && strlen(cptr)>4) {
144 strlcpy(limfile, cptr+4, FILENAME_MAX); continue;
145 } else if(strcasecmp(cptr, "LIM")==0) {
146 strcpy(limfile, "stdout"); continue;
147 }
148 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
149 return(1);
150 } else break;
151
152 TPCSTATUS status; statusInit(&status);
153 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
154 status.verbose=verbose-3;
155
156 /* Print help or version? */
157 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
158 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
159 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
160
161 /* Process other arguments, starting from the first non-option */
162 if(ai<argc) strlcpy(tacfile, argv[ai++], FILENAME_MAX);
163 if(ai<argc) strlcpy(parfile, argv[ai++], FILENAME_MAX);
164 if(ai<argc) {
165 fprintf(stderr, "Error: invalid argument '%s'.\n", argv[ai]);
166 return(1);
167 }
168
169 /* In verbose mode print arguments and options */
170 if(verbose>1) {
171 if(tacfile[0]) printf("tacfile := %s\n", tacfile);
172 if(limfile[0]) printf("limfile := %s\n", limfile);
173 if(parfile[0]) printf("parfile := %s\n", parfile);
174 if(svgfile[0]) printf("svgfile := %s\n", svgfile);
175 if(!isnan(fixed_k)) printf("fixed_k := %g\n", fixed_k);
176 if(!isnan(fixed_delay)) printf("fixed_delay := %g\n", fixed_delay);
177 printf("model := %s\n", modelCode(model));
178 printf("weights := %d\n", weights);
179 }
180
181 /* Set parameter names and initial constraints */
182 PAR plim; parInit(&plim); if(parAllocate(&plim, maxParNr, 1)!=TPCERROR_OK) {
183 fprintf(stderr, "Error: cannot initiate parameter list.\n"); return(1);}
184 plim.parNr=maxParNr;
185 strcpy(plim.n[0].name, "dT"); plim.n[0].lim1=0.0; plim.n[0].lim2=100.0;
186 strcpy(plim.n[1].name, "A"); plim.n[1].lim1=1.0E-06; plim.n[1].lim2=1.0E+03;
187 strcpy(plim.n[2].name, "B"); plim.n[2].lim1=1.0E-06; plim.n[2].lim2=20.0;
188 if(model==modelCodeIndex("weibullcdfdd")) {
189 strcpy(plim.n[3].name, "n"); plim.n[3].lim1=0.5; plim.n[3].lim2=4.0;
190 strcpy(plim.n[4].name, "k"); plim.n[4].lim1=0.0; plim.n[4].lim2=5.0;
191 } else {
192 strcpy(plim.n[3].name, "n"); plim.n[3].lim1=1.0E-03; plim.n[3].lim2=4.0;
193 strcpy(plim.n[4].name, "k"); plim.n[4].lim1=0.0; plim.n[4].lim2=0.0;
194 }
195 /* If only file name for parameter constraints was given, then write one and exit */
196 if(limfile[0] && !tacfile[0]) {
197 /* Check that initial value file does not exist */
198 if(strcasecmp(limfile, "stdout")!=0 && fileExist(limfile)) {
199 fprintf(stderr, "Error: parameter constraint file %s exists.\n", limfile);
200 parFree(&plim); return(1);
201 }
202 /* Create parameter file */
203 plim.parNr=modelParNr(model);
204 if(verbose>1 && strcasecmp(limfile, "stdout")!=0)
205 printf("writing parameter constraints file\n");
206 if(parWriteLimits(&plim, limfile, verbose-2)!=TPCERROR_OK) {
207 fprintf(stderr, "Error: cannot write constraints file.\n");
208 parFree(&plim); return(1);
209 }
210 if(strcasecmp(limfile, "stdout")!=0)
211 fprintf(stdout, "Parameter constraints written in %s\n", limfile);
212 parFree(&plim); return(0);
213 }
214
215 /* Did we get all the information that we need? */
216 if(!tacfile[0]) {
217 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
218 parFree(&plim); return(1);
219 }
220 if(strcasecmp(limfile, "stdout")==0) limfile[0]=(char)0;
221
222
223 /*
224 * Read parameter constraints if file for that was given
225 */
226 if(limfile[0]) {
227 if(parReadLimits(&plim, limfile, verbose-2)!=TPCERROR_OK) {
228 fprintf(stderr, "Error: cannot read constraints file.\n");
229 parFree(&plim); return(1);
230 }
231 if(verbose>1) parListLimits(&plim, stdout);
232 }
233 /* Set optional user-defined constraints */
234 if(!isnan(fixed_delay)) plim.n[0].lim1=plim.n[0].lim2=fixed_delay;
235 if(!isnan(fixed_k)) plim.n[4].lim1=plim.n[4].lim2=fixed_k;
236 if(verbose>1) parListLimits(&plim, stdout);
237
238
239
240 /*
241 * Read TAC data
242 */
243 if(verbose>1) printf("reading %s\n", tacfile);
244 TAC tac; tacInit(&tac);
245 if(tacRead(&tac, tacfile, &status)!=TPCERROR_OK) {
246 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
247 tacFree(&tac); parFree(&plim); return(2);
248 }
249 if(verbose>1) {
250 printf("fileformat := %s\n", tacFormattxt(tac.format));
251 printf("tacNr := %d\n", tac.tacNr);
252 printf("sampleNr := %d\n", tac.sampleNr);
253 printf("xunit := %s\n", unitName(tac.tunit));
254 printf("yunit := %s\n", unitName(tac.cunit));
255 printf("isframe := %d\n", tac.isframe);
256 }
257 if(tac.tacNr<1) {
258 fprintf(stderr, "Error: file contains no data.\n");
259 tacFree(&tac); parFree(&plim); return(2);
260 }
261 if(tac.sampleNr<3) {
262 fprintf(stderr, "Error: too few samples.\n");
263 tacFree(&tac); parFree(&plim); return(2);
264 }
265 /* Check NaNs */
266 if(tacNaNs(&tac)>0) {
267 fprintf(stderr, "Error: data contains missing values.\n");
268 tacFree(&tac); parFree(&plim); return(2);
269 }
270 /* Sort data by sample time */
271 tacSortByTime(&tac, &status);
272 /* Get x range */
273 double xmin, xmax;
274 if(tacXRange(&tac, &xmin, &xmax)!=0) {
275 fprintf(stderr, "Error: invalid data sample times.\n");
276 tacFree(&tac); parFree(&plim); return(2);
277 }
278 if(verbose>1) {
279 printf("xmin := %g\n", xmin);
280 printf("xmax := %g\n", xmax);
281 }
282 /* Refine dT limits */
283 if(!limfile[0] && plim.n[0].lim2>plim.n[0].lim1 && xmax<plim.n[0].lim2/0.75)
284 plim.n[0].lim2=0.75*xmax;
285
286 /* Check and set weights */
287 if(weights==0) {
288 if(!tacIsWeighted(&tac)) {
290 for(int i=0; i<tac.sampleNr; i++) tac.w[i]=1.0;
291 }
292 } else if(weights==1) {
294 for(int i=0; i<tac.sampleNr; i++) tac.w[i]=1.0;
295 } else if(weights==2) {
296 if(tacWByFreq(&tac, ISOTOPE_UNKNOWN, &status)!=TPCERROR_OK) {
297 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
298 tacFree(&tac); parFree(&plim); return(2);
299 }
300 }
301
302
303 /*
304 * Copy function parameters into PAR struct for printing and saving
305 */
306 if(verbose>1) printf("preparing space for parameters\n");
307 PAR par; parInit(&par);
308 if(parAllocateWithTAC(&par, &tac, maxParNr, &status)!=TPCERROR_OK) {
309 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
310 tacFree(&tac); parFree(&plim); return(3);
311 }
312 par.tacNr=tac.tacNr; par.parNr=modelParNr(model);
314 for(int i=0; i<tac.tacNr; i++) {
315 par.r[i].model=model;
316 par.r[i].dataNr=tacWSampleNr(&tac);
317 par.r[i].start=xmin;
318 par.r[i].end=xmax;
319 }
320 /* Set parameter names */
321 for(int i=0; i<par.parNr; i++) strcpy(par.n[i].name, plim.n[i].name);
322 /* set time and program name */
323 {
324 char buf[256];
325 time_t t=time(NULL);
326 iftPut(&par.h, "analysis_time", ctime_r_int(&t, buf), 0, NULL);
327 tpcProgramName(argv[0], 1, 1, buf, 256);
328 iftPut(&par.h, "program", buf, 0, NULL);
329 }
330 /* set file names */
331 iftPut(&par.h, "datafile", tacfile, 0, NULL);
332
333
334 /*
335 * Fitting
336 */
337 if(verbose>1) printf("preparing for fitting\n");
338
339 drandSeed(1);
340
341 if(verbose>0) printf("fitting...\n");
342 for(int ci=0; ci<tac.tacNr; ci++) {
343 if(verbose>1) printf("TAC %d: %s\n", 1+ci, tac.c[ci].name);
344 /* Get y range */
345 double ymax; int ymaxi;
346 if(tacYRange(&tac, ci, NULL, &ymax, NULL, &ymaxi, NULL, NULL)!=0) {
347 fprintf(stderr, "Error: invalid y (concentration) values.\n");
348 tacFree(&tac); parFree(&plim); parFree(&par); return(5);
349 }
350 if(verbose>3) printf(" ymax := %g\n", ymax);
351 /* Set data pointers for the fit */
352 double yfit[tac.sampleNr];
353 FITDATA fitdata;
354 fitdata.n=tac.sampleNr;
355 fitdata.x=tac.x;
356 fitdata.ymeas=tac.c[ci].y;
357 fitdata.ysim=yfit;
358 fitdata.w=tac.w;
359 /* Set NLLS options */
360 NLOPT nlo; nloptInit(&nlo);
361 if(nloptAllocate(&nlo, par.parNr)!=TPCERROR_OK) {
362 fprintf(stderr, "Error: cannot initiate NLLS.\n");
363 tacFree(&tac); parFree(&plim); parFree(&par); return(5);
364 }
365 if(model==modelCodeIndex("weibullcdfdd")) nlo._fun=func_wcdfd; else nlo._fun=func_wcdf;
366 nlo.fundata=&fitdata;
367 nlo.totalNr=par.parNr;
368 for(int i=0; i<par.parNr; i++) {
369 nlo.xlower[i]=plim.n[i].lim1;
370 nlo.xupper[i]=plim.n[i].lim2;
371 }
372 for(int i=0; i<par.parNr; i++) {
373 if(!(plim.n[i].lim2>plim.n[i].lim1)) nlo.xtol[i]=0.0;
374 else nlo.xtol[i]=0.0001*(plim.n[i].lim2-plim.n[i].lim1);
375 }
376 nlo.maxFunCalls=50000;
377 /* Fit */
378 if(verbose>4) nloptWrite(&nlo, stdout);
379#if(0)
380 if(nloptITGO2(&nlo, 1, 0, 0, 0, &status)!=TPCERROR_OK) {
381 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
382 tacFree(&tac); parFree(&plim); parFree(&par); nloptFree(&nlo); return(6);
383 }
384#else
385 if(nloptIATGO(&nlo, 1, 0, 0.25, &status)!=TPCERROR_OK) {
386 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
387 tacFree(&tac); parFree(&plim); parFree(&par); nloptFree(&nlo); return(6);
388 }
389#endif
390 nlo._fun(nlo.totalNr, nlo.xfull, nlo.fundata);
391 if(verbose>2) nloptWrite(&nlo, stdout);
392 if(verbose>6) {
393 printf("measured and fitted TAC:\n");
394 for(int i=0; i<tac.sampleNr; i++)
395 printf("\t%g\t%g\t%g\n", tac.x[i], tac.c[ci].y[i], yfit[i]);
396 }
397 //if(verbose>2) printf(" wss := %g\n", nlo.funval);
398
399 /* Copy parameters */
400 for(int i=0; i<par.parNr; i++) par.r[ci].p[i]=nlo.xfull[i];
401 par.r[ci].wss=nlo.funval;
402
403 nloptFree(&nlo);
404 } // next TAC
405
406 /* Print and save parameters */
407 if(verbose>0 || !parfile[0]) parWrite(&par, stdout, PAR_FORMAT_TSV_UK, 1, NULL);
408 if(parfile[0]) {
409 /* Save file */
410 if(verbose>1) printf(" saving %s\n", parfile);
411 FILE *fp=fopen(parfile, "w");
412 if(fp==NULL) {
413 fprintf(stderr, "Error: cannot open file for writing.\n");
414 tacFree(&tac); parFree(&plim); parFree(&par); return(11);
415 }
416 int ret=parWrite(&par, fp, PAR_FORMAT_FIT, 1, &status);
417 fclose(fp);
418 if(ret!=TPCERROR_OK) {
419 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
420 tacFree(&tac); parFree(&plim); parFree(&par); return(12);
421 }
422 if(verbose>0) printf("parameters saved in %s\n", parfile);
423 }
424
425
426
427 /*
428 * Plot measured and fitted data, if requested
429 */
430 if(svgfile[0]) {
431 if(verbose>1) printf("plotting measured and fitted data\n");
432 /* Prepare place for function TAC */
433 double sdist;
434 tacGetSampleInterval(&tac, 1.0E-03, &sdist, NULL);
435 int snr=(int)simSamples(0.2*sdist, 0.0, par.r[0].end-par.r[0].start, 2, NULL);
436 TAC ftac; tacInit(&ftac);
437 int ret=tacAllocate(&ftac, snr, tac.tacNr);
438 if(ret!=TPCERROR_OK) {
439 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
440 tacFree(&tac); parFree(&plim); parFree(&par); return(21);
441 }
442 ftac.tacNr=tac.tacNr; ftac.sampleNr=snr;
443 ret=tacCopyHdr(&tac, &ftac);
444 for(int ci=0; ci<tac.tacNr && ret==0; ci++)
445 ret=tacCopyTacchdr(tac.c+ci, ftac.c+ci);
446 if(ret!=TPCERROR_OK) {
447 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
448 tacFree(&tac); parFree(&plim); parFree(&par); tacFree(&ftac);
449 return(22);
450 }
451 snr=(int)simSamples(0.2*sdist, 0.0, par.r[0].end-par.r[0].start, 2, ftac.x);
452 ftac.isframe=0;
453 for(int i=0; i<ftac.sampleNr; i++) ftac.x[i]+=par.r[0].start;
454 /* Compute function values at sample times */
455 ret=0;
456 for(int ci=0; ci<tac.tacNr && ret==0; ci++)
457 ret=mfEvalY(modelCode(par.r[ci].model), par.parNr, par.r[ci].p,
458 ftac.sampleNr, ftac.x, ftac.c[ci].y, verbose-5);
459 if(ret!=TPCERROR_OK) {
460 fprintf(stderr, "Error: cannot calculate function values.\n");
461 tacFree(&tac); parFree(&plim); parFree(&par); tacFree(&ftac);
462 return(23);
463 }
464 if(verbose>10) tacWrite(&ftac, stdout, TAC_FORMAT_UNKNOWN, 1, NULL);
465 /* Plot */
466 ret=tacPlotFitSVG(&tac, &ftac, "", nan(""), nan(""), nan(""), nan(""), svgfile, &status);
467 if(ret!=TPCERROR_OK) {
468 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
469 tacFree(&tac); parFree(&plim); parFree(&par); tacFree(&ftac);
470 return(24);
471 }
472 tacFree(&ftac);
473 if(verbose>0) printf("Measured and fitted data plotted in %s\n", svgfile);
474 }
475
476
477 tacFree(&tac);
478 parFree(&plim);
479 parFree(&par);
480 return(0);
481}
482/*****************************************************************************/
483
484/*****************************************************************************
485 *
486 * Functions to be minimized
487 *
488 *****************************************************************************/
489double func_wcdfd(int parNr, double *p, void *fdata)
490{
491 double v, wss=0.0;
492 FITDATA *d=(FITDATA*)fdata;
493
494 /* Calculate the curve values and weighted SS */
495 for(unsigned int i=0; i<d->n; i++) {
496 d->ysim[i]=0.0;
497 if(isnan(d->ymeas[i]) || isnan(d->x[i])) continue;
498 double x=d->x[i]-p[0];
499 if(x>0.0) {
500 double et=exp(-pow(x/p[2], p[3]));
501 double wpdf=(p[3]/p[2]) * pow(x/p[2], p[3]-1.0) * et;
502 d->ysim[i]=p[1]*(wpdf + p[4]*(1.0-et));
503 }
504 v=d->ysim[i]-d->ymeas[i];
505 wss+=d->w[i]*v*v;
506 }
507 if(0) {
508 for(unsigned int i=0; i<(unsigned int)parNr; i++) printf(" %g", p[i]);
509 printf(" -> %g\n", wss);
510 }
511 return(wss);
512}
513
514double func_wcdf(int parNr, double *p, void *fdata)
515{
516 double v, wss=0.0;
517 FITDATA *d=(FITDATA*)fdata;
518
519 /* Calculate the curve values and weighted SS */
520 for(unsigned int i=0; i<d->n; i++) {
521 d->ysim[i]=0.0;
522 if(isnan(d->ymeas[i]) || isnan(d->x[i])) continue;
523 double x=d->x[i]-p[0];
524 if(x>0.0) {
525 d->ysim[i]=p[1]*(1.0 - exp(-pow(x/p[2], p[3])));
526 }
527 v=d->ysim[i]-d->ymeas[i];
528 wss+=d->w[i]*v*v;
529 }
530 if(0) {
531 for(unsigned int i=0; i<(unsigned int)parNr; i++) printf(" %g", p[i]);
532 printf(" -> %g\n", wss);
533 }
534 return(wss);
535}
536/*****************************************************************************/
537
538/*****************************************************************************/
char * ctime_r_int(const time_t *t, char *buf)
Convert calendar time t into a null-terminated string of the form YYYY-MM-DD hh:mm:ss,...
Definition datetime.c:119
int atofCheck(const char *s, double *v)
Definition decpoint.c:94
int fileExist(const char *filename)
Definition filexist.c:17
int mfEvalY(const char *fid, const int parNr, const double *p, const int sampleNr, const double *x, double *y, const int verbose)
Definition func.c:26
unsigned int drandSeed(short int seed)
Make and optionally set the seed for rand(), drand, drandRange, and drandGaussian().
Definition gaussdev.c:27
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition ift.c:63
unsigned int simSamples(double initStep, double maxStep, double endTime, int mode, double *x)
Definition interpolate.c:50
char * modelCode(const unsigned int i)
Definition modell.c:176
unsigned int modelParNr(const unsigned int code)
Definition modell.c:256
unsigned int modelCodeIndex(const char *s)
Definition modell.c:237
void nloptInit(NLOPT *nlo)
Definition nlopt.c:25
int nloptAllocate(NLOPT *nlo, unsigned int parNr)
Definition nlopt.c:74
void nloptFree(NLOPT *nlo)
Definition nlopt.c:52
void nloptWrite(NLOPT *d, FILE *fp)
Definition nlopt.c:302
void parFree(PAR *par)
Definition par.c:75
int parAllocate(PAR *par, int parNr, int tacNr)
Definition par.c:108
void parInit(PAR *par)
Definition par.c:25
int parWrite(PAR *par, FILE *fp, parformat format, int extra, TPCSTATUS *status)
Definition pario.c:148
int parReadLimits(PAR *par, const char *fname, const int verbose)
Definition pario.c:489
void parListLimits(PAR *par, FILE *fp)
Definition pario.c:406
int parWriteLimits(PAR *par, const char *fname, const int verbose)
Definition pario.c:432
int parAllocateWithTAC(PAR *par, TAC *tac, int parNr, TPCSTATUS *status)
Allocate PAR based on data in TAC.
Definition partac.c:90
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:47
void tpcProgramName(const char *program, int version, int copyright, char *prname, int n)
Definition proginfo.c:406
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:169
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:339
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:114
void statusInit(TPCSTATUS *s)
Definition statusmsg.c:104
char * errorMsg(tpcerror e)
Definition statusmsg.c:68
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition stringext.c:632
double(* _fun)(int, double *, void *)
Definition tpcnlopt.h:42
double funval
Definition tpcnlopt.h:50
unsigned int maxFunCalls
Definition tpcnlopt.h:46
double * xupper
Definition tpcnlopt.h:33
double * xlower
Definition tpcnlopt.h:31
void * fundata
Definition tpcnlopt.h:44
double * xfull
Definition tpcnlopt.h:29
double * xtol
Definition tpcnlopt.h:39
unsigned int totalNr
Definition tpcnlopt.h:27
Definition tpcpar.h:100
int format
Definition tpcpar.h:102
IFT h
Optional (but often useful) header information.
Definition tpcpar.h:147
int parNr
Definition tpcpar.h:108
int tacNr
Definition tpcpar.h:104
PARR * r
Definition tpcpar.h:114
PARN * n
Definition tpcpar.h:112
double lim2
Definition tpcpar.h:90
char name[MAX_PARNAME_LEN+1]
Definition tpcpar.h:82
double lim1
Definition tpcpar.h:88
double wss
Definition tpcpar.h:72
int dataNr
Definition tpcpar.h:62
unsigned int model
Definition tpcpar.h:48
double * p
Definition tpcpar.h:64
double start
Definition tpcpar.h:52
double end
Definition tpcpar.h:54
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
double * y
Definition tpctac.h:75
Definition tpctac.h:87
double * x
Definition tpctac.h:97
unit cunit
Definition tpctac.h:105
tacformat format
Definition tpctac.h:93
int sampleNr
Definition tpctac.h:89
double * w
Definition tpctac.h:111
int isframe
Definition tpctac.h:95
TACC * c
Definition tpctac.h:117
weights weighting
Definition tpctac.h:115
unit tunit
Definition tpctac.h:109
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
void tacFree(TAC *tac)
Definition tac.c:106
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition tac.c:130
void tacInit(TAC *tac)
Definition tac.c:24
int tacCopyTacchdr(TACC *d1, TACC *d2)
Definition tac.c:282
int tacCopyHdr(TAC *tac1, TAC *tac2)
Copy TAC header data from tac1 to tac2.
Definition tac.c:310
int tacPlotFitSVG(TAC *tac1, TAC *tac2, const char *main_title, const double x1, const double x2, const double y1, const double y2, const char *fname, TPCSTATUS *status)
Definition tacfitplot.c:27
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
Definition tacio.c:413
char * tacFormattxt(tacformat c)
Definition tacio.c:98
int tacWrite(TAC *tac, FILE *fp, tacformat format, int extra, TPCSTATUS *status)
Definition tacio.c:332
int tacNaNs(TAC *tac)
Definition tacnan.c:71
int tacSortByTime(TAC *d, TPCSTATUS *status)
Definition tacorder.c:74
int tacIsWeighted(TAC *tac)
Definition tacw.c:24
unsigned int tacWSampleNr(TAC *tac)
Definition tacw.c:219
int tacWByFreq(TAC *tac, isotope isot, TPCSTATUS *status)
Definition tacw.c:134
int tacGetSampleInterval(TAC *d, double ilimit, double *minfdur, double *maxfdur)
Get the shortest and longest sampling intervals or frame lengths in TAC structure.
Definition tacx.c:832
int tacXRange(TAC *d, double *xmin, double *xmax)
Get the range of x values (times) in TAC structure.
Definition tacx.c:124
int tacYRange(TAC *d, int i, double *ymin, double *ymax, int *smin, int *smax, int *imin, int *imax)
Get the range of y values (concentrations) in TAC struct.
Definition tacy.c:26
int nloptIATGO(NLOPT *nlo, const int doLocal, unsigned int maxIterNr, double neighFract, TPCSTATUS *status)
Definition tgo.c:681
int nloptITGO2(NLOPT *nlo, const int doLocal, unsigned int tgoNr, unsigned int sampleNr, unsigned int neighNr, TPCSTATUS *status)
Definition tgo.c:342
Header file for library libtpcextensions.
weights
Is data weighted, or are weight factors available with data?
@ WEIGHTING_OFF
Not weighted or weights not available (weights for all included samples are 1.0).
@ TPCERROR_OK
No error.
char * unitName(int unit_code)
Definition units.c:143
Header file for libtpcfileutil.
Header file for library libtpcift.
@ ISOTOPE_UNKNOWN
Unknown.
Definition tpcisotope.h:51
Header file for library libtpcnlopt.
Header file for libtpcpar.
@ PAR_FORMAT_FIT
Function fit format of Turku PET Centre.
Definition tpcpar.h:30
@ PAR_FORMAT_TSV_UK
UK TSV (point as decimal separator).
Definition tpcpar.h:35
Header file for libtpcrand.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.
Definition tpctac.h:28
Header file for libtpctacmod.