TPCCLIB
Loading...
Searching...
No Matches
fit_xexp.c
Go to the documentation of this file.
1
8/*****************************************************************************/
9#include "tpcclibConfig.h"
10/*****************************************************************************/
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <math.h>
15/*****************************************************************************/
16#include "tpcextensions.h"
17#include "tpcift.h"
18#include "tpctac.h"
19#include "tpcpar.h"
20#include "tpcli.h"
21#include "tpccm.h"
22#include "tpctacmod.h"
23#include "tpclinopt.h"
24#include "tpcrand.h"
25#include "tpcnlopt.h"
26/*****************************************************************************/
27
28/*****************************************************************************/
29/* Local functions */
30double func_xexp(int parNr, double *p, void*);
31/*****************************************************************************/
32typedef struct FITDATA {
34 unsigned int in;
36 double *ix;
38 double *iy;
40 double *kernel;
42 double *cy;
43
45 unsigned int n;
47 double *x;
49 double *y;
51 double *ysim;
53 double *w;
55 int verbose;
56} FITDATA;
57/*****************************************************************************/
58
59/*****************************************************************************/
60static char *info[] = {
61 "Non-linear fitting of the parameters of response function, convolved with",
62 "input TAC, to reproduce given output TAC:",
63 " output(t) = input(t) (x) h(t)",
64 "Response function is:",
65 " h(t) = a1*exp(-b1*t) + a2*exp(-b2*t)",
66 " ",
67 "Usage: @P [Options] inputfile outputfile [parfile]",
68 " ",
69 "Options:",
70 " -a=<value>",
71 " Constrain h(t) integral (AUC) from zero to infinity (a1/b1 + a2/b2)",
72 " to specified value; fitted by default.",
73 " -amin=<value>",
74 " Minimum value for AUC; by default 0.1.",
75 " -amax=<value>",
76 " Maximum value for AUC; by default 1.0.",
77 " -w1",
78 " All weights are set to 1.0 (no weighting); by default, weights in",
79 " output data file are used, if available.",
80 " -wf",
81 " Weight by output TAC sampling interval.",
82 " -svg=<Filename>",
83 " Fitted and measured TACs are plotted in specified SVG file.",
84 " -i=<Interval>",
85 " Sample time interval (sec) in convolution; by default the shortest",
86 " interval in the input data; too long interval as compared to b leads",
87 " to bias.",
88 " -stdoptions", // List standard options like --help, -v, etc
89 " ",
90 "If TAC files contain more than one TAC, only the first is used.",
91 " ",
92 "See also: convexpf, sim_av",
93 " ",
94 "Keywords: TAC, curve fitting, convolution",
95 0};
96/*****************************************************************************/
97
98/*****************************************************************************/
99/* Turn on the globbing of the command line, since it is disabled by default in
100 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
101 In Unix&Linux wildcard command line processing is enabled by default. */
102/*
103#undef _CRT_glob
104#define _CRT_glob -1
105*/
106int _dowildcard = -1;
107/*****************************************************************************/
108
109/*****************************************************************************/
113int main(int argc, char **argv)
114{
115 int ai, help=0, version=0, verbose=1;
116 char inpfile[FILENAME_MAX], outfile[FILENAME_MAX], parfile[FILENAME_MAX], svgfile[FILENAME_MAX];
117 int weights=0; // 0=default, 1=no weighting, 2=frequency
118 double amin=0.1, amax=1.0;
119 double interval=nan("");
120 int ret;
121
122
123 /*
124 * Get arguments
125 */
126 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
127 inpfile[0]=outfile[0]=parfile[0]=svgfile[0]=(char)0;
128 /* Options */
129 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
130 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
131 char *cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(!*cptr) continue;
132 if(strcasecmp(cptr, "W1")==0) {
133 weights=1; continue;
134 } else if(strcasecmp(cptr, "WF")==0) {
135 weights=2; continue;
136 } else if(strncasecmp(cptr, "SVG=", 4)==0 && strlen(cptr)>4) {
137 strlcpy(svgfile, cptr+4, FILENAME_MAX); continue;
138 } else if(strncasecmp(cptr, "AMIN=", 5)==0) {
139 amin=atofVerified(cptr+5); if(amin>0.0) continue;
140 } else if(strncasecmp(cptr, "AMAX=", 5)==0) {
141 amax=atofVerified(cptr+5); if(amax>0.0) continue;
142 } else if(strncasecmp(cptr, "A=", 2)==0) {
143 amin=amax=atofVerified(cptr+2); if(amin>0.0) continue;
144 } else if(strncasecmp(cptr, "I=", 2)==0) {
145 interval=atofVerified(cptr+2); if(interval>0.0) continue;
146 }
147 fprintf(stderr, "Error: invalid option '%s'.\n", argv[ai]);
148 return(1);
149 } else break;
150
151 TPCSTATUS status; statusInit(&status);
152 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
153 status.verbose=verbose-3;
154
155 /* Print help or version? */
156 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
157 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
158 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
159
160 /* Process other arguments, starting from the first non-option */
161 if(ai<argc) strlcpy(inpfile, argv[ai++], FILENAME_MAX);
162 if(ai<argc) strlcpy(outfile, 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 /* Did we get all the information that we need? */
169 if(!outfile[0]) { // note that parameter file is optional
170 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
171 return(1);
172 }
173 /* Check parameters */
174 if(amin>amax) {
175 fprintf(stderr, "Error: invalid limits for a.\n");
176 return(1);
177 }
178
179 /* In verbose mode print arguments and options */
180 if(verbose>1) {
181 printf("inpfile := %s\n", inpfile);
182 printf("outfile := %s\n", outfile);
183 if(parfile[0]) printf("parfile := %s\n", parfile);
184 if(svgfile[0]) printf("svgfile := %s\n", svgfile);
185 printf("amin := %g\n", amin);
186 printf("amax := %g\n", amax);
187 printf("weights := %d\n", weights);
188 if(!isnan(interval)) printf("interval := %g\n", interval);
189 fflush(stdout);
190 }
191
192
193 /*
194 * Read input and output data
195 */
196 if(verbose>1) printf("reading TAC data\n");
197 statusSet(&status, __func__, __FILE__, __LINE__, TPCERROR_OK);
198 TAC itac, otac; tacInit(&itac); tacInit(&otac);
199 int fitSampleNr;
200 double fitdur=1.0E+12;
201 ret=tacReadModelingData(outfile, inpfile, NULL, NULL, &fitdur, 0,
202 &fitSampleNr, &otac, &itac, &status);
203 if(ret!=TPCERROR_OK) {
204 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
205 tacFree(&itac); tacFree(&otac); return(2);
206 }
207 if(verbose>2) {
208 printf("fileformat := %s\n", tacFormattxt(itac.format));
209 printf("inp.sampleNr := %d\n", itac.sampleNr);
210 printf("out.sampleNr := %d\n", otac.sampleNr);
211 printf("fitSampleNr := %d\n", fitSampleNr);
212 printf("xunit := %s\n", unitName(itac.tunit));
213 printf("yunit := %s\n", unitName(itac.cunit));
214 printf("fitdur := %g s\n", fitdur);
215 }
216 if(fitSampleNr<4 || itac.sampleNr<4) {
217 fprintf(stderr, "Error: too few samples.\n");
218 tacFree(&itac); tacFree(&otac); return(2);
219 }
220 /* Set second output TAC to place fitted data into */
221 otac.tacNr=1;
222 ret=tacAllocateMore(&otac, 1);
223 if(ret!=TPCERROR_OK) {
224 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
225 tacFree(&itac); tacFree(&otac); return(2);
226 }
227 /* Check and set weights */
228 if(weights==0) {
229 if(!tacIsWeighted(&otac)) {
231 for(int i=0; i<otac.sampleNr; i++) otac.w[i]=1.0;
232 }
233 } else if(weights==1) {
235 for(int i=0; i<otac.sampleNr; i++) otac.w[i]=1.0;
236 } else if(weights==2) {
237 ret=tacWByFreq(&otac, ISOTOPE_UNKNOWN, &status);
238 if(ret!=TPCERROR_OK) {
239 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
240 tacFree(&itac); tacFree(&otac); return(2);
241 }
242 }
243
244 /* Sample times should now be in minutes; convert interval to minutes, too. */
245 if(interval>0.0) {
246 interval/=60.0;
247
248 if(interval>0.1*itac.x[itac.sampleNr-1]) {
249 fprintf(stderr, "Error: too long interval time.\n");
250 tacFree(&itac); tacFree(&otac); return(2);
251 }
252 if(interval>0.01*itac.x[itac.sampleNr-1]) {
253 if(verbose>0) fprintf(stderr, "Warning: interval time may be too long.\n");
254 }
255 }
256
257 /*
258 * Interpolate data with even sample intervals for convolution
259 */
260 TAC iitac; tacInit(&iitac);
261 if(tacInterpolateToEqualLengthFrames(&itac, interval, interval, &iitac, &status)!=TPCERROR_OK) {
262 fprintf(stderr, "Error: cannot interpolate data to even sample times.\n");
263 tacFree(&itac); tacFree(&otac); return(3);
264 }
265 /* Get the sample interval in interpolated data */
266 double freq=iitac.x2[0]-iitac.x1[0];
267 if(verbose>1) {
268 printf("sample_intervals_in_convolution := %g\n", freq);
269 printf("interpolated data range: %g - %g\n", iitac.x1[0], iitac.x2[itac.sampleNr-1]);
270 }
271
272
273 if(verbose>1) fprintf(stdout, "allocate memory for kernel...\n");
274 double *kernel=(double*)malloc(2*iitac.sampleNr*sizeof(double));
275 if(kernel==NULL) {
276 fprintf(stderr, "Error: out of memory.\n");
277 tacFree(&itac); tacFree(&otac); tacFree(&iitac); return(4);
278 }
279 double *cy=kernel+iitac.sampleNr;
280
281
282
283
284
285 /*
286 * Fitting
287 */
288 if(verbose>1) printf("preparing for fitting\n");
289
290 /* Set data pointers for the fit */
291 FITDATA fitdata;
292 fitdata.verbose=0;
293 fitdata.kernel=kernel;
294 fitdata.in=iitac.sampleNr;
295 fitdata.ix=iitac.x;
296 fitdata.iy=iitac.c[0].y;
297 fitdata.cy=cy;
298
299 fitdata.n=otac.sampleNr;
300 fitdata.x=otac.x;
301 fitdata.y=otac.c[0].y;
302 fitdata.ysim=otac.c[1].y;
303 fitdata.w=otac.w;
304
305
306
307 /* Set parameters for nonlinear optimization */
308 /* Because AUC is constrained, we will fit parameters a1, fAUC, a2, and AUC,
309 and calculate a1/b1=fAUC*AUC, b1=a1/(fAUC*AUC), and b2=a2/((1-fAUC)*AUC) */
310 if(verbose>2) printf("process initial parameter values\n");
311 NLOPT nlo; nloptInit(&nlo);
312 ret=nloptAllocate(&nlo, 4);
313 if(ret!=TPCERROR_OK) {
314 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
315 tacFree(&itac); tacFree(&otac); tacFree(&iitac); return(5);
316 }
317 /* Set function */
318 nlo._fun=func_xexp;
319 nlo.fundata=&fitdata;
320 nlo.totalNr=4;
321 {
322 nlo.xlower[0]=1.0E-08; nlo.xupper[0]=amax/freq; nlo.xfull[0]=nlo.xlower[0]+0.02*(nlo.xupper[0]-nlo.xlower[0]);
323 nlo.xlower[1]=1.0E-10; nlo.xupper[1]=0.999; nlo.xfull[1]=0.2;
324 nlo.xlower[2]=1.0E-08; nlo.xupper[2]=amax/freq; nlo.xfull[2]=nlo.xlower[2]+0.08*(nlo.xupper[2]-nlo.xlower[2]);
325/*
326 nlo.xlower[0]=1.0E-08; nlo.xupper[0]=1.0E+00; nlo.xfull[0]=0.6;
327 nlo.xlower[1]=1.0E-10; nlo.xupper[1]=0.999; nlo.xfull[1]=0.2;
328 nlo.xlower[2]=1.0E-08; nlo.xupper[2]=1.0E+00; nlo.xfull[2]=0.4;
329*/
330 nlo.xlower[3]=amin; nlo.xupper[3]=amax; nlo.xfull[3]=amin+0.8*(amax-amin);
331 for(unsigned int i=0; i<nlo.totalNr; i++) {
332 nlo.xdelta[i]=0.1*(nlo.xfull[i]-nlo.xlower[i]);
333 nlo.xtol[i]=fabs(0.001*nlo.xdelta[i]);
334 }
335 }
336 nlo.maxFunCalls=10000;
337
338 /* Get nr of fixed parameters */
339 unsigned int fixedNr=nloptFixedNr(&nlo);
340 if(verbose>2) printf("fixedNr := %d\n", fixedNr);
341
342#if(0)
343 // call function for testing
344 fitdata.verbose=10;
345 func_xexp(nlo.totalNr, nlo.xfull, &fitdata); exit(1);
346#endif
347
348 /* Fit */
349 drandSeed(1);
350 if(verbose>2) nloptWrite(&nlo, stdout);
351 if(verbose>0) printf("fitting\n");
352 if(nloptSimplexARRS(&nlo, 0, &status)!=TPCERROR_OK) {
353 //if(nloptITGO2(&nlo, 1, 0, 0, 0, &status)!=TPCERROR_OK) {
354 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
355 tacFree(&itac); tacFree(&otac); tacFree(&iitac); nloptFree(&nlo); return(6);
356 }
357 nlo._fun(nlo.totalNr, nlo.xfull, nlo.fundata);
358 if(verbose>2) nloptWrite(&nlo, stdout);
359 if(verbose>1) {
360 printf("measured and fitted TAC:\n");
361 for(int i=0; i<otac.sampleNr; i++)
362 printf("\t%g\t%g\t%g\n", otac.x[i], otac.c[0].y[i], otac.c[1].y[i]);
363 }
364 if(verbose>2) printf(" wss := %g\n", nlo.funval);
365
366
367 /*
368 * Copy function parameters into PAR structure for printing and saving
369 */
370 PAR par; parInit(&par);
371 ret=parAllocateWithTAC(&par, &otac, nlo.totalNr, &status);
372 if(ret!=TPCERROR_OK) {
373 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
374 tacFree(&itac); tacFree(&otac); tacFree(&iitac); nloptFree(&nlo); return(7);
375 }
376 /* set time and program name */
377 {
378 char buf[256];
379 time_t t=time(NULL);
380 iftPut(&par.h, "analysis_time", ctime_r_int(&t, buf), 0, NULL);
381 tpcProgramName(argv[0], 1, 1, buf, 256);
382 iftPut(&par.h, "program", buf, 0, NULL);
383 }
384 par.tacNr=1; par.parNr=nlo.totalNr;
386 par.r[0].model=modelCodeIndex("2exp");
387 par.r[0].dataNr=tacWSampleNr(&otac);
388 par.r[0].start=otac.x[0];
389 par.r[0].end=otac.x[otac.sampleNr-1];
390 par.r[0].wss=nlo.funval;
391 par.r[0].fitNr=nlo.totalNr-fixedNr;
392 /* Set parameter names and units */
393 for(int i=0; i<par.parNr; i+=2) {
394 sprintf(par.n[i].name, "a%d", 1+i/2);
395 sprintf(par.n[i+1].name, "b%d", 1+i/2);
396 par.n[i].unit=UNIT_UNITLESS;
397 par.n[i+1].unit=unitInverse(otac.tunit);
398 }
399 /* Set parameters */
400 par.r[0].p[0]=nlo.xfull[0];
401 par.r[0].p[1]=nlo.xfull[0]/(nlo.xfull[1]*nlo.xfull[3]);
402 par.r[0].p[2]=nlo.xfull[2];
403 par.r[0].p[3]=nlo.xfull[2]/((1.0-nlo.xfull[1])*nlo.xfull[3]);
404 // Switch order if necessary to set faster exp first
405 if(par.r[0].p[3]>par.r[0].p[1]) {
406 double v;
407 v=par.r[0].p[0]; par.r[0].p[0]=par.r[0].p[2]; par.r[0].p[2]=v;
408 v=par.r[0].p[1]; par.r[0].p[1]=par.r[0].p[3]; par.r[0].p[3]=v;
409 }
410 /* Set TAC name if missing */
411 if(strlen(par.r[0].name)<1) strcpy(par.r[0].name, "1");
412 /* set file names */
413 iftPut(&par.h, "inputfile", inpfile, 0, NULL);
414 iftPut(&par.h, "datafile", outfile, 0, NULL);
415
416 /* Print and save */
417 if(verbose>0) parWrite(&par, stdout, PAR_FORMAT_TSV_UK, 1, NULL);
418 if(parfile[0]) {
419 /* Save file */
420 if(verbose>1) printf(" saving %s\n", parfile);
421 FILE *fp;
422 fp=fopen(parfile, "w");
423 if(fp==NULL) {
424 fprintf(stderr, "Error: cannot open file for writing.\n");
425 tacFree(&itac); tacFree(&otac); tacFree(&iitac); nloptFree(&nlo); parFree(&par); return(11);
426 }
427 ret=parWrite(&par, fp, PAR_FORMAT_TSV_UK, 1, &status);
428 fclose(fp);
429 if(ret!=TPCERROR_OK) {
430 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
431 tacFree(&itac); tacFree(&otac); tacFree(&iitac); nloptFree(&nlo); parFree(&par); return(12);
432 }
433 if(verbose>0) printf("parameters saved in %s\n", parfile);
434 }
435
436
437
438 /*
439 * Plot measured and fitted data, if requested
440 */
441 if(svgfile[0]) {
442 if(verbose>1) printf("plotting measured and fitted data\n");
443 for(unsigned int i=0; i<fitdata.in; i++) iitac.c[0].y[i]=fitdata.cy[i];
444 /* Plot */
445 ret=tacPlotFitSVG(&otac, &iitac, "", nan(""), nan(""), nan(""), nan(""), svgfile, &status);
446 if(ret!=TPCERROR_OK) {
447 fprintf(stderr, "Error: %s\n", errorMsg(status.error));
448 tacFree(&itac); tacFree(&otac); tacFree(&iitac); nloptFree(&nlo); parFree(&par);
449 return(24);
450 }
451
452 if(verbose>0) printf("Measured and fitted data plotted in %s\n", svgfile);
453 }
454
455
456
457 nloptFree(&nlo); parFree(&par);
458 tacFree(&itac); tacFree(&otac); tacFree(&iitac);
459
460 return(0);
461}
462/*****************************************************************************/
463
464/*****************************************************************************
465 *
466 * Functions to be minimized
467 *
468 *****************************************************************************/
469double func_xexp(int parNr, double *p, void *fdata)
470{
471 FITDATA *d=(FITDATA*)fdata;
472
473 if(d->verbose>0) {printf("%s()\n", __func__); fflush(stdout);}
474 if(d->verbose>2) printf("p[]: %g %g %g %g\n", p[0], p[1], p[2], p[3]);
475
476 /*
477 * Calculate the response function for convolution
478 */
479 if(d->verbose>1) {fprintf(stdout, "computing the kernel...\n"); fflush(stdout);}
480 double a1, b1, a2, b2;
481 a1=p[0]; a2=p[2];
482 b1=a1/(p[1]*p[3]); b2=a2/((1.0-p[1])*p[3]);
483 if(d->verbose>2) printf("a1=%g b1=%g a2=%g b2=%g\n", a1, b1, a2, b2);
484 double ksum=0.0;
485 double freq=d->ix[1]-d->ix[0];
486 if(d->verbose>6) printf("\nData\tKernel:\n");
487 for(unsigned int i=0; i<d->in; i++) {
488 d->kernel[i] = (a1/b1) * (exp(b1*freq) - 1.0) * exp(-b1*(d->ix[i]+0.5*freq)) +
489 (a2/b2) * (exp(b2*freq) - 1.0) * exp(-b2*(d->ix[i]+0.5*freq));
490 ksum+=d->kernel[i];
491 if(d->verbose>6) printf("%g\t%g\n", d->ix[i], d->kernel[i]);
492 }
493 if(d->verbose>2) printf("Sum of response function := %g\n", ksum);
494 if(!isnormal(ksum)) {
495 if(d->verbose>0) fprintf(stderr, "Error: invalid kernel contents.\n");
496 return(nan(""));
497 }
498
499 /*
500 * Convolution
501 */
502 if(d->verbose>1) {fprintf(stdout, "convolution...\n"); fflush(stdout);}
503 if(convolve1D(d->iy, d->in, d->kernel, d->in, d->cy)!=0) {
504 fprintf(stderr, "Error: cannot convolve the data.\n");
505 return(nan(""));
506 }
507 if(d->verbose>4) {
508 printf("\nData x\ty\tKernel\tConvolved\n");
509 for(unsigned int i=0; i<d->in; i++)
510 printf("%g\t%g\t%g\t%g\n", d->ix[i], d->iy[i], d->kernel[i], d->cy[i]);
511 }
512
513 /* Interpolate to output sample times */
514 if(d->verbose>2) {fprintf(stdout, "interpolation...\n"); fflush(stdout);}
515 if(liInterpolate(d->ix, d->cy, d->in, d->x, d->ysim, NULL, NULL, d->n, 0, 0, 0)!=0) {
516 fprintf(stderr, "Error: cannot interpolate.\n");
517 return(nan(""));
518 }
519 if(d->verbose>3) {
520 printf("\nData x\ty\tSimulated\n");
521 for(unsigned int i=0; i<d->n; i++)
522 printf("%g\t%g\t%g\n", d->x[i], d->y[i], d->ysim[i]);
523 }
524
525 /* Calculate the weighted SS */
526 if(d->verbose>2) {fprintf(stdout, "computing WSS...\n"); fflush(stdout);}
527 double wss=0.0;
528 for(unsigned i=0; i<d->n; i++) {
529 double v=d->ysim[i] - d->y[i];
530 wss+=d->w[i]*v*v;
531 }
532 if(d->verbose>1) {
533 for(int i=0; i<parNr; i++) printf(" %g", p[i]);
534 printf(" -> %g\n", wss);
535 }
536
537 return(wss);
538}
539/*****************************************************************************/
540
541/*****************************************************************************/
int convolve1D(double *data, const int n, double *kernel, const int m, double *out)
Calculates the convolution sum of a discrete real data set data[0..n-1] and a discretized response fu...
Definition convolut.c:27
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
double atofVerified(const char *s)
Definition decpoint.c:75
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
int liInterpolate(double *x, double *y, const int nr, double *newx, double *newy, double *newyi, double *newyii, const int newnr, const int se, const int ee, const int verbose)
Linear interpolation and/or integration with trapezoidal method.
int tacInterpolateToEqualLengthFrames(TAC *inp, double minfdur, double maxfdur, TAC *tac, TPCSTATUS *status)
Definition lisim.c:214
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
unsigned int nloptFixedNr(NLOPT *d)
Definition nlopt.c:354
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
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 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 * xdelta
Definition tpcnlopt.h:36
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
int unit
Definition tpcpar.h:86
char name[MAX_PARNAME_LEN+1]
Definition tpcpar.h:82
double wss
Definition tpcpar.h:72
int fitNr
Definition tpcpar.h:58
char name[MAX_TACNAME_LEN+1]
Definition tpcpar.h:50
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
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
TACC * c
Definition tpctac.h:117
weights weighting
Definition tpctac.h:115
double * x2
Definition tpctac.h:101
unit tunit
Definition tpctac.h:109
double * x1
Definition tpctac.h:99
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
void tacInit(TAC *tac)
Definition tac.c:24
int tacAllocateMore(TAC *tac, int tacNr)
Definition tac.c:178
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
char * tacFormattxt(tacformat c)
Definition tacio.c:98
int tacReadModelingData(const char *tissuefile, const char *inputfile1, const char *inputfile2, const char *inputfile3, double *fitdur, int cutInput, int *fitSampleNr, TAC *tis, TAC *inp, TPCSTATUS *status)
Read tissue and input data for modelling.
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
Header file for libtpccm.
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).
@ UNIT_UNITLESS
Unitless.
int unitInverse(int u)
Definition units.c:654
@ TPCERROR_OK
No error.
char * unitName(int unit_code)
Definition units.c:143
Header file for library libtpcift.
@ ISOTOPE_UNKNOWN
Unknown.
Definition tpcisotope.h:51
Header file for libtpcli.
Header file for libtpclinopt.
Header file for library libtpcnlopt.
Header file for libtpcpar.
@ PAR_FORMAT_TSV_UK
UK TSV (point as decimal separator).
Definition tpcpar.h:35
Header file for libtpcrand.
Header file for library libtpctac.
Header file for libtpctacmod.