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

Check if the information in two IFT files is the same. More...

Go to the source code of this file.

Functions

int iftCheckKeyValue (IFT *ift1, IFT *ift2, char *key, int test_lt, int test_gt, double test_abs, int verbose)
int iftCheckKeyValues (IFT *ift1, IFT *ift2, char *key1, char *key2, int test_lt, int test_gt, double test_abs, int verbose)

Detailed Description

Check if the information in two IFT files is the same.

Author
Vesa Oikonen

Definition in file iftmatch.c.

Function Documentation

◆ iftCheckKeyValue()

int iftCheckKeyValue ( IFT * ift1,
IFT * ift2,
char * key,
int test_lt,
int test_gt,
double test_abs,
int verbose )

Verify that specified key string is found in both IFT structs with the same values. If more than one instance of key is found, then all are tested.

Returns
Returns 0 if match is found and >0 in case of no match.
Parameters
ift1Pointer to filled IFT struct
ift2Pointer to filled IFT struct
keyPointer to case-insensitive key name
test_ltIf set to non-zero, value in ift1 must be smaller than corresponding value in ift2
test_gtIf set to non-zero, value in ift1 must be greater than corresponding value in ift2
test_absAllowed absolute difference in values; set to <=0 if no difference is allowed.
verboseVerbose level; if zero, nothing is printed into stdout or stderr

Definition at line 258 of file iftmatch.c.

276 {
277 if(verbose>2)
278 printf("iftCheckKeyValue(*ift1, *ift2, \"%s\", %d, %d, %g, ...)\n",
279 key, test_lt, test_gt, test_abs);
280 if(ift1==NULL || ift2==NULL) return(1);
281 if(key==NULL || strlen(key)<1) return(1);
282
283 /* Check first that key can be found in both files */
284 int n1, n2;
285 n1=iftFindNrOfKeys(ift1, key);
286 n2=iftFindNrOfKeys(ift2, key);
287 if(verbose>0) {
288 printf("%d instance(s) of key in file1.\n", n1);
289 printf("%d instance(s) of key in file2.\n", n2);
290 }
291 if(n1<1 || n2<1) {
292 if(verbose>0) fprintf(stderr, "No match: key not found.\n");
293 return(10);
294 }
295 /* Verify that the same key(s) and value(s) are found in both */
296 if(n1!=n2) {
297 if(verbose>0) fprintf(stderr, "No match: different nr of keys.\n");
298 return(10);
299 }
300 char *s1, *s2;
301 int i, li, lj;
302 double v1, v2;
303 s1=(char*)NULL; s2=(char*)NULL;
304 for(i=0, li=lj=-1; i<n1; i++) {
305 li=iftFindKey(ift1, key, li+1); if(verbose>5) printf("li=%d\n", li);
306 lj=iftFindKey(ift2, key, lj+1); if(verbose>5) printf("lj=%d\n", lj);
307 if(li<0 || lj<0) break;
308 /* Get pointers to value strings */
309 s1=(char*)ift1->item[li].value; s2=(char*)ift2->item[lj].value;
310 if(verbose>2) printf("testing strings '%s' == '%s'\n", s1, s2);
311 /* Check if both values are NULL or empty; considered as match */
312 if(s1==NULL && s2==NULL) continue;
313 if(strlen(s1)==0 && strlen(s2)==0) continue;
314 /* Check if values are the same as strings */
315 if(strcasecmp(s1, s2)==0) continue;
316 /* Try to convert them to doubles, ignoring unit */
317 if(doubleGetWithUnit(s1, &v1, NULL)!=0) break;
318 if(doubleGetWithUnit(s2, &v2, NULL)!=0) break;
319 /* Compare the doubles */
320 if(test_lt) {
321 if(verbose>2) printf("testing whether %g < %g\n", v1, v2);
322 if(v1<v2) continue;
323 } else if(test_gt) {
324 if(verbose>2) printf("testing whether %g > %g\n", v1, v2);
325 if(v1>v2) continue;
326 } else if(test_abs>=0) {
327 if(verbose>2) printf("testing whether |%g-%g| < %g\n", v1, v2, test_abs);
328 if(fabs(v1-v2)<test_abs) continue;
329 } else {
330 if(verbose>2) printf("testing whether %g == %g\n", v1, v2);
331 if(v1==v2) continue;
332 }
333 break;
334 }
335 if(i!=n1) {
336 if(verbose>0) fprintf(stderr, "No match: values are not the same.\n");
337 if(verbose>1) printf("value1 := '%s'\nvalue2 := '%s'\n", s1, s2);
338 return(10);
339 }
340 if(verbose>0) fprintf(stdout, "Match was found: values are the same.\n");
341 return(0);
342}
int doubleGetWithUnit(const char *s, double *v, int *u)
Definition doubleutil.c:272
int iftFindNrOfKeys(IFT *ift, const char *key)
Definition iftfind.c:142
int iftFindKey(IFT *ift, const char *key, int start_index)
Definition iftfind.c:30
char * value
Definition tpcift.h:37
IFT_ITEM * item
Definition tpcift.h:57

◆ iftCheckKeyValues()

int iftCheckKeyValues ( IFT * ift1,
IFT * ift2,
char * key1,
char * key2,
int test_lt,
int test_gt,
double test_abs,
int verbose )

Verify that items with specified key strings are found in both IFT structs, with the same item values. If more than one instance of key is found, then all of them are tested.

Returns
Returns 0 if match is found and >0 in case of no match.
Parameters
ift1Pointer to filled IFT struct
ift2Pointer to filled IFT struct
key1Pointer to case-insensitive key name for ift1
key2Pointer to case-insensitive key name for ift2
test_ltIf set to non-zero, value in ift1 must be smaller than corresponding value in ift2
test_gtIf set to non-zero, value in ift1 must be greater than corresponding value in ift2
test_absAllowed absolute difference in values; set to <=0 if no difference is allowed.
verboseVerbose level; if zero, nothing is printed into stdout or stderr

Definition at line 351 of file iftmatch.c.

371 {
372 if(verbose>2)
373 printf("iftCheckKeyValues(*ift1, *ift2, \"%s\", \"%s\", %d, %d, %g, ...)\n",
374 key1, key2, test_lt, test_gt, test_abs);
375 if(ift1==NULL || ift2==NULL) return(1);
376 if(key1==NULL || strlen(key1)<1) return(1);
377 if(key2==NULL) key2=key1;
378
379 /* Check first that keys can be found in both files */
380 int n1, n2;
381 n1=iftFindNrOfKeys(ift1, key1);
382 n2=iftFindNrOfKeys(ift2, key2);
383 if(verbose>0) {
384 printf("%d instance(s) of key in file1.\n", n1);
385 printf("%d instance(s) of key in file2.\n", n2);
386 }
387 if(n1<1 || n2<1) {
388 if(verbose>0) fprintf(stderr, "No match: key not found.\n");
389 return(10);
390 }
391 /* Verify that the same key(s) and value(s) are found in both */
392 if(n1!=n2) {
393 if(verbose>0) fprintf(stderr, "No match: different nr of keys.\n");
394 return(10);
395 }
396 char *s1, *s2;
397 int i, li, lj;
398 double v1, v2;
399 s1=(char*)NULL; s2=(char*)NULL;
400 for(i=0, li=lj=-1; i<n1; i++) {
401 li=iftFindKey(ift1, key1, li+1); if(verbose>5) printf("li=%d\n", li);
402 lj=iftFindKey(ift2, key2, lj+1); if(verbose>5) printf("lj=%d\n", lj);
403 if(li<0 || lj<0) break;
404 /* Get pointers to value strings */
405 s1=(char*)ift1->item[li].value; s2=(char*)ift2->item[lj].value;
406 if(verbose>2) printf("testing strings '%s' == '%s'\n", s1, s2);
407 /* Check if both values are NULL or empty; considered as match */
408 if(s1==NULL && s2==NULL) continue;
409 if(strlen(s1)==0 && strlen(s2)==0) continue;
410 /* Check if values are the same as strings */
411 if(strcasecmp(s1, s2)==0) continue;
412 /* Try to convert them to doubles */
413 if(doubleGetWithUnit(s1, &v1, NULL)!=0) break;
414 if(doubleGetWithUnit(s2, &v2, NULL)!=0) break;
415 /* Compare the doubles */
416 if(test_lt) {
417 if(verbose>2) printf("testing whether %g < %g\n", v1, v2);
418 if(v1<v2) continue;
419 } else if(test_gt) {
420 if(verbose>2) printf("testing whether %g > %g\n", v1, v2);
421 if(v1>v2) continue;
422 } else if(test_abs>=0) {
423 if(verbose>2) printf("testing whether |%g-%g| < %g\n", v1, v2, test_abs);
424 if(fabs(v1-v2)<test_abs) continue;
425 } else {
426 if(verbose>2) printf("testing whether %g == %g\n", v1, v2);
427 if(v1==v2) continue;
428 }
429 break;
430 }
431 if(i!=n1) {
432 if(verbose>0) fprintf(stderr, "No match: values are not the same.\n");
433 if(verbose>1) printf("value1 := '%s'\nvalue2 := '%s'\n", s1, s2);
434 return(10);
435 }
436 if(verbose>0) fprintf(stdout, "Match was found: values are the same.\n");
437 return(0);
438}