Skip to content
Snippets Groups Projects
Commit 82821256 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Enable optional user noise threshold in pycompare

parent 0014260b
No related branches found
No related tags found
No related merge requests found
...@@ -343,6 +343,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=4, log_file=None): ...@@ -343,6 +343,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=4, log_file=None):
log_line + "</code><span style=\"font-weight: bold; color: rgb(255,0,0)\"><code>" log_line + "</code><span style=\"font-weight: bold; color: rgb(255,0,0)\"><code>"
+ c_groups[-1] + "</code></span><code>" + c_line[c_ends[-1]:len(c_line) - 2] + c_groups[-1] + "</code></span><code>" + c_line[c_ends[-1]:len(c_line) - 2]
) )
if ((not config['hide_noise']) or warnings > 0 or errors > 0):
log_file.write(log_line + "</code></pre></div>\n") log_file.write(log_line + "</code></pre></div>\n")
log_file.write(ref_line) log_file.write(ref_line)
else: # The two lines contain a different number of numeric values else: # The two lines contain a different number of numeric values
...@@ -430,9 +431,12 @@ def mismatch_severities(str_f_values, str_c_values, config): ...@@ -430,9 +431,12 @@ def mismatch_severities(str_f_values, str_c_values, config):
if (fractional <= config['warning_threshold']): if (fractional <= config['warning_threshold']):
result[i] = 2 result[i] = 2
else: else:
if (log_f_value > config['data_order']):
result[i] = 3 result[i] = 3
else: else:
result[i] = 1 result[i] = 1
else:
result[i] = 1
else: # f_values[i] == 0 and c_values[i] != 0 else: # f_values[i] == 0 and c_values[i] != 0
sign = 1.0 if c_values[i] > 0.0 else -1.0 sign = 1.0 if c_values[i] > 0.0 else -1.0
log_c_value = log10(sign * c_values[i]) log_c_value = log10(sign * c_values[i])
...@@ -443,9 +447,12 @@ def mismatch_severities(str_f_values, str_c_values, config): ...@@ -443,9 +447,12 @@ def mismatch_severities(str_f_values, str_c_values, config):
if (fractional <= config['warning_threshold']): if (fractional <= config['warning_threshold']):
result[i] = 2 result[i] = 2
else: else:
if (log_c_value > config['data_order']):
result[i] = 3 result[i] = 3
else: else:
result[i] = 1 result[i] = 1
else:
result[i] = 1
# End number comparison # End number comparison
return result return result
...@@ -460,25 +467,40 @@ def mismatch_severities(str_f_values, str_c_values, config): ...@@ -460,25 +467,40 @@ def mismatch_severities(str_f_values, str_c_values, config):
# \returns config: `dict` A dictionary containing the script configuration. # \returns config: `dict` A dictionary containing the script configuration.
def parse_arguments(): def parse_arguments():
config = { config = {
'fortran_file_name': '',
'c_file_name': '', 'c_file_name': '',
'check_all': True,
'data_order': -99.0,
'fortran_file_name': '',
'full_log': False, 'full_log': False,
'help_mode': False,
'hide_noise': False,
'html_output': 'pycompare.html',
'linewise': True, 'linewise': True,
'log_html': False, 'log_html': False,
'html_output': 'pycompare.html',
'say_progress': True, 'say_progress': True,
'warning_threshold': 0.005, 'warning_threshold': 0.005,
'help_mode': False,
'check_all': True,
} }
arg_index = 1
skip_arg = False
for arg in argv[1:]: for arg in argv[1:]:
if skip_arg:
skip_arg = False
continue
split_arg = arg.split("=") split_arg = arg.split("=")
if (arg.startswith("--ffile")): if (arg.startswith("--ffile")):
config['fortran_file_name'] = split_arg[1] config['fortran_file_name'] = argv[arg_index + 1]
arg_index += 1
skip_arg = True
elif (arg.startswith("--cfile")): elif (arg.startswith("--cfile")):
config['c_file_name'] = split_arg[1] config['c_file_name'] = argv[arg_index + 1]
arg_index += 1
skip_arg = True
elif (arg.startswith("--data-order")):
config['data_order'] = float(split_arg[1])
elif (arg.startswith("--full")): elif (arg.startswith("--full")):
config['full_log'] = True config['full_log'] = True
elif (arg.startswith("--hide-noise")):
config['hide_noise'] = True
elif (arg.startswith("--html")): elif (arg.startswith("--html")):
config['log_html'] = True config['log_html'] = True
if (len(split_arg) == 2): if (len(split_arg) == 2):
...@@ -495,6 +517,7 @@ def parse_arguments(): ...@@ -495,6 +517,7 @@ def parse_arguments():
config['check_all'] = False config['check_all'] = False
else: else:
raise Exception("Unrecognized argument \'{0:s}\'".format(arg)) raise Exception("Unrecognized argument \'{0:s}\'".format(arg))
arg_index += 1
return config return config
## \brief Print a command-line help summary. ## \brief Print a command-line help summary.
...@@ -507,10 +530,12 @@ def print_help(): ...@@ -507,10 +530,12 @@ def print_help():
print("Usage: \"./pycompare.py OPTIONS\" ") print("Usage: \"./pycompare.py OPTIONS\" ")
print(" ") print(" ")
print("Valid options are: ") print("Valid options are: ")
print("--ffile=FORTRAN_OUTPUT File containing the output of the FORTRAN code (mandatory).") print("--ffile FORTRAN_OUTPUT File containing the output of the FORTRAN code (mandatory).")
print("--cfile=C++_OUTPUT File containing the output of the C++ code (mandatory).") print("--cfile C++_OUTPUT File containing the output of the C++ code (mandatory).")
print("--data-order=ORDER Consider data only down to specified order (default order is -99).")
print("--full Print all lines to log file (default prints only mismatches).") print("--full Print all lines to log file (default prints only mismatches).")
print("--help Print this help and exit.") print("--help Print this help and exit.")
print("--hide-noise Hide noise in reports (default is to show it).")
print("--html[=OPT_OUTPUT_NAME] Enable logging to HTML file (default logs to \"pycompare.html\").") print("--html[=OPT_OUTPUT_NAME] Enable logging to HTML file (default logs to \"pycompare.html\").")
print("--linewise Load only one line at a time. Useful to compare big files (True by default).") print("--linewise Load only one line at a time. Useful to compare big files (True by default).")
print("--no-progress Disable progress logging.") print("--no-progress Disable progress logging.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment