wind-diff.py (850B)
1 import math 2 3 def read_last_column(filename): 4 result = [] 5 with open(filename) as f1: 6 result = [[float(p[0]),float(p[1])] for p in 7 [line.split()[2:4] for line in f1.readlines()]] 8 return result 9 10 def length(v): 11 return math.sqrt(v[0]*v[0]+v[1]*v[1]) 12 13 w1 = read_last_column('gnuplot/wind.orig') 14 w2 = read_last_column('gnuplot/wind.our') 15 16 diff_max = 0 17 length_max = 0 18 for wind_orig, wind_our in zip(w1,w2): 19 len1 = length(wind_orig) 20 len2 = length(wind_our) 21 #diff = (abs(100-(len2 / len1 * 100))) 22 diff = abs(len2 - len1) 23 if (len1 > length_max): length_max = len1 24 if (len2 > length_max): length_max = len2 25 if (diff > diff_max): diff_max = diff 26 27 print('Max. velocity: {}'.format(length_max)) 28 print('Max. difference: {}'.format(diff_max)) 29 print('Max. error: {}'.format(diff_max/length_max*100))