Skip to content

Changing locale causes network input files reads to fail #875

@AbelHeinsbroek

Description

@AbelHeinsbroek

Hi all,

EPANET uses the strtod stdlib function to parse strings into floats/doubles. The strtod function is locale aware and, depending on the locale setting, uses commas or dots as the decimal separator.

That means that standard input files that use dots as decimal separator fail to open when the locale has been set to something other then the default "C". I've found this to happen when trying to integrate the EPANET toolkit into existing applications that set the locale.

Setting the locale to a language with a comma decimal separator will also result in an output file containing commas instead of dots:

Image

I suggest for EPANET to only support dots as a decimal separator, though I'm unsure on the proper way to do that. One possibility is setting the locale before loading or writing input files, and restoring its setting directly after:

char *old_locale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
// Read input data
ERRCODE(getdata(pr));
setlocale(LC_NUMERIC, old_locale);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions