TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctacmod
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
/*****************************************************************************/
26
int
mfCreateTAC
(
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
/*****************************************************************************/
mfEvalY
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
iftFindKey
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition
iftfind.c:30
mfCreateTAC
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
modelCode
char * modelCode(const unsigned int i)
Definition
modell.c:176
modelParNr
unsigned int modelParNr(const unsigned int code)
Definition
modell.c:256
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
IFT_ITEM::value
char * value
Definition
tpcift.h:37
IFT::item
IFT_ITEM * item
Definition
tpcift.h:57
PAR
Definition
tpcpar.h:100
PAR::h
IFT h
Optional (but often useful) header information.
Definition
tpcpar.h:147
PAR::tacNr
int tacNr
Definition
tpcpar.h:104
PAR::r
PARR * r
Definition
tpcpar.h:114
PARR::name
char name[MAX_TACNAME_LEN+1]
Definition
tpcpar.h:50
PARR::model
unsigned int model
Definition
tpcpar.h:48
PARR::p
double * p
Definition
tpcpar.h:64
TACC::name
char name[MAX_TACNAME_LEN+1]
Definition
tpctac.h:81
TACC::y
double * y
Definition
tpctac.h:75
TAC
Definition
tpctac.h:87
TAC::x
double * x
Definition
tpctac.h:97
TAC::cunit
unit cunit
Definition
tpctac.h:105
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::isframe
int isframe
Definition
tpctac.h:95
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::tacNr
int tacNr
Definition
tpctac.h:91
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
TPCSTATUS::error
tpcerror error
Error code.
Definition
tpcextensions.h:245
tacFree
void tacFree(TAC *tac)
Definition
tac.c:106
tacAllocate
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition
tac.c:130
tpcextensions.h
Header file for library libtpcextensions.
TPCERROR_FAIL
@ TPCERROR_FAIL
General error.
Definition
tpcextensions.h:192
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
TPCERROR_INCOMPATIBLE_DATA
@ TPCERROR_INCOMPATIBLE_DATA
Incompatible data.
Definition
tpcextensions.h:216
unitIdentify
int unitIdentify(const char *s)
Definition
units.c:162
tpcmodels.h
Header file for libtpcmodels.
tpctac.h
Header file for library libtpctac.
tpctacmod.h
Header file for libtpctacmod.
Generated on
for TPCCLIB by
1.17.0