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

busy with a second repo to test stuff

parent 32de636e
No related branches found
No related tags found
No related merge requests found
...@@ -17,10 +17,21 @@ We can do that with providing a logging string alltogether, or generate a loggin ...@@ -17,10 +17,21 @@ We can do that with providing a logging string alltogether, or generate a loggin
In either way, this should be passed to stardata->preferences->custom_output_function as a pointer to that function In either way, this should be passed to stardata->preferences->custom_output_function as a pointer to that function
*** Provide string for logging *** Provide string for logging
In perl this is done in the following way: 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 sub binary_c_log_code
{ {
my ($code) = @_; my ($code) = @_;
...@@ -56,22 +67,13 @@ void custom_output_function(SV * x) ...@@ -56,22 +67,13 @@ void custom_output_function(SV * x)
"; ";
} }
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);
'
);
Or use it via: Or use it via:
*** auto logging *** auto logging
We should also try to be able to have the code autogenerate some logging function via the following: 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 => { $population->set( C_auto_logging => {
'MY_STELLAR_DATA' => 'MY_STELLAR_DATA' =>
[ [
...@@ -82,7 +84,7 @@ $population->set( C_auto_logging => { ...@@ -82,7 +84,7 @@ $population->set( C_auto_logging => {
] ]
}); });
**** code to handle that input
Which is handled in perl via (see binary_grid2.pm Which is handled in perl via (see binary_grid2.pm
sub autogen_C_logging_code sub autogen_C_logging_code
{ {
...@@ -122,8 +124,8 @@ sub autogen_C_logging_code ...@@ -122,8 +124,8 @@ sub autogen_C_logging_code
*** DONE Make function in python that puts code into c function
*** TODO 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 *** DONE Make function in python that generates c-function from a list of arguments
CLOSED: [2019-10-29 Tue 23:52] CLOSED: [2019-10-29 Tue 23:52]
*** TODO Resolve current issue malloc *** TODO Resolve current issue malloc
...@@ -135,6 +137,11 @@ ImportError: /home/david/projects/binary_c_root/binary_c-python/libbinary_c_api. ...@@ -135,6 +137,11 @@ ImportError: /home/david/projects/binary_c_root/binary_c-python/libbinary_c_api.
I get this error when I am using the master version of binary_c with either branches of the python wrapper I get this error when I am using the master version of binary_c with either branches of the python wrapper
*** TODO Make sure this works with the last major release of binaryc
*** TODO Finish testing a simpler case (see other repo)
** General: ** General:
*** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?) *** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?)
CLOSED: [2019-10-29 Tue 17:44] CLOSED: [2019-10-29 Tue 17:44]
......
# Autologging # Autologging
# Perl code for autogeneration # Perl code for autogeneration
# sub autogen_C_logging_code sub autogen_C_logging_code
# { {
# # given a hash of arrays of variable names, where the hash # given a hash of arrays of variable names, where the hash
# # key is the header, autogenerate PRINTF statements # key is the header, autogenerate PRINTF statements
# my ($self) = @_; my ($self) = @_;
# my $code = undef; my $code = undef;
# if(defined $self->{_grid_options}->{C_auto_logging} && if(defined $self->{_grid_options}->{C_auto_logging} &&
# ref $self->{_grid_options}->{C_auto_logging} eq 'HASH' ref $self->{_grid_options}->{C_auto_logging} eq 'HASH'
# ) )
# { {
# $code = ''; $code = '';
# foreach my $header (keys %{$self->{_grid_options}->{C_auto_logging}}) foreach my $header (keys %{$self->{_grid_options}->{C_auto_logging}})
# { {
# if(ref $self->{_grid_options}->{C_auto_logging}->{$header} eq 'ARRAY') if(ref $self->{_grid_options}->{C_auto_logging}->{$header} eq 'ARRAY')
# { {
# $code .= 'PRINTF("'.$header.' '; $code .= 'PRINTF("'.$header.' ';
# foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}}) foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
# { {
# $code .= '%g '; $code .= '%g ';
# } }
# $code .= '\n"'; $code .= '\n"';
# foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}}) foreach my $x (@{$self->{_grid_options}->{C_auto_logging}->{$header}})
# { {
# $code .= ',((double)stardata->'.$x.')'; $code .= ',((double)stardata->'.$x.')';
# } }
# $code .= ');' $code .= ');'
# } }
# } }
# } }
# print "MADE AUTO CODE \n\n************************************************************\n\n$code\n\n************************************************************\n"; print "MADE AUTO CODE \n\n************************************************************\n\n$code\n\n************************************************************\n";
# return $code; return $code;
# } }
# Which is used in flexi-grid via this: Which is used in flexi-grid via this:
# $population->set( C_auto_logging => { $population->set( C_auto_logging => {
# 'MY_STELLAR_DATA' => 'MY_STELLAR_DATA' =>
# [ [
# 'model.time', 'model.time',
# 'star[0].mass', 'star[0].mass',
# 'model.probability', 'model.probability',
# 'model.dt' 'model.dt'
# ] ]
# }); });
# binary_c_log_code # binary_c_log_code
# sub binary_c_log_code sub binary_c_log_code
# { {
# my ($code) = @_; my ($code) = @_;
# return " return "
# #pragma push_macro(\"MAX\") #pragma push_macro(\"MAX\")
# #pragma push_macro(\"MIN\") #pragma push_macro(\"MIN\")
# #undef MAX #undef MAX
# #undef MIN #undef MIN
# #include \"binary_c.h\" #include \"binary_c.h\"
# void custom_output_function(SV * x); void custom_output_function(SV * x);
# SV * custom_output_function_pointer(void); SV * custom_output_function_pointer(void);
# SV * custom_output_function_pointer() SV * custom_output_function_pointer()
# { {
# /* /*
# * use PTR2UV to convert the function pointer * use PTR2UV to convert the function pointer
# * &custom_output_function to an unsigned int, * &custom_output_function to an unsigned int,
# * which is then converted to a Perl SV * which is then converted to a Perl SV
# */ */
# return (SV*)newSVuv(PTR2UV(&custom_output_function)); return (SV*)newSVuv(PTR2UV(&custom_output_function));
# } }
# void custom_output_function(SV * x) void custom_output_function(SV * x)
# { {
# struct stardata_t * stardata = (struct stardata_t *)x; struct stardata_t * stardata = (struct stardata_t *)x;
# $code; $code;
# } }
# #undef MAX #undef MAX
# #undef MIN #undef MIN
# #pragma pop_macro(\"MIN\") #pragma pop_macro(\"MIN\")
# #pragma pop_macro(\"MAX\") #pragma pop_macro(\"MAX\")
# "; ";
# } }
# And then to use it via And then to use it via
# $population->set( $population->set(
# C_logging_code => ' C_logging_code => '
# PRINTF("MY_STELLAR_DATA %g %g %g %g\n", PRINTF("MY_STELLAR_DATA %g %g %g %g\n",
# stardata->model.time, stardata->model.time,
# stardata->star[0].mass, stardata->star[0].mass,
# stardata->model.probability, stardata->model.probability,
# stardata->model.dt); stardata->model.dt);
# ' '
# ); );
import textwrap import textwrap
# Functions for the automatic logging of stuff # Functions for the automatic logging of stuff
# https://stackoverflow.com/questions/41954269/create-c-function-pointers-structure-in-python
# https://stackabuse.com/enhancing-python-with-custom-c-extensions/ Read
# https://stackoverflow.com/questions/49941617/runtime-generation-and-compilation-of-cython-functions
# https://realpython.com/cpython-source-code-guide/
# https://docs.python.org/3.6/c-api/index.html
# https://stackoverflow.com/questions/6626167/build-a-pyobject-from-a-c-function
# https://docs.python.org/3.6/extending/newtypes_tutorial.html?highlight=pointer
# https://realpython.com/cpython-source-code-guide/
# https://diseraluca.github.io/blog/2019/03/21/wetting-feet-with-python-c-api
# https://docs.python.org/3/c-api/function.html
# See example_perl.pm autologging # See example_perl.pm autologging
def autogen_C_logging_code(logging_dict): def autogen_C_logging_code(logging_dict):
......
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