forked from python-hydro/pyro2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare.py
More file actions
executable file
·74 lines (46 loc) · 1.38 KB
/
Copy pathcompare.py
File metadata and controls
executable file
·74 lines (46 loc) · 1.38 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
from __future__ import print_function
import numpy
import mesh.patch
import getopt
import sys
usage = """
usage: ./compare.py file1 file2
"""
errors = {"gridbad": "grids don't agree",
"namesbad": "variable lists don't agree",
"varerr": "one or more variables don't agree"}
def compare(myg1, myd1, myg2, myd2):
# compare the grids
if not myg1 == myg2:
return "gridbad"
# compare the data
if not myd1.vars == myd2.vars:
return "namesbad"
print(" ")
print("variable comparisons:")
result = 0
n = 0
while n < myd1.nvar:
d1 = myd1.get_var(myd1.vars[n])
d2 = myd2.get_var(myd2.vars[n])
err = numpy.max(numpy.abs(d1[myg1.ilo:myg1.ihi+1,myg1.jlo:myg1.jhi+1] -
d2[myg2.ilo:myg2.ihi+1,myg2.jlo:myg2.jhi+1]))
print("%20s error = %20.10g" % (myd1.vars[n], err))
if not err == 0:
result = "varerr"
n += 1
return result
if __name__== "__main__":
if not len(sys.argv) == 3:
print(usage)
sys.exit(2)
file1 = sys.argv[1]
file2 = sys.argv[2]
myg1, myd1 = mesh.patch.read(file1)
myg2, myd2 = mesh.patch.read(file2)
result = compare(myg1, myd1, myg2, myd2)
if result == 0:
print("SUCCESS: files agree")
else:
print("ERROR: ", errors[result])