diff --git a/old_solution/binary_c_api.c b/old_solution/binary_c_api.c deleted file mode 100644 index 2361e2fdae25bd826a8fc9effa65d6d0663d9762..0000000000000000000000000000000000000000 --- a/old_solution/binary_c_api.c +++ /dev/null @@ -1,172 +0,0 @@ -#include "binary_c_python.h" -//#include "binary_c_api.h" -#include "binary_c_API.h" -#include "binary_c_API_prototypes.h" -#include <time.h> -#include <sys/timeb.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - - -/* - * apitest - * - * Short test programme to throw random binary systems at binary_c's - * library via its API. - * - * Note that it looks more complicated than it is because I have included - * code to capture binary_c's stdout stream and output it here. - * - * This code sends output to stderr : you should use apitest.sh to run it - * and hence force output to your terminal's stdout. - * - * Output lines: - * - * APITEST .... is information about what this code is doing. - * STATUS .... is information about the binary system. - * BINARY_C .... is output from binary_c (see iterate_logging.c etc.) - * which would have gone to stdout - * - * If you define the NO_OUTPUT macro, there will be no output except - * the memory allocation and test system information. This is useful for speed tests, - * but note that you may end up in a race condition where the pipe which replaces - * stdout's buffer fills and hence the code stops. - * - * Note: - * I have tested this with gcc 4.7.2 (Ubuntu 12.10) only. - */ - - -// #define _CAPTURE -#ifdef _CAPTURE -static void show_stdout(void); -static void capture_stdout(void); -#endif - - -/* global variables */ -int out_pipe[2]; -int stdoutwas; - -int main(int argc, - char * argv[]) -{ - char * argstring = MALLOC(sizeof(char) * (size_t)STRING_LENGTH); - snprintf(argstring, - STRING_LENGTH, - "binary_c M_1 %g M_2 %g separation %g orbital_period %g metallicity %g max_evolution_time %g\n", - 20.0, - 15.0, - 0.0, - 3.0, - 0.02, - 15000.0); - - char * buffer ; - size_t nbytes; - int out = run_binary(argstring, - &buffer, - &nbytes); - - printf("output (binary_c returned %d)\n%s\n",out,buffer); - - free(buffer); - - return out; -} - - -int run_binary(char * argstring, - char ** buffer, - size_t * nbytes) -{ - /* memory for N binary systems */ - struct libbinary_c_stardata_t *stardata; - struct libbinary_c_store_t * store = NULL; - - printf("argstring : %s\n",argstring); - fflush(stdout); - - stardata = NULL; - binary_c_new_system(&stardata, - NULL, - NULL, - &store, - &argstring, - -1); - snprintf(stardata->preferences->log_filename, - STRING_LENGTH-1, - "%s", - "/dev/null"); - snprintf(stardata->preferences->api_log_filename_prefix, - STRING_LENGTH-1, - "%s", - "/dev/null"); - stardata->preferences->internal_buffering = 2; - stardata->preferences->batchmode = BATCHMODE_LIBRARY; - - binary_c_evolve_for_dt(stardata, - stardata->model.max_evolution_time); - - /* - * Save the buffer pointer - */ - binary_c_buffer_info(stardata,&buffer,nbytes); - - /* - * And free everything else - */ - binary_c_free_memory(&stardata,TRUE,TRUE,FALSE); - binary_c_free_store_contents(store); - - return 0; -} - -int return_arglines(char ** buffer, - size_t * nbytes) -{ - /* memory for N binary systems */ - struct libbinary_c_stardata_t *stardata; - struct libbinary_c_store_t * store = NULL; - - /* make new stardata */ - stardata = NULL; - char * empty_str = ""; - binary_c_new_system(&stardata, - NULL, - NULL, - &store, - &empty_str, - -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; - - /* List available arguments */ - binary_c_list_args(stardata); - - /* 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; -} \ No newline at end of file diff --git a/old_solution/binary_c_api.h b/old_solution/binary_c_api.h deleted file mode 100644 index 950f505aac9f6df0ba55c152c7fc80788f3d8211..0000000000000000000000000000000000000000 --- a/old_solution/binary_c_api.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#ifndef BINARY_C_PYTHON_API_H -#define BINARY_C_PYTHON_API_H - -/* local function prototypes */ -static void APIprintf(char * format,...); - -int run_binary(char * argstring, - char ** buffer, - size_t * nbytes); - -int return_arglines(char ** buffer, - size_t * nbytes); - -/* C macros */ -#define BINARY_C_APITEST_VERSION 0.1 -#define APIprint(...) APIprintf(__VA_ARGS__); -#define NO_OUTPUT - -#endif // BINARY_C_PYTHON_API_H diff --git a/old_solution/binary_c_api_python.h b/old_solution/binary_c_api_python.h deleted file mode 100644 index 950f505aac9f6df0ba55c152c7fc80788f3d8211..0000000000000000000000000000000000000000 --- a/old_solution/binary_c_api_python.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#ifndef BINARY_C_PYTHON_API_H -#define BINARY_C_PYTHON_API_H - -/* local function prototypes */ -static void APIprintf(char * format,...); - -int run_binary(char * argstring, - char ** buffer, - size_t * nbytes); - -int return_arglines(char ** buffer, - size_t * nbytes); - -/* C macros */ -#define BINARY_C_APITEST_VERSION 0.1 -#define APIprint(...) APIprintf(__VA_ARGS__); -#define NO_OUTPUT - -#endif // BINARY_C_PYTHON_API_H diff --git a/old_solution/compile_script.txt b/old_solution/compile_script.txt deleted file mode 100644 index db54dea283afd4f9e9c5c5ec801d0498c51021e2..0000000000000000000000000000000000000000 --- a/old_solution/compile_script.txt +++ /dev/null @@ -1,61 +0,0 @@ -Jeff's instructions - -please see README.md instead! - - ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- - - - - - ----- - -First, we need to compile binary_c_api.c into a shared library. We can do this by either the short way - -make all - -or the long way - -gcc binary_c_api.c -c -lbinary_c -lm -lc -fpic -gcc -shared -o libbinary_c_api.so binary_c_api.o - -#### - -export BINARY_C=... -export LD_LIBRARY_PATY=$BINARY_C/src - -gcc `$BINARY_C/binary_c-config --flags` binary_c_api.c -c - - -#### - -Next, we need to make sure that the current directory (that containing libbinary_c_api.so) is included in $LD_LIBRARY_PATH -export LD_LIBRARY_PATH=.... - - -Next, we compile the python setup.py script: -python setup.py build_ext --inplace - -Within python, you should be able to now run: -python python_API_test.py - - -Or access the python functions within an ipython notebook: -import binary_c -binary_c.function_name() - - -To remake, first, start by running -make clean -