# Autologging # Perl code for autogeneration # 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; # } # Which is used in flexi-grid via this: # $population->set( C_auto_logging => { # 'MY_STELLAR_DATA' => # [ # 'model.time', # 'star[0].mass', # 'model.probability', # 'model.dt' # ] # }); # binary_c_log_code # 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\") # "; # } # 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); # ' # );