From e3294d31ca09e54faf5f2b86484bc874384562a8 Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Sat, 16 Dec 2023 17:18:44 +0100
Subject: [PATCH] Write original lines in comparison script

---
 src/scripts/pycompare.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/scripts/pycompare.py b/src/scripts/pycompare.py
index d919a82a..92420746 100755
--- a/src/scripts/pycompare.py
+++ b/src/scripts/pycompare.py
@@ -6,7 +6,7 @@
 #  Comparing the numeric output can be rendered hard by the amount of information
 #  contained in a typical output file and the necessity to determine whether a
 #  difference is actually significant or just caused by numeric noise hitting
-#  negligible values. The task of this script is to compare two output files, in
+#  negligible values. The task of `pycompare.py` is to compare two output files, in
 #  the assumption that they were written by the FORTRAN and the C++ versions of
 #  the code and to flag all the possible inconsistencies according to various
 #  severity levels (namely: NOISE, WARNING, and ERROR).
@@ -105,7 +105,7 @@ def compare_files(config):
         line_count = len(f_lines)
         num_len = 1
         if (line_count > 0):
-            num_len = int(log10(line_count)) + 1
+            num_len = max(4, int(log10(line_count)) + 1)
         if (config['log_html']):
             l_file = open(config['html_output'], 'w')
             l_file.write("<!DOCTYPE html>\n")
@@ -157,11 +157,13 @@ def compare_files(config):
 #
 #  \returns mismatch_count: `tuple(int, int, int)` A tuple that bundles
 #  together the numbers of detected errors, warnings and noisy values.
-def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None):
+def compare_lines(f_line, c_line, config, line_num=0, num_len=4, log_file=None):
     errors = 0
     warnings = 0
     noisy = 0
     f_line = f_line.replace("D-","E-").replace("D+","E+")
+    ref_format = "    <div><span style=\"font-weight: bold; color: rgb(125,125,125)\"><pre><code>{0:%ds}"%num_len
+    ref_line = (ref_format + ": {1:s}</code></pre></span></div>\n").format("ORIG", f_line[:-1])
     if (f_line == c_line):
         if log_file is not None:
             if (config['full_log']):
@@ -246,6 +248,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None):
                                 + c_groups[-1] + "</code></span><code>" + c_line[c_ends[-1]:len(c_line) - 2]
                             )
                 log_file.write(log_line + "</code></pre></div>\n")
+                log_file.write(ref_line)
         else: # The two lines contain a different number of numeric values
             if (log_file is not None):
                 num_format = "    <div><pre><code>{0:0%dd}"%num_len
@@ -255,6 +258,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=1, log_file=None):
                     + c_line + "</code></span><code>"
                 )
                 log_file.write(log_line + "</code></pre></div>\n")
+                log_file.write(ref_line)
             errors += 1
     return (errors, warnings, noisy)
 
-- 
GitLab