On 2009-09-04 13:43+0200 Arjen Markus wrote:

> Hi Alan,
>
> I have looked at the locale behaviour with the small program below:
>
> /* chklocale.c --
>        Check the behaviour of the locale - printf() and friends
> */
>
> #include <stdio.h>
> #include <locale.h>
>
> int main( int argc, char *argv[] ) {
>
>     float x = 1.2;
>
>     setlocale(LC_NUMERIC, "");
>
>     printf( "Number: %f\n", x );
>
>     if ( argc > 1 ) {
>         sscanf( argv[1], "%f", &x );
>         printf( "Read: %f\n", x );
>     }
> }
>
> Setting LC_NUMERIC to "nl_NL.UTF-8" gives the following
> results:
>
> > chklocale 1.3
> chklocale 1.3
> Number: 1,200000
> Read: 1,000000
>
> > chklocal 1,3
> chklocale 1.3
> Number: 1,200000
> Read: 1,300000
>
> So indeed - as was to be expected, the comma is used on input and
> output instead of a period. If PLplot's setting of the locale is visible
> outside the PLplot functions, this may give very nasty errors!

Hi Arjen:

I was hoping you would respond to my post since you live in a country
where the decimal separator is a comma rather than period.

However, now I have slept on this idea I don't like my suggested
implementation any more.  I don't think it is a good idea for the PLplot
library to set locale since that might conflict with what is assumed by
libraries or applications that use the PLplot library. (We were the victim
of this ourselves when one form of Qt4 library on OS X set locale without
restoring it to whatever PLplot assumed after it was done.)

My new idea is it is perfectly legitimate for applications such as
examples/c/x01c.c to contain

setlocale(LC_NUMERIC, "");

So I now lean toward making that call as a special option for that example
(implemented the same general way as the xor option for that example).  That
should give those who prefer the comma separator for the axis label a
specific example of how their applications should be set up to do just that.
Note such an example option would also demand the comma separator be used
consistently for user input, e.g., "-fsiz 0,5G" rather than "-fsiz 0.5G" for
specifying PLplot floating point values on the command line, but I think
that is okay since if a user specifically demands comma separators via his
locale, but then fails to use them for his command-line input, he probably
gets what he deserves.  :-)

Demonstrating the possibility of using the user's locale as an option for
example 1 is probably the correct way to show this possibility for PLplot,
but it still leaves the issue of protecting PLplot library file reads (such
as the palette file reads which require a period decimal separator) from
whatever locale other libraries and applications have set.  My reading of
the man page for setlocale indicates we can store the current locale in an
opaque character string using a NULL locale string as an argument, and then
after executing

setlocale(LC_NUMERIC, "C");

to protect the read, we can restore back the original locale using the
opaque character string.  Anyhow, today I will try implementing the example
1 -use_locale option and see whether I can get that to work with my suggested
method of protecting the file reads.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to