source: LMDZ6/trunk/tools/compare_real.py @ 3654

Last change on this file since 3654 was 2412, checked in by lguez, 9 years ago

Make the use of python or python3 more transparent.

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1"""This script should be called by "diffdef.sh". It operates on
2different lines with common variables. It requires version 2.7 or
3higher of Python (it also works with Python 3).
4
5Author: Lionel GUEZ"""
6
7import sys, os.path
8
9with open(os.path.join(sys.argv[1], "common_var")) as common_var1, \
10        open(os.path.join(sys.argv[2], "common_var")) as common_var2, \
11        open("common_lines", "a") as common_lines, \
12        open("uniq_val", "w") as uniq_val:
13    uniq_val.write("Comparison of " + sys.argv[1] + " and " +  sys.argv[2] 
14                   + ":\n") # title line
15    for line1, line2 in zip(common_var1, common_var2):
16        i = line1.index("=")
17        var_name = line1[:i]
18        value1 = line1[i + 1:-1]
19        value2 = line2[i + 1:-1]
20        try:
21            value1_num = float(value1)
22            value2_num = float(value2)
23        except ValueError:
24            uniq_val.write(var_name + "=\t" + value1 + "\t" + value2 + "\n")
25        else:
26            if (value1_num, value2_num) == (0, 0) \
27                    or abs(value2_num - value1_num) \
28                    / max(abs(value1_num), abs(value2_num)) <= 1e-5:
29                # These should not be integer values, write a formatted value:
30                common_lines.write(var_name + "=" + str(value1_num) + "\n")
31            else:
32                # These could be integer values, write the original strings:
33                uniq_val.write(var_name + "=\t" + value1 + "\t" + value2
34                               + "\n")
Note: See TracBrowser for help on using the repository browser.