TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctac
taccomp.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include "
tpcift.h
"
8
/*****************************************************************************/
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <math.h>
12
#include <time.h>
13
#include <ctype.h>
14
#include <string.h>
15
#include <strings.h>
16
/*****************************************************************************/
17
#include "
tpctac.h
"
18
/*****************************************************************************/
19
20
/*****************************************************************************/
27
int
tacCompareUnit
(
29
TAC
*d1,
31
TAC
*d2,
33
TPCSTATUS
*status
34
) {
35
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
36
if
(verbose>1) printf(
"%s()\n"
, __func__);
37
38
/* Check that required data exists */
39
if
(d1==NULL || d2==NULL) {
40
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
41
return
3;
42
}
43
44
int
ret=0;
45
if
(d1->
cunit
!=d2->
cunit
) ret+=1;
46
if
(d1->
tunit
!=d2->
tunit
) ret+=2;
47
if
(ret>0 && verbose>0) {
48
printf(
"tac1.cunit := %s\n"
,
unitName
(d1->
cunit
));
49
printf(
"tac2.cunit := %s\n"
,
unitName
(d2->
cunit
));
50
printf(
"tac1.tunit := %s\n"
,
unitName
(d1->
tunit
));
51
printf(
"tac2.tunit := %s\n"
,
unitName
(d2->
tunit
));
52
}
53
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
54
return
(ret);
55
}
56
/*****************************************************************************/
57
58
/*****************************************************************************/
67
int
tacCompareNames
(
69
TAC
*d1,
71
TAC
*d2,
73
const
int
i,
75
TPCSTATUS
*status
76
) {
77
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
78
if
(verbose>1) printf(
"%s()\n"
, __func__);
79
80
/* Check that required data exists */
81
if
(d1==NULL || d2==NULL || d1->
tacNr
<1 || d2->
tacNr
<1) {
82
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
83
return
1;
84
}
85
/* If index is specified, then verify that that TAC is available */
86
if
(i>=0 && (i>=d1->
tacNr
|| i>=d2->
tacNr
)) {
87
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_FAIL
);
88
return
1;
89
}
90
91
/* If index is not specified, then tacNr must match */
92
if
(i<0 && (d1->
tacNr
!=d2->
tacNr
)) {
93
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
94
if
(verbose>0) printf(
"different TAC nr.\n"
);
95
return
(1);
96
}
97
98
/* Compare */
99
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
100
for
(
int
ri=0; ri<d1->
tacNr
; ri++)
if
(i<0 || i==ri) {
101
if
(strcmp(d1->
c
[ri].
name
, d2->
c
[ri].
name
)!=0) {
102
if
(verbose>0) {
103
printf(
"tac1.c[%d].name := '%s'\n"
, ri, d1->
c
[ri].
name
);
104
printf(
"tac2.c[%d].name := '%s'\n"
, ri, d2->
c
[ri].
name
);
105
}
106
return
(1);
107
}
108
}
109
return
(0);
110
}
111
/*****************************************************************************/
112
113
/*****************************************************************************/
122
int
tacCompareConc
(
124
TAC
*d1,
126
TAC
*d2,
128
const
int
i,
130
const
double
test_abs,
134
const
double
test_rel,
136
TPCSTATUS
*status
137
) {
138
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
139
if
(verbose>1) printf(
"%s()\n"
, __func__);
140
141
/* Check that required data exists */
142
if
(d1==NULL || d2==NULL || d1->
tacNr
<1 || d2->
tacNr
<1
143
|| d1->
sampleNr
<1 || d2->
sampleNr
<1) {
144
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
145
return
1;
146
}
147
/* If index is specified, then verify that that TAC is available */
148
if
(i>=0 && (i>=d1->
tacNr
|| i>=d2->
tacNr
)) {
149
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_FAIL
);
150
return
1;
151
}
152
153
/* If index is not specified, then tacNr must match */
154
if
(i<0 && (d1->
tacNr
!=d2->
tacNr
)) {
155
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
156
if
(verbose>0) printf(
"different TAC nr.\n"
);
157
return
(2);
158
}
159
160
/* Sample nr must match */
161
if
(d1->
sampleNr
!=d2->
sampleNr
) {
162
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
163
if
(verbose>0) printf(
"different sample nr.\n"
);
164
return
(3);
165
}
166
167
/* Compare */
168
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
169
for
(
int
ri=0; ri<d1->
tacNr
; ri++)
if
(i<0 || i==ri) {
170
for
(
int
fi=0; fi<d1->
sampleNr
; fi++) {
171
if
(
doubleMatch
(d1->
c
[ri].
y
[fi], d2->
c
[ri].
y
[fi], test_abs)==1)
172
continue
;
173
if
(test_rel>0.0 &&
174
doubleMatchRel
(d1->
c
[ri].
y
[fi], d2->
c
[ri].
y
[fi], test_rel)==1)
175
continue
;
176
if
(verbose>0) {
177
double
s;
178
s=fabs(d1->
c
[ri].
y
[fi]-d2->
c
[ri].
y
[fi]);
179
printf(
"tac1.c[%d].y[%d] := %g\n"
, ri, fi, d1->
c
[ri].
y
[fi]);
180
printf(
"tac2.c[%d].y[%d] := %g\n"
, ri, fi, d2->
c
[ri].
y
[fi]);
181
printf(
"|diff| := %g\n"
, s);
182
printf(
"diff_limit := %g\n"
, test_abs);
183
if
(test_rel>0.0) printf(
"rel_diff_limit := %g\n"
, test_rel);
184
}
185
return
(10);
186
}
187
}
188
return
(0);
189
}
190
/*****************************************************************************/
191
192
/*****************************************************************************/
201
int
tacCompareTimes
(
203
TAC
*d1,
205
TAC
*d2,
207
const
double
test_abs,
211
const
double
test_rel,
213
TPCSTATUS
*status
214
) {
215
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
216
if
(verbose>1) printf(
"%s()\n"
, __func__);
217
218
/* Check that required data exists */
219
if
(d1==NULL || d2==NULL || d1->
sampleNr
<1 || d2->
sampleNr
<1) {
220
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
221
return
1;
222
}
223
224
/* X type must match */
225
if
(d1->
isframe
!=d2->
isframe
) {
226
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
227
if
(verbose>0) printf(
"different sampling type.\n"
);
228
return
(2);
229
}
230
231
/* Sample nr must match */
232
if
(d1->
sampleNr
!=d2->
sampleNr
) {
233
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
234
if
(verbose>0) printf(
"different sample nr.\n"
);
235
return
(3);
236
}
237
238
/* Compare */
239
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
240
for
(
int
fi=0; fi<d1->
sampleNr
; fi++) {
241
if
(d1->
isframe
==0) {
242
if
(
doubleMatch
(d1->
x
[fi], d2->
x
[fi], test_abs)==1)
243
continue
;
244
if
(test_rel>0.0 &&
doubleMatchRel
(d1->
x
[fi], d2->
x
[fi], test_rel)==1)
245
continue
;
246
if
(verbose>0) {
247
double
s;
248
s=fabs(d1->
x
[fi]-d2->
x
[fi]);
249
printf(
"tac1.x[%d] := %g\n"
, fi, d1->
x
[fi]);
250
printf(
"tac2.x[%d] := %g\n"
, fi, d2->
x
[fi]);
251
printf(
"|diff| := %g\n"
, s);
252
printf(
"diff_limit := %g\n"
, test_abs);
253
if
(test_rel>0.0) printf(
"rel_diff_limit := %g\n"
, test_rel);
254
}
255
return
(10);
256
}
else
{
257
if
(
doubleMatch
(d1->
x1
[fi], d2->
x1
[fi], test_abs)==1 &&
258
doubleMatch
(d1->
x2
[fi], d2->
x2
[fi], test_abs)==1)
259
continue
;
260
if
(test_rel>0.0 &&
261
doubleMatchRel
(d1->
x1
[fi], d2->
x1
[fi], test_rel)==1 &&
262
doubleMatchRel
(d1->
x2
[fi], d2->
x2
[fi], test_rel)==1)
263
continue
;
264
if
(verbose>0) {
265
printf(
"tac1.x1[%d] := %g\n"
, fi, d1->
x1
[fi]);
266
printf(
"tac2.x1[%d] := %g\n"
, fi, d2->
x1
[fi]);
267
printf(
"|diff| := %g\n"
, fabs(d1->
x1
[fi]-d2->
x1
[fi]));
268
printf(
"tac1.x2[%d] := %g\n"
, fi, d1->
x2
[fi]);
269
printf(
"tac2.x2[%d] := %g\n"
, fi, d2->
x2
[fi]);
270
printf(
"|diff| := %g\n"
, fabs(d1->
x2
[fi]-d2->
x2
[fi]));
271
printf(
"diff_limit := %g\n"
, test_abs);
272
if
(test_rel>0.0) printf(
"rel_diff_limit := %g\n"
, test_rel);
273
}
274
return
(11);
275
}
276
}
277
return
(0);
278
}
279
/*****************************************************************************/
280
281
/*****************************************************************************/
289
int
tacCompareWeights
(
291
TAC
*d1,
293
TAC
*d2,
295
const
double
test_abs,
299
const
double
test_rel,
301
TPCSTATUS
*status
302
) {
303
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
304
if
(verbose>1) printf(
"%s()\n"
, __func__);
305
306
/* Check that required data exists */
307
if
(d1==NULL || d2==NULL || d1->
sampleNr
<1 || d2->
sampleNr
<1) {
308
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
309
return
1;
310
}
311
312
/* Weight setting must match */
313
if
(d1->
weighting
!=d2->
weighting
) {
314
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
315
if
(verbose>0) printf(
"different weighting setting.\n"
);
316
return
(2);
317
}
318
319
/* If no weights, then no checking either */
320
if
(d1->
weighting
==
WEIGHTING_OFF
&& d2->
weighting
==
WEIGHTING_OFF
)
return
(0);
321
if
(d1->
weighting
==
WEIGHTING_UNKNOWN
&& d2->
weighting
==
WEIGHTING_UNKNOWN
)
return
(0);
322
323
/* Sample nr must match */
324
if
(d1->
sampleNr
!=d2->
sampleNr
) {
325
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
326
if
(verbose>0) printf(
"different sample nr.\n"
);
327
return
(3);
328
}
329
330
/* Compare */
331
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
332
for
(
int
fi=0; fi<d1->
sampleNr
; fi++) {
333
if
(
doubleMatch
(d1->
w
[fi], d2->
w
[fi], test_abs)==1)
continue
;
334
if
(test_rel>0.0 &&
doubleMatchRel
(d1->
w
[fi], d2->
w
[fi], test_rel)==1)
continue
;
335
if
(verbose>0) {
336
double
s;
337
s=fabs(d1->
w
[fi]-d2->
w
[fi]);
338
printf(
"tac1.w[%d] := %g\n"
, fi, d1->
w
[fi]);
339
printf(
"tac2.w[%d] := %g\n"
, fi, d2->
w
[fi]);
340
printf(
"|diff| := %g\n"
, s);
341
printf(
"diff_limit := %g\n"
, test_abs);
342
if
(test_rel>0.0) printf(
"rel_diff_limit := %g\n"
, test_rel);
343
}
344
return
(10);
345
}
346
return
(0);
347
}
348
/*****************************************************************************/
349
350
/*****************************************************************************/
doubleMatch
int doubleMatch(const double v1, const double v2, const double lim)
Definition
doubleutil.c:27
doubleMatchRel
int doubleMatchRel(const double v1, const double v2, const double lim)
Definition
doubleutil.c:77
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
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::w
double * w
Definition
tpctac.h:111
TAC::isframe
int isframe
Definition
tpctac.h:95
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::weighting
weights weighting
Definition
tpctac.h:115
TAC::x2
double * x2
Definition
tpctac.h:101
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::x1
double * x1
Definition
tpctac.h:99
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
tacCompareWeights
int tacCompareWeights(TAC *d1, TAC *d2, const double test_abs, const double test_rel, TPCSTATUS *status)
Definition
taccomp.c:289
tacCompareNames
int tacCompareNames(TAC *d1, TAC *d2, const int i, TPCSTATUS *status)
Definition
taccomp.c:67
tacCompareTimes
int tacCompareTimes(TAC *d1, TAC *d2, const double test_abs, const double test_rel, TPCSTATUS *status)
Definition
taccomp.c:201
tacCompareConc
int tacCompareConc(TAC *d1, TAC *d2, const int i, const double test_abs, const double test_rel, TPCSTATUS *status)
Definition
taccomp.c:122
tacCompareUnit
int tacCompareUnit(TAC *d1, TAC *d2, TPCSTATUS *status)
Definition
taccomp.c:27
WEIGHTING_OFF
@ WEIGHTING_OFF
Not weighted or weights not available (weights for all included samples are 1.0).
Definition
tpcextensions.h:54
WEIGHTING_UNKNOWN
@ WEIGHTING_UNKNOWN
Not known; usually assumed that not weighted.
Definition
tpcextensions.h:53
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
unitName
char * unitName(int unit_code)
Definition
units.c:143
tpcift.h
Header file for library libtpcift.
tpctac.h
Header file for library libtpctac.
Generated on
for TPCCLIB by
1.17.0