Skip to content

Commit

Permalink
Use of wrong variable (sim->ion.isotope) instead of sim->beam_isotope…
Browse files Browse the repository at this point in the history
… caused crashes if no simulation hadn't been run before exporting simulation to an IDF file.
  • Loading branch information
jaakkojulin committed Oct 5, 2023
1 parent 84ab299 commit ac64860
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/simulation2idf.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ int simulation2idf(const struct fit_data *fit, const char *filename) {
fprintf(f, "%s", (char *) xmlbuff);
fclose(f);
xmlFreeDoc(doc);
jabs_message(MSG_WARNING, "Saving simulations to IDF files support is incomplete, output file was created but it might not work as intended.");
return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -144,7 +143,7 @@ xmlNodePtr simulation2idf_structure(const sample_model *sm) {
}

xmlNodePtr simulation2idf_spectra(const struct fit_data *fit) {
if(!fit || !fit->sim) {
if(!fit || !fit->sim || !fit->sim->beam_isotope) {
return NULL;
}
xmlNodePtr spectra = xmlNewNode(NULL, BAD_CAST "spectra");
Expand Down Expand Up @@ -173,9 +172,9 @@ xmlNodePtr simulation2idf_spectra(const struct fit_data *fit) {

xmlNodePtr simulation2idf_beam(const simulation *sim) {
xmlNodePtr beam = xmlNewNode(NULL, BAD_CAST "beam");
xmlAddChild(beam, idf_new_node_printf(BAD_CAST "beamparticle", "%s", sim->ion.isotope->name));
xmlAddChild(beam, idf_new_node_printf(BAD_CAST "beamZ", "%i", sim->ion.Z));
xmlAddChild(beam, idf_new_node_units(BAD_CAST "beammass", BAD_CAST IDF_UNIT_AMU, NULL, sim->ion.isotope->mass));
xmlAddChild(beam, idf_new_node_printf(BAD_CAST "beamparticle", "%s", sim->beam_isotope->name));
xmlAddChild(beam, idf_new_node_printf(BAD_CAST "beamZ", "%i", sim->beam_isotope->Z));
xmlAddChild(beam, idf_new_node_units(BAD_CAST "beammass", BAD_CAST IDF_UNIT_AMU, NULL, sim->beam_isotope->mass));
xmlAddChild(beam, idf_new_node_units(BAD_CAST "beamenergy", BAD_CAST IDF_UNIT_KEV, NULL, sim->beam_E));
xmlAddChild(beam, idf_new_node_units(BAD_CAST "beamenergyspread", BAD_CAST IDF_UNIT_KEV, BAD_CAST IDF_MODE_FWHM, sim->beam_E_broad));
xmlAddChild(beam, idf_new_node_units(BAD_CAST "beamfluence", BAD_CAST IDF_UNIT_PARTICLES, NULL, sim->fluence));
Expand Down

0 comments on commit ac64860

Please sign in to comment.