TPCCLIB
Loading...
Searching...
No Matches
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/*****************************************************************************/
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/*****************************************************************************/
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/*****************************************************************************/
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/*****************************************************************************/
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/*****************************************************************************/
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/*****************************************************************************/
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
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
int sampleNr
Definition tpctac.h:89
double * w
Definition tpctac.h:111
int cunit
Definition tpctac.h:105
int isframe
Definition tpctac.h:95
TACC * c
Definition tpctac.h:117
weights weighting
Definition tpctac.h:115
int tunit
Definition tpctac.h:109
double * x2
Definition tpctac.h:101
double * x1
Definition tpctac.h:99
int tacNr
Definition tpctac.h:91
int verbose
Verbose level, used by statusPrint() etc.
int tacCompareWeights(TAC *d1, TAC *d2, const double test_abs, const double test_rel, TPCSTATUS *status)
Definition taccomp.c:289
int tacCompareNames(TAC *d1, TAC *d2, const int i, TPCSTATUS *status)
Definition taccomp.c:67
int tacCompareTimes(TAC *d1, TAC *d2, const double test_abs, const double test_rel, TPCSTATUS *status)
Definition taccomp.c:201
int tacCompareConc(TAC *d1, TAC *d2, const int i, const double test_abs, const double test_rel, TPCSTATUS *status)
Definition taccomp.c:122
int tacCompareUnit(TAC *d1, TAC *d2, TPCSTATUS *status)
Definition taccomp.c:27
@ 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.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
char * unitName(int unit_code)
Definition units.c:143
Header file for library libtpcift.
Header file for library libtpctac.