1 # Compare metadata filter output containing float value strings to reference
2 # output data. Returns the whole reference data if delta of each value is below
3 # threshold, else returns the whole input data.
6 return ((val < 0.0) ? -val : val);
9 function max(val1, val2) {
10 return ((val1 >= val2) ? val1 : val2);
13 function is_numeric_str(str) {
14 return (str ~ /^[+-]?[0-9]*\.?[0-9]+$/);
19 # check for "fuzz" (threshold) program parameter, else use default
23 # check for "ref" (reference file) program parameter
26 while ((getline line < ref) > 0) {
28 ref_lines[ref_nr] = line;
29 if (split(line, fields) == 2 && is_numeric_str(fields[2])) {
30 ref_keys[ref_nr] = fields[1];
31 ref_vals[ref_nr] = fields[2] + 0; # convert to number
37 result = (ref ? 1 : 0);
42 if (NF == 2 && is_numeric_str($2) && ref_vals[NR]) {
43 val = $2 + 0; # convert to number
44 delta = abs((val / ref_vals[NR]) - 1);
45 delta_max = max(delta_max, delta);
46 result = result && ($1 == ref_keys[NR]) && (delta <= fuzz);
48 result = result && ($0 == ref_lines[NR]);
54 for (i = 1; i <= ref_nr; i++)
57 for (i = 1; i <= NR; i++)
60 print "[refcmp] lines: " NR " != " ref_nr > "/dev/stderr";
61 if (delta_max >= fuzz)
62 print "[refcmp] delta_max: " delta_max " >= " fuzz > "/dev/stderr";