TPCCLIB
Loading...
Searching...
No Matches
fit_suri.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <math.h>
14/*****************************************************************************/
15#include "tpcextensions.h"
16#include "tpcift.h"
17#include "tpctac.h"
18#include "tpcpar.h"
19#include "tpctacmod.h"
20#include "tpcrand.h"
21#include "tpcnlopt.h"
22#include "tpcfileutil.h"
23/*****************************************************************************/
24
25/*****************************************************************************/
26/* Local functions */
27double func_suri(int parNr, double *p, void*);
28/*****************************************************************************/
29
30/*****************************************************************************/
31typedef struct FITDATA {
33 unsigned int n;
35 double *x;
37 double *ymeas;
39 double *ysim;
41 double *w;
42} FITDATA;
43const int maxParNr=4;
44/*****************************************************************************/
45
46/*****************************************************************************/
47static char *info[] = {
48 "Non-linear fitting of the Surge function plus integral (recirculation)",
49 "to PET time-activity curves (TACs).",
50 " ",
51 "Function:",
52 " when x<=dT, f(x) = 0 ",
53 " when x>dT, f(x) = A*(x-dT)*exp(-B*(x-dT)) + ",
54 " (C*A/B^2)*(1-exp(-B*(x-dT))-B*(x-dT)*exp(-B*(x-dT)))",
55 ", where A>=0, B>=0, C>=0, and dT>=0.",
56 " ",
57 "Usage: @P [Options] tacfile [parfile]",
58 " ",
59 "Options:",
60 " -w1 | -wf",
61 " All weights are set to 1.0 (no weighting), or weights are based on",
62 " sampling interval. By default, weights in tacfile are used, if available.",
63 " -lim[=<filename>]",
64 " Specify the constraints for function parameters;",
65 " This file with default values can be created by giving this option",
66 " as the only command-line argument to this program.",
67 " Without file name the default values are printed on screen.",
68 " Setting feasible limits are highly recommended.",
69 " -svg=<Filename>",
70 " Fitted and measured TACs are plotted in specified SVG file.",
71 " -stdoptions", // List standard options like --help, -v, etc
72 " ",
73 "See also: fit_sinf, fit_feng, fit_ratf, fit2dat",
74 " ",
75 "Keywords: TAC, curve fitting",
76 0};
77/*****************************************************************************/
78
79/*****************************************************************************/
80/* Turn on the globbing of the command line, since it is disabled by default in
81 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
82 In Unix&Linux wildcard command line processing is enabled by default. */
83/*
84#undef _CRT_glob
85#define _CRT_glob -1
86*/
87int _dowildcard = -1;
88/*****************************************************************************/
89
90/*****************************************************************************/
94int main(int argc, char **argv)
95{
96 int ai, help=0, version=0, verbose=1;
97 char tacfile[FILENAME_MAX], parfile[FILENAME_MAX], svgfile[FILENAME_MAX];
98 char limfile[FILENAME_MAX];
99 int weights=0; // 0=default, 1=no weighting, 2=frequency
100 unsigned int model=0;
101
102
103 /*
104 * Get arguments
105 */
106 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
107 tacfile[0]=parfile[0]=svgfile[0]=limfile[0]=(char)0;
108 model=modelCodeIndex("surgerecircd");
109 /* Options */
110 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
111 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
112 char *cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!*cptr) continue;
113 if(strcasecmp(cptr, "W1")==0) {
114 weights=1; continue;
115 } else if(strcasecmp(cptr, "WF")==0) {
116 weights=2; continue;
117 } else if(strncasecmp(cptr, "SVG=", 4)==0 && strlen(cptr)>4) {
118 strlcpy(svgfile, cptr+4, FILENAME_MAX); continue;
119 } else if(strncasecmp(cptr, "LIM=", 4)==0 && strlen(cptr)>4) {
120 strlcpy(limfile, cptr+4, FILENAME_MAX); continue;
121 } else if(strcasecmp(cptr, "LIM")==0) {
122 strcpy(limfile, "stdout"); continue;
123 }
124 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
125 return(1);
126 } else break;
127
128 TPCSTATUS status; statusInit(&status);
129 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
130 status.verbose=verbose-3;
131
132 /* Print help or version? */
133 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
134 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
135 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
136
137 /* Process other arguments, starting from the first non-option */
138 if(ai<argc) strlcpy(tacfile, argv[ai++], FILENAME_MAX);
139 if(ai<argc) strlcpy(parfile, argv[ai++], FILENAME_MAX);
140 if(ai<argc) {
141 fprintf(stderr, "Error: invalid argument '%s'.\n", argv[ai]);
142 return(1);
143 }
144
145 /* In verbose mode print arguments and options */
146 if(verbose>1) {
147 if(tacfile[0]) printf("tacfile := %s\n", tacfile);
148 if(limfile[0]) printf("limfile := %s\n", limfile);
149 if(parfile[0]) printf("parfile := %s\n", parfile);
150 if(svgfile[0]) printf("svgfile := %s\n", svgfile);
151 printf("model := %s\n", modelCode(model));
152 printf("weights := %d\n", weights);
153 }
154
155 /* Set parameter names and initial constraints */
156 PAR plim; parInit(&plim); if(parAllocate(&plim, maxParNr, 1)!=TPCERROR_OK) {
157 fprintf(stderr, "Error: cannot initiate parameter list.\n"); return(1);}
158 plim.parNr=maxParNr;
159 strcpy(plim.n[0].name, "A"); plim.n[0].lim1=0.0; plim.n[0].lim2=1.0E+04;
160 strcpy(plim.n[1].name, "B"); plim.n[1].lim1=1.0E-06; plim.n[1].lim2=1.0E+01;
161 strcpy(plim.n[2].name, "C"); plim.n[2].lim1=1.0E-06; plim.n[2].lim2=1.0E+03;
162 strcpy(plim.n[3].name, "D"); plim.n[3].lim1=0.0; plim.n[3].lim2=1.0;
163 /* If only file name for parameter constraints was given, then write one and exit */
164 if(limfile[0] && !tacfile[0]) {
165 /* Check that initial value file does not exist */
166 if(strcasecmp(limfile, "stdout")!=0 && fileExist(limfile)) {
167 fprintf(stderr, "Error: parameter constraint file %s exists.\n", limfile);
168 parFree(&plim); return(1);
169 }
170 /* Create parameter file */
171 plim.parNr=modelParNr(model);
172 if(verbose>1 && strcasecmp(limfile, "stdout")!=0)
173 printf("writing parameter constraints file\n");
174 if(parWriteLimits(&plim, limfile, verbose-2)!=TPCERROR_OK) {
175 fprintf(stderr, "Error: cannot write constraints file.\n");
176 parFree(&plim); return(1);
177 }
178 if(strcasecmp(limfile, "stdout")!=0)
179 fprintf(stdout, "Parameter constraints written in %s\n", limfile);
180 parFree(&plim); return(0);
181 }
182
183 /* Did we get all the information that we need? */
184 if(!tacfile[0]) {
185 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
186 parFree(&plim); return(1);
187 }
188 if(strcasecmp(limfile, "stdout")==0) limfile[0]=(char)0;
189
190
191 /*
192 * Read parameter constraints if file for that was given
193 */
194 if(limfile[0]) {
195 if(parReadLimits(&plim, limfile, verbose-2)!=TPCERROR_OK) {
196 fprintf(stderr, "Error: cannot read constraints file.\n");
197 parFree(&plim); return(1);
198 }
199 }
200 if(verbose>1) parListLimits(&plim, stdout);
201
202
203
204 /*
205 * Read TAC data
206 */
207 if(verbose>1) printf("reading %s\n", tacfile);
208 TAC tac; tacInit(&tac);
209 if(tacRead(&tac, tacfile, &status)!=TPCERROR_OK) {
210 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
211 tacFree(&tac); parFree(&plim); return(2);
212 }
213 if(verbose>1) {
214 printf("fileformat := %s\n", tacFormattxt(tac.format));
215 printf("tacNr := %d\n", tac.tacNr);
216 printf("sampleNr := %d\n", tac.sampleNr);
217 printf("xunit := %s\n", unitName(tac.tunit));
218 printf("yunit := %s\n", unitName(tac.cunit));
219 printf("isframe := %d\n", tac.isframe);
220 }
221 if(tac.tacNr<1) {
222 fprintf(stderr, "Error: file contains no data.\n");
223 tacFree(&tac); parFree(&plim); return(2);
224 }
225 if(tac.sampleNr<3) {
226 fprintf(stderr, "Error: too few samples.\n");
227 tacFree(&tac); parFree(&plim); return(2);
228 }
229 /* Check NaNs */
230 if(tacNaNs(&tac)>0) {
231 fprintf(stderr, "Error: data contains missing values.\n");
232 tacFree(&tac); parFree(&plim); return(2);
233 }
234 /* Sort data by sample time */
235 tacSortByTime(&tac, &status);
236 /* Get x range */
237 double xmin, xmax;
238 if(tacXRange(&tac, &xmin, &xmax)!=0) {
239 fprintf(stderr, "Error: invalid data sample times.\n");
240 tacFree(&tac); parFree(&plim); return(2);
241 }
242 if(verbose>1) {
243 printf("xmin := %g\n", xmin);
244 printf("xmax := %g\n", xmax);
245 }
246 /* Refine dT limits */
247 if(!limfile[0] && plim.n[0].lim2>plim.n[0].lim1 && xmax<plim.n[0].lim2/0.75)
248 plim.n[0].lim2=0.75*xmax;
249
250 /* Check and set weights */
251 if(weights==0) {
252 if(!tacIsWeighted(&tac)) {
254 for(int i=0; i<tac.sampleNr; i++) tac.w[i]=1.0;
255 }
256 } else if(weights==1) {
258 for(int i=0; i<tac.sampleNr; i++) tac.w[i]=1.0;
259 } else if(weights==2) {
260 if(tacWByFreq(&tac, ISOTOPE_UNKNOWN, &status)!=TPCERROR_OK) {
261 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
262 tacFree(&tac); parFree(&plim); return(2);
263 }
264 }
265
266
267 /*
268 * Copy function parameters into PAR structure for printing and saving
269 */
270 if(verbose>1) printf("preparing space for parameters\n");
271 PAR par; parInit(&par);
272 if(parAllocateWithTAC(&par, &tac, maxParNr, &status)!=TPCERROR_OK) {
273 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
274 tacFree(&tac); parFree(&plim); return(3);
275 }
276 par.tacNr=tac.tacNr; par.parNr=modelParNr(model);
278 for(int i=0; i<tac.tacNr; i++) {
279 par.r[i].model=model;
280 par.r[i].dataNr=tacWSampleNr(&tac);
281 par.r[i].start=xmin;
282 par.r[i].end=xmax;
283 }
284 /* Set parameter names */
285 for(int i=0; i<par.parNr; i++) strcpy(par.n[i].name, plim.n[i].name);
286 /* set time and program name */
287 {
288 char buf[256];
289 time_t t=time(NULL);
290 iftPut(&par.h, "analysis_time", ctime_r_int(&t, buf), 0, NULL);
291 tpcProgramName(argv[0], 1, 1, buf, 256);
292 iftPut(&par.h, "program", buf, 0, NULL);
293 }
294 /* set file names */
295 iftPut(&par.h, "datafile", tacfile, 0, NULL);
296
297
298 /*
299 * Fitting
300 */
301 if(verbose>1) printf("preparing for fitting\n");
302
303 drandSeed(1);
304
305 if(verbose>0) printf("fitting...\n");
306 for(int ci=0; ci<tac.tacNr; ci++) {
307 if(verbose>1) printf("TAC %d: %s\n", 1+ci, tac.c[ci].name);
308 /* Get y range */
309 double ymax; int ymaxi;
310 if(tacYRange(&tac, ci, NULL, &ymax, NULL, &ymaxi, NULL, NULL)!=0) {
311 fprintf(stderr, "Error: invalid y (concentration) values.\n");
312 tacFree(&tac); parFree(&plim); parFree(&par); return(5);
313 }
314 if(verbose>3) printf(" ymax := %g\n", ymax);
315 /* Set data pointers for the fit */
316 double yfit[tac.sampleNr];
317 FITDATA fitdata;
318 fitdata.n=tac.sampleNr;
319 fitdata.x=tac.x;
320 fitdata.ymeas=tac.c[ci].y;
321 fitdata.ysim=yfit;
322 fitdata.w=tac.w;
323 /* Set NLLS options */
324 NLOPT nlo; nloptInit(&nlo);
325 if(nloptAllocate(&nlo, par.parNr)!=TPCERROR_OK) {
326 fprintf(stderr, "Error: cannot initiate NLLS.\n");
327 tacFree(&tac); parFree(&plim); parFree(&par); return(5);
328 }
329 nlo._fun=func_suri;
330 nlo.fundata=&fitdata;
331 nlo.totalNr=par.parNr;
332 for(int i=0; i<par.parNr; i++) {
333 nlo.xlower[i]=plim.n[i].lim1;
334 nlo.xupper[i]=plim.n[i].lim2;
335 }
336 for(int i=0; i<par.parNr; i++) {
337 if(!(plim.n[i].lim2>plim.n[i].lim1)) nlo.xtol[i]=0.0;
338 else nlo.xtol[i]=0.0001*(plim.n[i].lim2-plim.n[i].lim1);
339 }
340 nlo.maxFunCalls=50000;
341 /* Fit */
342 if(verbose>4) nloptWrite(&nlo, stdout);
343#if(1)
344 if(nloptSimplexARRS(&nlo, 0, &status)!=TPCERROR_OK) {
345 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
346 tacFree(&tac); parFree(&plim); parFree(&par); nloptFree(&nlo); return(6);
347 }
348#else
349 if(nloptIATGO(&nlo, 1, 0, 0.25, &status)!=TPCERROR_OK) {
350 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
351 tacFree(&tac); parFree(&plim); parFree(&par); nloptFree(&nlo); return(6);
352 }
353#endif
354 nlo._fun(nlo.totalNr, nlo.xfull, nlo.fundata);
355 if(verbose>2) nloptWrite(&nlo, stdout);
356 if(verbose>6) {
357 printf("measured and fitted TAC:\n");
358 for(int i=0; i<tac.sampleNr; i++)
359 printf("\t%g\t%g\t%g\n", tac.x[i], tac.c[ci].y[i], yfit[i]);
360 }
361 //if(verbose>2) printf(" wss := %g\n", nlo.funval);
362
363 /* Copy parameters */
364 for(int i=0; i<par.parNr; i++) par.r[ci].p[i]=nlo.xfull[i];
365 par.r[ci].wss=nlo.funval;
366
367 nloptFree(&nlo);
368 } // next TAC
369
370 /* Print and save parameters */
371 if(verbose>0 || !parfile[0]) parWrite(&par, stdout, PAR_FORMAT_TSV_UK, 1, NULL);
372 if(parfile[0]) {
373 /* Save file */
374 if(verbose>1) printf(" saving %s\n", parfile);
375 FILE *fp=fopen(parfile, "w");
376 if(fp==NULL) {
377 fprintf(stderr, "Error: cannot open file for writing.\n");
378 tacFree(&tac); parFree(&plim); parFree(&par); return(11);
379 }
380 int ret=parWrite(&par, fp, PAR_FORMAT_FIT, 1, &status);
381 fclose(fp);
382 if(ret!=TPCERROR_OK) {
383 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
384 tacFree(&tac); parFree(&plim); parFree(&par); return(12);
385 }
386 if(verbose>0) printf("parameters saved in %s\n", parfile);
387 }
388
389
390
391 /*
392 * Plot measured and fitted data, if requested
393 */
394 if(svgfile[0]) {
395 if(verbose>1) printf("plotting measured and fitted data\n");
396 /* Prepare place for function TAC */
397 double sdist;
398 tacGetSampleInterval(&tac, 1.0E-03, &sdist, NULL);
399 int snr=(int)simSamples(0.2*sdist, 0.0, par.r[0].end-par.r[0].start, 2, NULL);
400 TAC ftac; tacInit(&ftac);
401 int ret=tacAllocate(&ftac, snr, tac.tacNr);
402 if(ret!=TPCERROR_OK) {
403 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
404 tacFree(&tac); parFree(&plim); parFree(&par); return(21);
405 }
406 ftac.tacNr=tac.tacNr; ftac.sampleNr=snr;
407 ret=tacCopyHdr(&tac, &ftac);
408 for(int ci=0; ci<tac.tacNr && ret==0; ci++)
409 ret=tacCopyTacchdr(tac.c+ci, ftac.c+ci);
410 if(ret!=TPCERROR_OK) {
411 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
412 tacFree(&tac); parFree(&plim); parFree(&par); tacFree(&ftac);
413 return(22);
414 }
415 snr=(int)simSamples(0.2*sdist, 0.0, par.r[0].end-par.r[0].start, 2, ftac.x);
416 ftac.isframe=0;
417 for(int i=0; i<ftac.sampleNr; i++) ftac.x[i]+=par.r[0].start;
418 /* Compute function values at sample times */
419 ret=0;
420 for(int ci=0; ci<tac.tacNr && ret==0; ci++)
421 ret=mfEvalY(modelCode(par.r[ci].model), par.parNr, par.r[ci].p,
422 ftac.sampleNr, ftac.x, ftac.c[ci].y, verbose-5);
423 if(ret!=TPCERROR_OK) {
424 fprintf(stderr, "Error: cannot calculate function values.\n");
425 tacFree(&tac); parFree(&plim); parFree(&par); tacFree(&ftac);
426 return(23);
427 }
428 if(verbose>10) tacWrite(&ftac, stdout, TAC_FORMAT_UNKNOWN, 1, NULL);
429 /* Plot */
430 ret=tacPlotFitSVG(&tac, &ftac, "", nan(""), nan(""), nan(""), nan(""), svgfile, &status);
431 if(ret!=TPCERROR_OK) {
432 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
433 tacFree(&tac); parFree(&plim); parFree(&par); tacFree(&ftac);
434 return(24);
435 }
436 tacFree(&ftac);
437 if(verbose>0) printf("Measured and fitted data plotted in %s\n", svgfile);
438 }
439
440
441 tacFree(&tac);
442 parFree(&plim);
443 parFree(&par);
444 return(0);
445}
446/*****************************************************************************/
447
448/*****************************************************************************
449 *
450 * Functions to be minimized
451 *
452 *****************************************************************************/
453double func_suri(int parNr, double *p, void *fdata)
454{
455 double v, wss=0.0;
456 FITDATA *d=(FITDATA*)fdata;
457
458 /* Calculate the curve values and weighted SS */
459 for(unsigned int i=0; i<d->n; i++) {
460 d->ysim[i]=0.0;
461 if(isnan(d->ymeas[i]) || isnan(d->x[i])) continue;
462 double x=d->x[i]-p[3];
463 if(x>0.0) {
464 double a=p[0];
465 double b=p[1];
466 double c=p[2];
467 double e=exp(-b*x);
468 d->ysim[i]=x*e + (c/(b*b))*(1.0-(b*x+1.0)*e);
469 d->ysim[i]*=a;
470 }
471 v=d->ysim[i]-d->ymeas[i];
472 wss+=d->w[i]*v*v;
473 }
474 if(0) {
475 for(unsigned int i=0; i<(unsigned int)parNr; i++) printf(" %g", p[i]);
476 printf(" -> %g\n", wss);
477 }
478 return(wss);
479}
480/*****************************************************************************/
481
482/*****************************************************************************/
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 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
int nloptSimplexARRS(NLOPT *nlo, unsigned int maxIter, TPCSTATUS *status)
Definition simplex.c:373
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
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.