-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvtk_diff.py
More file actions
executable file
·74 lines (63 loc) · 2.06 KB
/
Copy pathvtk_diff.py
File metadata and controls
executable file
·74 lines (63 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import sys
##################################
##################################
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
##################################
##################################
# Command line check, it takes two files to compare
if len(sys.argv) != 3 :
print ("Usage: vtk_diff.py <file> <expected_file>")
sys.exit(1)
# Read in the two files to be compared
try :
file = open(sys.argv[1], "r")
except IOError:
print ("Failed to open file: " + sys.argv[1])
exit(1)
lines = file.readlines()
file.close()
try :
exp_file = open(sys.argv[2], "r")
except IOError:
print ("Failed to open file: " + sys.argv[2])
exit(1)
exp_lines = exp_file.readlines()
exp_file.close()
# First a quick check to see the two files have the same number of lines
if (len(lines) != len(exp_lines)) :
print ("The two files do not have the same number of lines.")
sys.exit(1)
diff = False
for i in range(0, len(lines)) :
if (is_number(lines[i]) and is_number(exp_lines[i])) :
val = float(lines[i])
exp_val = float(exp_lines[i])
if (abs(exp_val) < 1.0e-8) :
# FIXME: This criterion seems still overly rigorous
if (abs(val - exp_val) > 1.0e-8) :
diff = True
print ("Line %d: Numbers are different between the two files:" % (i+1))
print ("Actual value = %e; Expected value = %e" % (val, exp_val))
else :
if (abs((val - exp_val) / exp_val) > 1.0e-8) :
diff = True
print ("Line %d: Numbers are different between the two files:" % (i+1))
print ("Actual value = %f; Expected value = %f" % (val, exp_val))
else :
if (lines[i] != exp_lines[i]) :
diff = True
print ("Line %d: String is different between the two files." % (i+1))
print (" <File> :", lines[i].rstrip())
print (" <Expected File>:", exp_lines[i].rstrip())
if (not diff) :
print ("The two files are the same [with zero_tol = %e, and rel_tol = %e]" % (1.0e-8, 1.0e-8))
sys.exit(0)
else :
print ("The two files are different.")
sys.exit(1)