source: LMDZ6/branches/LMDZ_ECRad/tools/compare_real.py @ 5304

Last change on this file since 5304 was 4727, checked in by idelkadi, 13 months ago

Merged trunk changes -r4488:4726 LMDZ_ECRad branch

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