mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Fix parsing xml files when running openmc-plotter in regions with comma decimal separator (#2723)
Co-authored-by: ecasglez <emilio.castro@upm.es> Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
bd1c2286f8
commit
7fe80e1490
1 changed files with 16 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "openmc/initialize.h"
|
||||
|
||||
#include <clocale>
|
||||
#include <cstddef>
|
||||
#include <cstdlib> // for getenv
|
||||
#include <cstring>
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue