Skip to content

Commit

Permalink
Fix parsing xml files when running openmc-plotter in regions with com…
Browse files Browse the repository at this point in the history
…ma decimal separator (#2723)

Co-authored-by: ecasglez <emilio.castro@upm.es>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
  • Loading branch information
3 people committed Oct 18, 2023
1 parent bd1c228 commit 7fe80e1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/initialize.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "openmc/initialize.h"

#include <clocale>
#include <cstddef>
#include <cstdlib> // for getenv
#include <cstring>
Expand Down Expand Up @@ -106,10 +107,25 @@ int openmc_init(int argc, char* argv[], const void* intracomm)
// will be re-initialized later
openmc::openmc_set_seed(DEFAULT_SEED);

// Copy previous locale and set locale to C. This is a workaround for an issue
// whereby when openmc_init is called from the plotter, the Qt application
// framework first calls std::setlocale, which affects how pugixml reads
// floating point numbers due to a bug:
// https://github.com/zeux/pugixml/issues/469
std::string prev_locale = std::setlocale(LC_ALL, nullptr);
if (std::setlocale(LC_ALL, "C") == NULL) {
fatal_error("Cannot set locale to C.");
}

// Read XML input files
if (!read_model_xml())
read_separate_xml_files();

// Reset locale to previous state
if (std::setlocale(LC_ALL, prev_locale.c_str()) == NULL) {
fatal_error("Cannot reset locale.");
}

// Write some initial output under the header if needed
initial_output();

Expand Down

0 comments on commit 7fe80e1

Please sign in to comment.