TPCCLIB
Loading...
Searching...
No Matches
mftac.c File Reference

Make mathematical function based TAC. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcextensions.h"
#include "tpcmodels.h"
#include "tpctac.h"
#include "tpctacmod.h"

Go to the source code of this file.

Functions

int mfCreateTAC (PAR *par, double endx, double dx, TAC *tac, TPCSTATUS *status)
 Make TAC(s) based on mathematical functions in PAR format.

Detailed Description

Make mathematical function based TAC.

Definition in file mftac.c.

Function Documentation

◆ mfCreateTAC()

int mfCreateTAC ( PAR * par,
double endx,
double dx,
TAC * tac,
TPCSTATUS * status )

Make TAC(s) based on mathematical functions in PAR format.

See also
mfEvalY, parExampleTTACs
Returns
enum tpcerror (TPCERROR_OK when successful).
Author
Vesa Oikonen
Parameters
parPointer to PAR structure containing functions for TACs.
endxEnd time (x) of created TAC data. TAC will always start at zero.
dxStep size (delta x).
tacPointer to initiated TAC structure. Any previous contents are deleted.
statusPointer to status data; enter NULL if not needed.

Definition at line 26 of file mftac.c.

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}
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
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30
char * modelCode(const unsigned int i)
Definition modell.c:176
unsigned int modelParNr(const unsigned int code)
Definition modell.c:256
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
IFT h
Optional (but often useful) header information.
Definition tpcpar.h:147
int tacNr
Definition tpcpar.h:104
PARR * r
Definition tpcpar.h:114
char name[MAX_TACNAME_LEN+1]
Definition tpcpar.h:50
unsigned int model
Definition tpcpar.h:48
double * p
Definition tpcpar.h:64
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81
double * y
Definition tpctac.h:75
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
@ 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