source: LMDZ6/branches/LMDZ_cdrag_LSCE/tools/compare_real.py @ 4911

Last change on this file since 4911 was 4512, checked in by lguez, 15 months ago

Update diffdef.sh

Updated with the version which was on LMDZ website, in [Boîte à outils
LMDZ](https://lmdz.lmd.jussieu.fr/utilisateurs/utilisation-de-lmdz). Removed
the corresponding tar file on LMDZ website, to avoid confusion.

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/env python3
2
3"""This script should be called by "diffdef.sh". It operates on
4different lines with common variables.
5
6Author: Lionel GUEZ"""
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.