Hi all,
Just in case someone else finds the approach useful, the following awk
script will add a "ratio" column to the output of 'h5diff -v'. That
is, the script turns
dataset: </rhou> and </rhou>
size: [6x3x12] [6x3x12]
position rhou rhou difference
------------------------------------------------------------
[ 0 0 5 ] 0.78521 0.78521 2.22045e-16
[ 3 0 4 ] -1.61703e-16 1.59751e-16 3.21454e-16
[ 3 0 5 ] 1.40625e-16 -8.84112e-17 2.29037e-16
[ 3 0 6 ] -1.90301e-16 5.90473e-17 2.49348e-16
4 differences found
into
dataset: </rhou> and </rhou>
size: [6x3x12] [6x3x12]
position rhou rhou difference ratio
---------------------------------------------------------------------
[ 0 0 5 ] +0.78521 +0.78521 +2.22045e-16 +1
[ 3 0 4 ] -1.61703e-16 +1.59751e-16 +3.21454e-16 -1.01222
[ 3 0 5 ] +1.40625e-16 -8.84112e-17 +2.29037e-16 -1.59058
[ 3 0 6 ] -1.90301e-16 +5.90473e-17 +2.49348e-16 -3.22286
4 differences found
I wrote this because I keep missing obvious multiplicative differences
between files whenever I debug. Save the script to an executable file
and then pipe h5diff's output through it as a filter. Improvements
and/or less brittle ways to accomplish the same thing greatly
appreciated.
- Rhys
#!/usr/bin/awk -f
BEGIN { OFMT=" %+10.6g"; aligner="column -t" }
{
sub("[[:space:]]*$", "")
}
$0 ~ /[[:space:]]+difference([[:space:]]+relative)?$/ {
print $0" ratio"
getline
print $0"---------"
augment = 1
next
}
$0 ~ /^[[:space:]]*[[:digit:]]+[[:space:]]+differences?[[:space:]]+found$/ {
close(aligner)
print
augment = 0
next;
}
augment == 1 {
split($0, a, /\][[:space:]]+/)
printf "%s ]", a[1] | aligner
n = split(a[2], b)
for (i = 1; i <= n; ++i) {
printf OFMT, b[i] | aligner
}
if (b[2] != 0) {
printf OFMT, b[1]/b[2] | aligner
} else {
printf " NaN" | aligner
}
printf "\n"| aligner
next
}
{
print
}