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

added new function to run the system with a log for further plotting or so

parent 030ae155
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,8 @@ static char create_binary_docstring[] = ...@@ -31,6 +31,8 @@ static char create_binary_docstring[] =
#endif #endif
static char run_binary_docstring[] = static char run_binary_docstring[] =
"Run one binary using binary_c"; "Run one binary using binary_c";
static char run_binary_with_logdocstring[] =
"Run one binary using binary_c and allow the logfile to be written. Do not use for populations!";
static char new_binary_system_docstring[] = static char new_binary_system_docstring[] =
"Return an object containing a binary, ready for evolution"; "Return an object containing a binary, ready for evolution";
static char function_prototype_docstring[] = static char function_prototype_docstring[] =
...@@ -43,6 +45,7 @@ static struct libbinary_c_store_t *store = NULL; ...@@ -43,6 +45,7 @@ static struct libbinary_c_store_t *store = NULL;
static PyObject* binary_c_create_binary(PyObject *self, PyObject *args); static PyObject* binary_c_create_binary(PyObject *self, PyObject *args);
#endif #endif
static PyObject* binary_c_run_binary(PyObject *self, PyObject *args); static PyObject* binary_c_run_binary(PyObject *self, PyObject *args);
static PyObject* binary_c_run_binary_with_log(PyObject *self, PyObject *args);
static PyObject* binary_c_function_prototype(PyObject *self, PyObject *args); static PyObject* binary_c_function_prototype(PyObject *self, PyObject *args);
static PyObject* binary_c_new_binary_system(PyObject *self, PyObject *args); static PyObject* binary_c_new_binary_system(PyObject *self, PyObject *args);
static PyObject* binary_c_return_arglines(PyObject *self, PyObject *args); static PyObject* binary_c_return_arglines(PyObject *self, PyObject *args);
...@@ -60,6 +63,7 @@ static PyMethodDef module_methods[] = { ...@@ -60,6 +63,7 @@ static PyMethodDef module_methods[] = {
{"create_binary", binary_c_create_binary, METH_VARARGS, create_binary_docstring}, {"create_binary", binary_c_create_binary, METH_VARARGS, create_binary_docstring},
#endif #endif
{"run_binary", binary_c_run_binary, METH_VARARGS, run_binary_docstring}, {"run_binary", binary_c_run_binary, METH_VARARGS, run_binary_docstring},
{"run_binary_with_log", binary_c_run_binary_with_log, METH_VARARGS, run_binary_with_logdocstring},
{"function_prototype", binary_c_function_prototype, METH_VARARGS, function_prototype_docstring}, {"function_prototype", binary_c_function_prototype, METH_VARARGS, function_prototype_docstring},
{"new_system", binary_c_new_binary_system, METH_VARARGS, new_binary_system_docstring}, {"new_system", binary_c_new_binary_system, METH_VARARGS, new_binary_system_docstring},
{"return_arglines", binary_c_return_arglines, METH_VARARGS, return_arglines_docstring}, {"return_arglines", binary_c_return_arglines, METH_VARARGS, return_arglines_docstring},
...@@ -191,6 +195,29 @@ static PyObject* binary_c_run_binary(PyObject *self, PyObject *args) ...@@ -191,6 +195,29 @@ static PyObject* binary_c_run_binary(PyObject *self, PyObject *args)
} }
} }
static PyObject* binary_c_run_binary_with_log(PyObject *self, PyObject *args)
{
/* Parse the input tuple */
char *argstring;
if(!PyArg_ParseTuple(args, "s", &argstring))
{
return NULL;
}
else
{
char * buffer;
int nbytes;
int out MAYBE_UNUSED = run_binary_with_log(argstring,
&buffer,
&nbytes);
/* copy the buffer to a python string */
PyObject * ret = Py_BuildValue("s", buffer);
free(buffer);
return ret;
}
}
static PyObject* binary_c_return_arglines(PyObject *self, PyObject *args) static PyObject* binary_c_return_arglines(PyObject *self, PyObject *args)
{ {
/* Binary structures */ /* Binary structures */
......
...@@ -13,6 +13,12 @@ int run_binary (char * argstring, ...@@ -13,6 +13,12 @@ int run_binary (char * argstring,
char ** outstring, char ** outstring,
int * nbytes); int * nbytes);
int run_binary_with_log (char * argstring,
char ** outstring,
int * nbytes);
int return_arglines(char ** buffer, int return_arglines(char ** buffer,
int * nbytes); int * nbytes);
......
...@@ -166,4 +166,52 @@ int return_arglines(char ** buffer, ...@@ -166,4 +166,52 @@ int return_arglines(char ** buffer,
binary_c_free_memory(&stardata,TRUE,TRUE,FALSE); binary_c_free_memory(&stardata,TRUE,TRUE,FALSE);
binary_c_free_store_contents(store); binary_c_free_store_contents(store);
return 0; return 0;
} }
\ No newline at end of file
int run_binary_with_log(char * argstring,
char ** buffer,
int * nbytes)
{
/* memory for N binary systems */
struct libbinary_c_stardata_t *stardata;
struct libbinary_c_store_t * store = NULL;
/* make new stardata */
stardata = NULL;
binary_c_new_system(&stardata,
NULL,
NULL,
&store,
&argstring,
-1);
/* disable logging */
// snprintf(stardata->preferences->log_filename,
// STRING_LENGTH-1,
// "%s",
// "/dev/null");
// snprintf(stardata->preferences->api_log_filename_prefix,
// STRING_LENGTH-1,
// "%s",
// "/dev/null");
/* output to strings */
stardata->preferences->internal_buffering = 2;
stardata->preferences->internal_buffering_compression = 0;
stardata->preferences->batchmode = BATCHMODE_LIBRARY;
/* do binary evolution */
binary_c_evolve_for_dt(stardata,
stardata->model.max_evolution_time);
/* get buffer pointer */
binary_c_buffer_info(stardata,buffer,nbytes);
/* set raw_buffer_size = -1 to prevent it being freed */
stardata->tmpstore->raw_buffer_size = -1;
/* free stardata (except the buffer) */
binary_c_free_memory(&stardata,TRUE,TRUE,FALSE);
binary_c_free_store_contents(store);
return 0;
}
...@@ -59,6 +59,7 @@ def run_system(**kwargs): ...@@ -59,6 +59,7 @@ def run_system(**kwargs):
# Construct arguments string and final execution string # Construct arguments string and final execution string
arg_string = create_arg_string(args) arg_string = create_arg_string(args)
arg_string = f'binary_c {arg_string}' arg_string = f'binary_c {arg_string}'
# print(arg_string) # print(arg_string)
# Run it and get output # Run it and get output
...@@ -67,6 +68,37 @@ def run_system(**kwargs): ...@@ -67,6 +68,37 @@ def run_system(**kwargs):
return output return output
def run_system_with_log(**kwargs):
"""
Wrapper to run a system with settings AND logs the files to a designated place defined by the log_filename parameter.
"""
# Load default args
args = get_defaults()
# args = {}
# For example
# physics_args['M_1'] = 20
# physics_args['separation'] = 0 # 0 = ignored, use period
# physics_args['orbital_period'] = 100000000000 # To make it single
# Use kwarg value to override defaults and add new args
for key in kwargs.keys():
args[key] = kwargs[key]
# Construct arguments string and final execution string
arg_string = create_arg_string(args)
arg_string = f'binary_c {arg_string}'
# print(arg_string)
# Run it and get output
buffer = ""
output = binary_c.run_binary_with_log(arg_string)
return output
def parse_output(output, selected_header): def parse_output(output, selected_header):
""" """
Function that parses output of binaryc when it is construction like this: Function that parses output of binaryc when it is construction like this:
......
No preview for this file type
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