TPCCLIB
Loading...
Searching...
No Matches
mftac.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <time.h>
11#include <string.h>
12/*****************************************************************************/
13#include "tpcextensions.h"
14#include "tpcmodels.h"
15#include "tpctac.h"
16/*****************************************************************************/
17#include "tpctacmod.h"
18/*****************************************************************************/
19
20/*****************************************************************************/
28 PAR *par,
30 double endx,
32 double dx,
34 TAC *tac,
36 TPCSTATUS *status
37) {
38 int verbose=0; if(status!=NULL) verbose=status->verbose;
39 if(verbose>2) {
40 printf("%s(par, %g, %g, tac, status)\n", __func__, endx, dx);
41 fflush(stdout);
42 }
43
44 /* Check provided data */
45 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_FAIL);
46 if(par==NULL || tac==NULL || !(endx>0.0) || !(dx>0.0)) return(status->error);
47 if(par->tacNr<1) {
48 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
49 return(status->error);
50 }
51
52 /* Make sure that TAC is empty */
53 tacFree(tac);
54
55 /* Allocate memory for TAC(s) */
56 int xNr=1+endx/dx;
57 int ret=tacAllocate(tac, xNr, par->tacNr);
58 if(ret!=TPCERROR_OK) {
59 statusSet(status, __func__, __FILE__, __LINE__, ret);
60 return(status->error);
61 }
62 tac->sampleNr=xNr;
63 tac->tacNr=par->tacNr;
64
65 /* Fill x (times) */
66 tac->isframe=0;
67 for(int i=0; i<xNr; i++) tac->x[i]=(double)i*dx;
68
69 /* Calculate curves */
70 for(int ci=0; ci<par->tacNr; ci++) {
71 strcpy(tac->c[ci].name, par->r[ci].name);
72 if(verbose>6)
73 printf("'%s' model=%u code=%s\n", par->r[ci].name, par->r[ci].model, modelCode(par->r[ci].model));
74 if(mfEvalY(modelCode(par->r[ci].model), modelParNr(par->r[ci].model), par->r[ci].p,
75 tac->sampleNr, tac->x, tac->c[ci].y, verbose-3))
76 {
77 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_INCOMPATIBLE_DATA);
78 tacFree(tac); return(status->error);
79 }
80 }
81
82 /* Try to find units */
83 int i;
84 i=iftFindKey(&par->h, "unit", 0); if(i<0) i=iftFindKey(&par->h, "calibration_unit", 0);
85 if(i>=0) tac->cunit=unitIdentify(par->h.item[i].value);
86 i=iftFindKey(&par->h, "timeunit", 0); if(i<0) i=iftFindKey(&par->h, "time_unit", 0);
87 if(i>=0) tac->tunit=unitIdentify(par->h.item[i].value);
88
89 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
90 return(TPCERROR_OK);
91}
92/*****************************************************************************/
93
94/*****************************************************************************/
int mfEvalY(const char *fid, const int parNr, double *p, const int sampleNr, double *x, double *y, const int verbose)
Definition func.c:26
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30
int mfCreateTAC(PAR *par, double endx, double dx, TAC *tac, TPCSTATUS *status)
Make TAC(s) based on mathematical functions in PAR format.
Definition mftac.c:26
char * modelCode(const unsigned int i)
Definition modell.c:175
unsigned int modelParNr(const unsigned int code)
Definition modell.c:255
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
char * value
Definition tpcift.h:37
IFT_ITEM * item
Definition tpcift.h:57
Definition tpcpar.h:101
IFT h
Optional (but often useful) header information.
Definition tpcpar.h:148
int tacNr
Definition tpcpar.h:105
PARR * r
Definition tpcpar.h:115
char name[MAX_TACNAME_LEN+1]
Definition tpcpar.h:50
unsigned int model
Definition tpcpar.h:48
double * p
Definition tpcpar.h:65
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
int sampleNr
Definition tpctac.h:89
int isframe
Definition tpctac.h:95
TACC * c
Definition tpctac.h:117
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
Header file for library libtpcextensions.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
@ TPCERROR_INCOMPATIBLE_DATA
Incompatible data.
int unitIdentify(const char *s)
Definition units.c:162
Header file for libtpcmodels.
Header file for library libtpctac.
Header file for libtpctacmod.