Skip to content
Snippets Groups Projects
Commit 3037d570 authored by David Hendriks's avatar David Hendriks
Browse files

added functionality to run_system wrapper function

parent 9efa1b58
No related branches found
No related tags found
No related merge requests found
......@@ -12,12 +12,24 @@ from binarycpython.utils.custom_logging_functions import (
def run_system(**kwargs):
"""
Wrapper to run a system with settings
Function that runs a system. Mostly as a useful utility function that handles all the setup of argument lists etc.
All~ the arguments known to binary_c can be passed to this function as kwargs.
Several extra arguments can be passed through the kwargs:
* custom_logging_code (string): Should contain a string containing the c-code for the shared library.
If this is provided binary_c will use that custom logging code to output its data
* log_filename (string): Should contain name of the binary_c system logfile.
Passing this will make sure that the filename gets written for a run (its default behaviour is NOT to write a logfile for a system)
* parse_function (function): should contain a function that parses the output. The parse function should take 1 required parameter: the output of the binaryc run
Passing this will call the parse_function by passing it the output of the binary_c call and returns what the parse_function returns
This function determines which underlying python-c api function will be called based upon the arguments that are passed via kwargs.
examples:
* run_system(M_1=10): will run a system with ZAMS mass 1 = 10
* run_system(M_1=10, log_filename="~/example_log.txt"): Will run a system and write the logfile to
* run_system(M_1=10, parse_function=fancy_parsing_function)
- if custom_logging_code or custom_logging_dict is included in the kwargs then it will
- if
Todo:
* Expand functionality.
"""
......@@ -45,10 +57,15 @@ def run_system(**kwargs):
write_logfile = 1
# Construct arguments string and final execution string
arg_string = create_arg_string(binary_c_args)
arg_string = "binary_c {}".format(arg_string)
binary_c_command = "binary_c {}".format(arg_string)
output = binary_c_python_api.run_system(binary_c_command, custom_logging_func_memaddr=func_memaddr, write_logfile=write_logfile)
output = binary_c_python_api.run_system(arg_string, custom_logging_func_memaddr=func_memaddr, write_logfile=write_logfile)
return output
\ No newline at end of file
if "parse_function" in kwargs:
return kwargs["parse_function"](output)
else:
return output
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment