Unidata / UDUNITS-2

API and utility for arithmetic manipulation of units of physical quantities
http://www.unidata.ucar.edu/software/udunits
Other
59 stars 36 forks source link

Different behaviour of unit mapping on Windows for 1-to-1 conversion #110

Closed Enchufa2 closed 2 years ago

Enchufa2 commented 2 years ago

Context: the units package adds support for measurement units to R, and uses udunits2 as the backend. Our users have detected this different behaviour on Windows (see r-quantities/units#301), which can be tracked down to ut_map_unit_to_symbol:

#include <stdio.h>
#include <udunits2/udunits2.h>

int main() {
    ut_set_error_message_handler((ut_error_message_handler) ut_ignore);
    ut_system *sys = ut_read_xml(NULL);
    ut_encoding enc = UT_UTF8;
    ut_set_error_message_handler((ut_error_message_handler) vprintf);

    ut_unit *m = ut_parse(sys, "1 m", enc);
    ut_map_symbol_to_unit("my_metre", enc, m);
    // fails on Windows, works fine on Unix
    ut_map_unit_to_symbol(m, "my_metre", enc);
    // Error: Unit already maps to "m"

    ut_free(m);
    ut_free_system(sys);
    return 0;
}

Apparently, this fails on Windows for "1 m", a 1-to-1 conversion, but not for others, like "2 m".

Enchufa2 commented 2 years ago

The issue may be misidentified after all. Sorry for the noise. I'll reopen if we find further clues.