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

Comparison of TAC struct data. More...

#include "tpcclibConfig.h"
#include "tpcift.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "tpctac.h"

Go to the source code of this file.

Functions

int tacCompareUnit (TAC *d1, TAC *d2, TPCSTATUS *status)
int tacCompareNames (TAC *d1, TAC *d2, const int i, TPCSTATUS *status)
int tacCompareConc (TAC *d1, TAC *d2, const int i, const double test_abs, const double test_rel, TPCSTATUS *status)
int tacCompareTimes (TAC *d1, TAC *d2, const double test_abs, const double test_rel, TPCSTATUS *status)
int tacCompareWeights (TAC *d1, TAC *d2, const double test_abs, const double test_rel, TPCSTATUS *status)

Detailed Description

Comparison of TAC struct data.

Definition in file taccomp.c.

Function Documentation

◆ tacCompareConc()

int tacCompareConc ( TAC * d1,
TAC * d2,
const int i,
const double test_abs,
const double test_rel,
TPCSTATUS * status )

Check whether TAC concentrations (y values) are the same in two TAC data. Note that units are ignored here.

If either absolute or relative difference is below the limit, the test is reported as passed.

See also
tacCompareUnit, tacCompareTimes.
Returns
0 in case of match, and >0 if no match or error.
Author
Vesa Oikonen
Parameters
d1Pointer to TAC structure.
d2Pointer to TAC structure.
iTAC index [0..tacNr-1] to compare; enter <0 to verify all TACs.
test_absLimit for accepted absolute difference; obligatory.
test_relOptional limit for accepted relative difference |2*(x1-x2)/(x1+x2)| ; set to negative value to not test this; in case of zero mean, this test is assumed to fail, but test for absolute difference may still pass.
statusPointer to status data; enter NULL if not needed.

Definition at line 122 of file taccomp.c.

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}
int doubleMatch(const double v1, const double v2, const double lim)
Definition doubleutil.c:27
int doubleMatchRel(const double v1, const double v2, const double lim)
Definition doubleutil.c:77
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
double * y
Definition tpctac.h:75
int sampleNr
Definition tpctac.h:89
TACC * c
Definition tpctac.h:117
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.

◆ tacCompareNames()

int tacCompareNames ( TAC * d1,
TAC * d2,
const int i,
TPCSTATUS * status )

Check whether TAC names are the same in two TAC data.

Comparison is very strict and even case-sensitive, thus TAC names may need to be preprocessed if this is used for other purpose than SW testing.

Returns
0 in case of match, 1 if no match or error.
Author
Vesa Oikonen
See also
tacSortByName, tacCompareUnit
Parameters
d1Pointer to TAC structure.
d2Pointer to TAC structure.
iTAC index [0..tacNr-1] to compare; enter <0 to verify all TACs.
statusPointer to status data; enter NULL if not needed.

Definition at line 67 of file taccomp.c.

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}
char name[MAX_TACNAME_LEN+1]
Definition tpctac.h:81

◆ tacCompareTimes()

int tacCompareTimes ( TAC * d1,
TAC * d2,
const double test_abs,
const double test_rel,
TPCSTATUS * status )

Check whether TAC sample times (x values) are the same in two TAC data. Note that units are ignored here.

If either absolute or relative difference is below the limit, the test is reported as passed.

See also
tacCompareUnit, tacCompareConc, tacSortByTime, tacVerifyTimeOrder.
Returns
0 in case of match, and >0 if no match or error.
Author
Vesa Oikonen
Parameters
d1Pointer to TAC structure.
d2Pointer to TAC structure.
test_absLimit for accepted absolute difference.
test_relOptional limit for accepted relative difference |2*(x1-x2)/(x1+x2)| ; set to negative value to not test this; in case of zero mean, this test is assumed to fail, but test for absolute difference may still pass.
statusPointer to status data; enter NULL if not needed.

Definition at line 201 of file taccomp.c.

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}
double * x
Definition tpctac.h:97
int isframe
Definition tpctac.h:95
double * x2
Definition tpctac.h:101
double * x1
Definition tpctac.h:99

◆ tacCompareUnit()

int tacCompareUnit ( TAC * d1,
TAC * d2,
TPCSTATUS * status )

Check whether time and concentration units are the same in two TAC data.

Returns
0 in case of match, 1 if y (concentration) unit is not matching, 2 if x (time) unit is not matching, and 3 if neither is matching.
See also
tacCompareConc, tacCompareTimes
Author
Vesa Oikonen
Parameters
d1Pointer to TAC structure.
d2Pointer to TAC structure.
statusPointer to status data; enter NULL if not needed

Definition at line 27 of file taccomp.c.

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}
unit cunit
Definition tpctac.h:105
unit tunit
Definition tpctac.h:109
char * unitName(int unit_code)
Definition units.c:143

◆ tacCompareWeights()

int tacCompareWeights ( TAC * d1,
TAC * d2,
const double test_abs,
const double test_rel,
TPCSTATUS * status )

Check whether TAC weights are the same in two TAC data.

If either absolute or relative difference is below the limit, the test is reported as passed.

See also
tacCompareTimes, tacCompareConc, tacCompareNames.
Returns
0 in case of match, and >0 if no match or error.
Author
Vesa Oikonen
Parameters
d1Pointer to TAC structure.
d2Pointer to TAC structure.
test_absLimit for accepted absolute difference.
test_relOptional limit for accepted relative difference |2*(w1-w2)/(w1+w2)| ; set to negative value to not test this; in case of zero mean, this test is assumed to fail, but test for absolute difference may still pass.
statusPointer to status data; enter NULL if not needed.

Definition at line 289 of file taccomp.c.

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}
double * w
Definition tpctac.h:111
weights weighting
Definition tpctac.h:115
@ WEIGHTING_OFF
Not weighted or weights not available (weights for all included samples are 1.0).
@ WEIGHTING_UNKNOWN
Not known; usually assumed that not weighted.