Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ IF (NOT WIN32)
target_link_libraries (dedx_use_wrappers m)
ENDIF()

# some of the examples need data/ folder in the same location as generated executable
add_custom_command(TARGET dedx_example PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/libdedx/data $<TARGET_FILE_DIR:dedx_example>/data)

install (TARGETS getdedx DESTINATION bin)
20 changes: 17 additions & 3 deletions examples/dedx_use_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ int main() {
int err = 0;
float energies[10];
float results[10];
int program = DEDX_BETHE_EXT00;
int ion = DEDX_HYDROGEN;
int target = DEDX_WATER_LIQUID;
const int program = DEDX_PSTAR;
const int ion = DEDX_HYDROGEN;
const int target = DEDX_WATER_LIQUID;

int no_of_samples;

no_of_samples = dedx_get_stp_table_size(program, ion, target);
printf("No of data samples %d\n", no_of_samples);

float *default_energies = calloc(sizeof(float), no_of_samples);
float *default_stps = calloc(sizeof(float), no_of_samples);

dedx_fill_default_energy_stp_table(program, ion, target, default_energies, default_stps);

free(default_energies);
free(default_stps);

int no_of_points = 10;
for (int i = 0; i < no_of_points; i++) {
energies[i] = 1.f + i * 1.1f;
Expand Down
2 changes: 1 addition & 1 deletion libdedx/dedx.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ float dedx_get_stp(dedx_workspace * ws, dedx_config * config, float energy, int
{
int id = config->cfg_id;
*err = 0;
//Check that the energy is inside the boundery
//Check that the energy is within the boundary
if((*err = _dedx_check_energy_bounds(ws->loaded_data[id],energy)) != 0)
return 0;
if(id > ws->active_datasets) //Check that the dataset is loaded.
Expand Down
65 changes: 64 additions & 1 deletion libdedx/dedx_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,67 @@ float dedx_get_simple_stp_for_program(const int program, const int ion, const in
dedx_free_config(config, err);
dedx_free_workspace(ws, err);
return stp;
}
}

int dedx_get_stp_table_size(const int program, const int ion, const int target) {
int err = 0;
int result = -1;

dedx_workspace *ws;
dedx_config *cfg = (dedx_config *) calloc(1, sizeof(dedx_config));
ws = dedx_allocate_workspace(1, &err);

// set program + ion + target combination
cfg->program = program;
cfg->ion = ion;
cfg->target = target;

// load spline database from the data files, it contains number of energy+stp samples
dedx_load_config(ws, cfg, &err);

// config loading failed, returning exit code
if (err != 0)
return -1;

// assume only one dataset is loaded, extract number of samples
if (ws->datasets == 1) {
result = ws->loaded_data[0]->n;
}

return result;
};

int
dedx_fill_default_energy_stp_table(const int program, const int ion, const int target, float *energies, float *stps) {
int err = 0;
int i;

dedx_workspace *ws;
dedx_config *cfg = (dedx_config *) calloc(1, sizeof(dedx_config));
ws = dedx_allocate_workspace(1, &err);

// set program + ion + target combination
cfg->program = program;
cfg->ion = ion;
cfg->target = target;

// load spline database from the data files
dedx_load_config(ws, cfg, &err);

// config loading failed, returning exit code
if (err != 0)
return -1;

// assume only one dataset is loaded, extract default no of energies and stopping powers
if (ws->datasets == 1) {
for (i = 0; i < ws->loaded_data[0]->n; i++) {
energies[i] = ws->loaded_data[0]->base[i].x;
stps[i] = dedx_get_stp(ws, cfg, energies[i], &err);
if (err != 0)
return -1;
}
}

return 0;

};
5 changes: 5 additions & 0 deletions libdedx/dedx_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DEDX_WRAPPERS_INCLUDED

#include <stdlib.h>
#include <stdio.h>
#include "dedx.h"

void dedx_fill_program_list(int *program_list);
Expand All @@ -15,4 +16,8 @@ int dedx_get_stp_table(const int program, const int ion, const int target, const

float dedx_get_simple_stp_for_program(const int program, const int ion, const int target, float energy, int *err);

int dedx_get_stp_table_size(const int program, const int ion, const int target);

int dedx_fill_default_energy_stp_table(const int program, const int ion, const int target, float *energies, float *stps);

#endif //DEDX_WRAPPERS_INCLUDED