From 7adea668e6400d11623dce449d310bdee4e887f7 Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Sat, 9 Nov 2019 23:05:32 +0000
Subject: [PATCH] moving files to different directory and exclude them from the
 merge with master

---
 TODO.org                                      |   8 +-
 TODO2.org                                     | 167 ------------------
 binary_c_python.c                             |   8 +-
 binary_c_python.h                             |   2 +-
 binary_c_python_api.c                         |   6 +-
 setup.py                                      |  14 +-
 {examples => testing_examples}/__init__.py    |   0
 .../example_notebook.ipynb                    |   0
 .../full_evolution_with_plot.py               |   0
 .../log_filename_test.py                      |   0
 {examples => testing_examples}/loop_system.py |   0
 {examples => testing_examples}/simple_test.py |   0
 .../single_system.py                          |   0
 13 files changed, 20 insertions(+), 185 deletions(-)
 delete mode 100644 TODO2.org
 rename {examples => testing_examples}/__init__.py (100%)
 rename {examples => testing_examples}/example_notebook.ipynb (100%)
 rename {examples => testing_examples}/full_evolution_with_plot.py (100%)
 rename {examples => testing_examples}/log_filename_test.py (100%)
 rename {examples => testing_examples}/loop_system.py (100%)
 rename {examples => testing_examples}/simple_test.py (100%)
 rename {examples => testing_examples}/single_system.py (100%)

diff --git a/TODO.org b/TODO.org
index ec732ae75..7c718ba74 100644
--- a/TODO.org
+++ b/TODO.org
@@ -145,10 +145,12 @@ That went very deep haha. alot of memory allocation stuff
     CLOSED: [2019-11-08 Fri 15:48]
 *** DONE Load all the things with the c-types
     CLOSED: [2019-11-08 Fri 18:49]
-*** TODO Implement new function for run_binary_with_custom_logging
-*** TODO Make new c function run_binary_with_custom_logging
+*** DONE Implement new function for run_binary_with_custom_logging
+    CLOSED: [2019-11-08 Fri 21:19]
+*** DONE Make new c function run_binary_with_custom_logging
+    CLOSED: [2019-11-08 Fri 21:19]
 *** TODO Put in some new tests in the python test api
-
+*** TODO Make sure the sharedlibs get written to the correct directory
 ** General:
 *** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?)
     CLOSED: [2019-10-29 Tue 17:44]
diff --git a/TODO2.org b/TODO2.org
deleted file mode 100644
index 7c718ba74..000000000
--- a/TODO2.org
+++ /dev/null
@@ -1,167 +0,0 @@
-* Todo list for the binary_c-python
-** Logging functionality:
-*** Idea
-Idea is to be able to give a string via python that will be used in the through the libbinary_c.so so that log_every_timestep.c 
-The code below is the piece in log_every_timestep that uses it.
-
-    if(stardata->preferences->custom_output_function != NULL)
-    {
-        Dprint("calling custom output function %p\n",
-               stardata->preferences->custom_output_function);
-        stardata->preferences->custom_output_function(stardata);
-    }
-
-So the function should recieve 'stardata' as input.
-
-We can do that with providing a logging string alltogether, or generate a logging function
-
-In either way, this should be passed to stardata->preferences->custom_output_function as a pointer to that function
-
-*** Provide string for logging
-In perl this is done in the following way:
-**** code to input
-And then to use it via 
-    $population->set(
-        C_logging_code => '
-             PRINTF("MY_STELLAR_DATA %g %g %g %g\n",
-                 stardata->model.time,
-                 stardata->star[0].mass,
-                 stardata->model.probability,
-                 stardata->model.dt);
-                       '
-    );
-**** code to handle that input
-sub binary_c_log_code
-{
-    my ($code) = @_;
-    return "
-#pragma push_macro(\"MAX\")
-#pragma push_macro(\"MIN\")
-#undef MAX
-#undef MIN
-#include \"binary_c.h\"
-
-void custom_output_function(SV * x);
-SV * custom_output_function_pointer(void);
-
-SV * custom_output_function_pointer()
-{
-    /*
-     * use PTR2UV to convert the function pointer 
-     * &custom_output_function to an unsigned int,
-     * which is then converted to a Perl SV
-     */
-    return (SV*)newSVuv(PTR2UV(&custom_output_function));
-}
-
-void custom_output_function(SV * x)
-{
-    struct stardata_t * stardata = (struct stardata_t *)x;
-    $code;
-}
-#undef MAX 
-#undef MIN
-#pragma pop_macro(\"MIN\")
-#pragma pop_macro(\"MAX\")
-";
-}
-Or use it via:
-*** auto logging
-We should also try to be able to have the code autogenerate some logging function via the following:
-**** input in perl
-$population->set(    C_auto_logging => {
-        'MY_STELLAR_DATA' =>
-            [
-             'model.time',
-             'star[0].mass',
-             'model.probability',
-             'model.dt'
-            ]
-    });
-**** code to handle that input
-Which is handled in perl via (see binary_grid2.pm
-sub autogen_C_logging_code
-{
-    # given a hash of arrays of variable names, where the hash
-    # key is the header, autogenerate PRINTF statements
-    my ($self) = @_;
-    my $code = undef;
-    if(defined $self->{_grid_options}->{C_auto_logging} &&
-       ref $self->{_grid_options}->{C_auto_logging} eq 'HASH'
-        )
-    {
-        $code = '';
-
-        foreach my $header (keys %{$self->{_grid_options}->{C_auto_logging}})
-        {
-            if(ref $self->{_grid_options}->{C_auto_logging}->{$header} eq 'ARRAY')
-            {
-                $code .= 'PRINTF("'.$header.' ';
-                foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
-                {
-                    $code .= '%g ';
-                }
-                $code .= '\n"';
-
-                foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
-                {
-                    $code .= ',((double)stardata->'.$x.')';
-                }
-                $code .= ');'
-            }
-        }
-    }
-    print "MADE AUTO CODE \n\n************************************************************\n\n$code\n\n************************************************************\n";
-
-    return $code;
-}
-*** DONE Make function in python that puts code into c function
-    CLOSED: [2019-10-31 Thu 11:13]
-*** DONE Make function in python that generates c-function from a list of arguments
-    CLOSED: [2019-10-29 Tue 23:52]
-*** DONE Resolve current issue malloc
-    CLOSED: [2019-11-08 Fri 11:12]
-➜  binary_c-python git:(master) ✗ python python_API_test.py 
-Traceback (most recent call last):
-  File "python_API_test.py", line 3, in <module>
-    import binary_c
-ImportError: /home/david/projects/binary_c_root/binary_c-python/libbinary_c_api.so: undefined symbol: MALLOC
-
-I get this error when I am using the master version of binary_c with either branches of the python wrapper..
-
-That went very deep haha. alot of memory allocation stuff
-
-*** DONE Make sure this works with the last major release of binaryc
-    CLOSED: [2019-11-08 Fri 15:00]
-*** DONE Finish testing a simpler case (see other repo)
-    CLOSED: [2019-11-08 Fri 09:37]
-*** DONE Make master master work
-    CLOSED: [2019-11-08 Fri 15:00]
-*** DONE Sync master with david_branch
-    CLOSED: [2019-11-08 Fri 15:00]
-*** DONE make tag of old master branch for future reference
-    CLOSED: [2019-11-08 Fri 15:00]
-*** DONE Implement the autogeneration of the library
-    CLOSED: [2019-11-08 Fri 15:48]
-*** DONE Load all the things with the c-types
-    CLOSED: [2019-11-08 Fri 18:49]
-*** DONE Implement new function for run_binary_with_custom_logging
-    CLOSED: [2019-11-08 Fri 21:19]
-*** DONE Make new c function run_binary_with_custom_logging
-    CLOSED: [2019-11-08 Fri 21:19]
-*** TODO Put in some new tests in the python test api
-*** TODO Make sure the sharedlibs get written to the correct directory
-** General:
-*** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?)
-    CLOSED: [2019-10-29 Tue 17:44]
-*** DONE make routine that reads out all the lines, splits them into pieces and reads out the correct key
-    CLOSED: [2019-10-29 Tue 17:43]
-*** TODO Put header and other source files in a dedicated directory
-*** TODO Use sphinx or read the docs for auto generation of documentation
-*** TODO Have the compiled files put into a build directory
-*** TODO add pythonpath thing to readme
-*** TODO make script that will set up binaryc automatically so that this can become an out of the box thing
-*** TODO Test the importing of this code from different places
-** Population ideas
-*** TODO Queuing system and some multiprocessing to run many systems
-*** TODO Consider rewriting the work that perl does
diff --git a/binary_c_python.c b/binary_c_python.c
index 00f4abd5e..b94452b24 100644
--- a/binary_c_python.c
+++ b/binary_c_python.c
@@ -223,9 +223,9 @@ static PyObject* binary_c_run_binary_custom_logging(PyObject *self, PyObject *ar
 {
     /* Parse the input tuple */
     char *argstring;
-    long int str_1;
+    long int func_memaddr;
 
-    if(!PyArg_ParseTuple(args, "sl", &argstring, &str_1))
+    if(!PyArg_ParseTuple(args, "sl", &argstring, &func_memaddr))
     {
         return NULL;
     }
@@ -235,7 +235,7 @@ static PyObject* binary_c_run_binary_custom_logging(PyObject *self, PyObject *ar
         char * error_buffer;
         size_t nbytes;
         int out MAYBE_UNUSED = run_binary_custom_logging(argstring,
-                                            str_1, 
+                                          func_memaddr, 
                                           &buffer,
                                           &error_buffer,
                                           &nbytes);
@@ -330,4 +330,4 @@ static PyObject* binary_c_return_arglines(PyObject *self, PyObject *args)
      * return the return_error_string as well!
      */
     return return_string;
-}
\ No newline at end of file
+}
diff --git a/binary_c_python.h b/binary_c_python.h
index 152c6e514..29979236e 100644
--- a/binary_c_python.h
+++ b/binary_c_python.h
@@ -20,7 +20,7 @@ int run_binary_with_logfile (char * argstring,
                 size_t * const nbytes);
 
 int run_binary_custom_logging(char * argstring,
-               long int str_1,
+               long int func_memaddr,
                char ** const buffer,
                char ** const error_buffer,
                size_t * const nbytes);
diff --git a/binary_c_python_api.c b/binary_c_python_api.c
index 04a0a9a8a..309fc39a3 100644
--- a/binary_c_python_api.c
+++ b/binary_c_python_api.c
@@ -97,7 +97,7 @@ int run_binary(char * argstring,
 }
 
 int run_binary_custom_logging(char * argstring,
-               long int str_1,
+               long int func_memaddr,
                char ** const buffer,
                char ** const error_buffer,
                size_t * const nbytes)
@@ -127,7 +127,7 @@ int run_binary_custom_logging(char * argstring,
     /* output to strings */
     stardata->preferences->internal_buffering = INTERNAL_BUFFERING_STORE;
     stardata->preferences->batchmode = BATCHMODE_LIBRARY;
-    stardata->preferences->custom_output_function = str_1;
+    stardata->preferences->custom_output_function = (void*)(struct stardata_t *)func_memaddr;
 
     /* do binary evolution */
     binary_c_evolve_for_dt(stardata,
@@ -239,4 +239,4 @@ int run_binary_with_logfile(char * argstring,
     binary_c_free_memory(&stardata,TRUE,TRUE,FALSE,FALSE);
     binary_c_free_store_contents(store);
     return 0;
-}
\ No newline at end of file
+}
diff --git a/setup.py b/setup.py
index cbd77df38..550b36262 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,6 @@ binary_c_config = os.environ['BINARY_C']+'/binary_c-config'
 binary_c_incdirs = subprocess.run([binary_c_config,'incdirs_list'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
 binary_c_libdirs = subprocess.run([binary_c_config,'libdirs_list'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
 binary_c_cflags =  subprocess.run([binary_c_config,'cflags'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
-# binary_c_cflags.remove('-fvisibility=hidden')
 binary_c_libs = subprocess.run([binary_c_config,'libs_list'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
 
 # create list of tuples of defined macros
@@ -19,6 +18,7 @@ binary_c_define_macros = []
 defines = subprocess.run([binary_c_config,'define_macros'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
 lone = re.compile('^-D(.+)$')
 partner = re.compile('^-D(.+)=(.+)$')
+
 for x in defines:
     y = partner.match(x)
     if(y):
@@ -35,15 +35,15 @@ setup(
     name='binary_c',
     version='1.0',
     description='This is a python API for binary_c by Rob Izzard and collaborators',
-    author='Jeff Andrews and Robert Izzard',
-    author_email='andrews@physics.uoc.gr and r.izzard@surrey.ac.uk and rob.izzard@gmail.com',
+    author='Jeff Andrews and Robert Izzard and David Hendriks',
+    author_email='andrews@physics.uoc.gr and r.izzard@surrey.ac.uk and rob.izzard@gmail.com and dhendriks93@gmail.com',
 license='',
     ext_modules=[Extension("binary_c",
                            ["binary_c_python.c"],
-                           libraries = ['binary_c']+binary_c_libs+['binary_c_api'],
-                           include_dirs = [os.environ['BINARY_C']+'/src',os.environ['BINARY_C']+'/src/API']+binary_c_incdirs,
-                           library_dirs = [os.environ['BINARY_C']+'/src', './'] + binary_c_libdirs,
-                           runtime_library_dirs = [os.environ['BINARY_C']+'/src', './']+binary_c_libdirs,
+                           libraries = ['binary_c'] + binary_c_libs + ['binary_c_api'],
+                           include_dirs = [os.environ['BINARY_C'] + '/src', os.environ['BINARY_C'] + '/src/API'] + binary_c_incdirs,
+                           library_dirs = [os.environ['BINARY_C'] + '/src', './'] + binary_c_libdirs,
+                           runtime_library_dirs = [os.environ['BINARY_C']+'/src', './'] + binary_c_libdirs,
                            define_macros = [] + binary_c_define_macros,
                            extra_objects = [],
                            extra_compile_args = [],
diff --git a/examples/__init__.py b/testing_examples/__init__.py
similarity index 100%
rename from examples/__init__.py
rename to testing_examples/__init__.py
diff --git a/examples/example_notebook.ipynb b/testing_examples/example_notebook.ipynb
similarity index 100%
rename from examples/example_notebook.ipynb
rename to testing_examples/example_notebook.ipynb
diff --git a/examples/full_evolution_with_plot.py b/testing_examples/full_evolution_with_plot.py
similarity index 100%
rename from examples/full_evolution_with_plot.py
rename to testing_examples/full_evolution_with_plot.py
diff --git a/examples/log_filename_test.py b/testing_examples/log_filename_test.py
similarity index 100%
rename from examples/log_filename_test.py
rename to testing_examples/log_filename_test.py
diff --git a/examples/loop_system.py b/testing_examples/loop_system.py
similarity index 100%
rename from examples/loop_system.py
rename to testing_examples/loop_system.py
diff --git a/examples/simple_test.py b/testing_examples/simple_test.py
similarity index 100%
rename from examples/simple_test.py
rename to testing_examples/simple_test.py
diff --git a/examples/single_system.py b/testing_examples/single_system.py
similarity index 100%
rename from examples/single_system.py
rename to testing_examples/single_system.py
-- 
GitLab