forked from nrnhines/nrntraub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcsdiff.py
66 lines (59 loc) · 1.59 KB
/
pcsdiff.py
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
printall = 1
import sys
filenames = sys.argv[1:]
if len(filenames) != 2:
print 'usage: python pcsdiff.py file1 file2'
quit()
print filenames
data = []
for name in filenames:
f = open(name, "r")
data.append([line.split() for line in f])
f.close()
for f in data:
for l in f:
for i, item in enumerate(l):
if item.isdigit():
ival = int(item)
l[i] = ival
else:
try:
xval = float(item)
l[i] = xval
except:
pass
data = zip(data[0], data[1])
relative = (0,0,0.,0.)
absolute = (0,0,0.,0.)
tag = "tag"
atag = tag
rtag = tag
tagsave = ""
for i, pair in enumerate(data):
if type(pair[0][0]) == str:
tag = " ".join([str(v) for v in pair[0]])
if pair[0] != pair[1]:
z = zip(pair[0], pair[1])
for j, values in enumerate(z):
if values[0] != values[1]:
assert(type(values[0]) == float or type(values[1]) == float)
x = abs(values[0] - values[1])
y = x/(abs(values[0]) + abs(values[1]))
if (x > absolute[3]):
absolute = (i+1, j, values[0], x)
atag = tag
if (y > relative[3]):
relative = (i+1, j, values[0], y)
rtag = tag
if printall:
if tagsave != tag:
tagsave = tag
print tag
node = data[i][0][0]
ix = data[i][0][1]
print "%d,%d %d %d %g diff %g" % (i+1,j, node, ix, values[0], x)
if relative[3] > 0.:
print "line %d,%d %.12g diff %g relative : " % relative, rtag
print "line %d,%d %.12g diff %g absolute : " % absolute, atag
else:
print 'files identical'