gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 1dc0ae07: Installed scripts: LC_NUMERIC=C set


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1dc0ae07: Installed scripts: LC_NUMERIC=C set to prevent commas in floats
Date: Fri, 12 Aug 2022 13:09:14 -0400 (EDT)

branch: master
commit 1dc0ae0758df58c10baf72473a44341408d242ab
Author: Raul Infante-Sainz <infantesainz@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Installed scripts: LC_NUMERIC=C set to prevent commas in floats
    
    Until now, in the installed scripts, 'export LANG=C' was set to prevent
    commas instead of floating points. However, we realized that even with this
    option, there were some situations where commas appeared. This is because
    there are several different local environment variables and depending on
    the particular configuration of the OS they can be different.
    
    For example 'LANG' is the language to print human-text, but 'LC_NUMERIC' is
    the format to print numbers, and they can be different! The relevant one
    for this purpose was is 'LC_NUMERIC'. By setting it to 'C' (for
    programmers), floating points won't be displayed as commas, but programs
    that print human text in the user's default language, will continue to do
    so with on inconvenience for the user.
    
    With this commit, 'export LC_NUMERIC=C' has been replaced with 'export
    LANG=C' at the beginning of all scripts. This fixes situations like
    above. Also, to further make sure that the tests are done in a "clean"
    environment, 'LC_NUMERIC' is also passed as an environment variable to all
    the check scripts.
    
    Finally, to make it easier for people to learn about this problem, the text
    that was previously in a box in the book has been moved to a whole new
    section in the "Common program behavior" chapter.
    
    This issue was found by Teet Kuutma, due to a failure in the 'make check'
    phase.
---
 NEWS                           |   3 ++
 bin/script/ds9-region.in       |   5 +-
 bin/script/fits-view.in        |   5 +-
 bin/script/psf-scale-factor.in |   5 +-
 bin/script/psf-select-stars.in |   5 +-
 bin/script/psf-stamp.in        |   5 +-
 bin/script/psf-subtract.in     |   5 +-
 bin/script/psf-unite.in        |   5 +-
 bin/script/radial-profile.in   |   5 +-
 bin/script/sort-by-night.in    |   5 +-
 doc/announce-acknowledge.txt   |   1 +
 doc/gnuastro.texi              | 103 ++++++++++++++++++++++++++---------------
 tests/Makefile.am              |   1 +
 13 files changed, 97 insertions(+), 56 deletions(-)

diff --git a/NEWS b/NEWS
index dad46f3f..859f5b75 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,9 @@ See the end of the file for license conditions.
   bug #62861: '--printkeynames' of Fits program gets caught in an infinite
               loop on FITS files that have empty keywords before
               'END'. Found by Pedram Ashofteh Ardakani.
+  bug #62892: Installed scripts don't account for differing LANG and
+              LC_NUMERIC. Found by Teet Kuutma and fixed by Raul
+              Infante-Sainz.
 
 
 
diff --git a/bin/script/ds9-region.in b/bin/script/ds9-region.in
index 5f01c662..fa1dd2ca 100644
--- a/bin/script/ds9-region.in
+++ b/bin/script/ds9-region.in
@@ -26,8 +26,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/fits-view.in b/bin/script/fits-view.in
index 43ca333e..e8f20485 100644
--- a/bin/script/fits-view.in
+++ b/bin/script/fits-view.in
@@ -28,8 +28,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/psf-scale-factor.in b/bin/script/psf-scale-factor.in
index 6247b2f8..9056a75c 100644
--- a/bin/script/psf-scale-factor.in
+++ b/bin/script/psf-scale-factor.in
@@ -28,8 +28,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/psf-select-stars.in b/bin/script/psf-select-stars.in
index 2da371db..27d61dfd 100644
--- a/bin/script/psf-select-stars.in
+++ b/bin/script/psf-select-stars.in
@@ -35,8 +35,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/psf-stamp.in b/bin/script/psf-stamp.in
index 0f4ee685..cafbdb00 100644
--- a/bin/script/psf-stamp.in
+++ b/bin/script/psf-stamp.in
@@ -35,8 +35,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/psf-subtract.in b/bin/script/psf-subtract.in
index ab030adc..80955cf6 100644
--- a/bin/script/psf-subtract.in
+++ b/bin/script/psf-subtract.in
@@ -27,8 +27,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/psf-unite.in b/bin/script/psf-unite.in
index 279066d4..117a7144 100644
--- a/bin/script/psf-unite.in
+++ b/bin/script/psf-unite.in
@@ -27,8 +27,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/radial-profile.in b/bin/script/radial-profile.in
index e98d56a5..c4996151 100644
--- a/bin/script/radial-profile.in
+++ b/bin/script/radial-profile.in
@@ -29,8 +29,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/bin/script/sort-by-night.in b/bin/script/sort-by-night.in
index 97f21792..d9ff8620 100644
--- a/bin/script/sort-by-night.in
+++ b/bin/script/sort-by-night.in
@@ -25,8 +25,9 @@
 # Exit the script in the case of failure
 set -e
 
-# To avoid floating points like '23,45' instead of '23.45'.
-export LANG=C
+# 'LC_NUMERIC' is responsible for formatting numbers printed by the OS.  It
+# prevents floating points like '23,45' instead of '23.45'.
+export LC_NUMERIC=C
 
 
 
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 1af2ff7c..e41c7228 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -2,6 +2,7 @@ Alphabetically ordered list to acknowledge in the next release.
 
 Marjan Akbari
 Sepideh Eskandarlou
+Teet Kuutma
 Richard Stallman
 
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 258b85b0..7ba09234 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -375,6 +375,7 @@ Common program behavior
 * Tessellation::                Tile the dataset into non-overlapping bins.
 * Automatic output::            About automatic output names.
 * Output FITS files::           Common properties when outputs are FITS.
+* Numeric locale::              Decimal point printed like 0.5 instead of 0,5.
 
 Command-line
 
@@ -2681,9 +2682,15 @@ This is especially convenient when you just want to make 
a small change to your
 Press the ``up'' key on your keyboard (possibly multiple times) to see your 
previous command(s) and modify them accordingly.
 @end cartouche
 
+@cartouche
+@strong{Your locale doesn't use `.' as decimal separator:} on systems that 
don't use an English language environment, dates, numbers and etc can be 
printed in different formats (for example `0.5' can be written as `0,5').
+With the @code{LC_NUMERIC} line at the start of the script below, we are 
ensuring a unified format in the outupt of @command{seq}.
+For more, please see @ref{Numeric locale}.
+@end cartouche
+
 @example
 ## If your system language uses ',' (not '.') as decimal separator.
-$ export LANG=C
+$ export LC_NUMERIC=C
 
 ## See the general statistics of non-blank pixel values.
 $ aststatistics flat-ir/xdf-f160w.fits
@@ -2748,40 +2755,6 @@ Just like this manual, you can also access GNU AWK's 
manual on the command-line
 Just run @code{info awk}.
 @end cartouche
 
-@cartouche
-@noindent
-@cindex Locale
-@cindex @code{LANG}
-@cindex @code{LC_ALL}
-@cindex Decimal separator
-@cindex Language of command-line
-@strong{Your locale doesn't use `.' as decimal separator:} the input/output of 
some core operating system tools like @command{awk} or @command{seq} depend on 
the @url{https://en.wikipedia.org/wiki/Locale_(computer_software), system 
locale}.
-For example in Spanish and some other languages the decimal separator (symbol 
used to separate the integer and fractional part of a number), is a comma.
-Therefore in systems that have Spanish as their default Locale, @command{seq} 
will print half of unity as `@code{0,5}' (instead of `@code{0.5}').
-This can cause problems for parsing the printed numbers in other programs.
-You can check your current locale with the @code{locale} command.
-You can test your default decimal separator with this command:
-
-@example
-seq 0.5 1
-@end example
-
-To avoid these kinds of locale-specific problems (for example another program 
not being able to read `@code{0,5}' as half of unity), you can change the 
locale by setting the @code{LANG} environment variable (or the 
lower-level/generic @code{LC_ALL}).
-You can do it only for a single command (the first one below), or all commands 
within the running session (the second command below):
-
-@example
-## Change the locale to the standard, only for this 'seq' command.
-$ LANG=C seq 0.5 1
-
-## Change the locale to the standard, for all commands after it.
-$ export LANG=C
-@end example
-
-If you want to change it generally for all future sessions, you can put the 
second command in your shell's startup file.
-For more on startup files, please see @ref{Installation directory}.
-@end cartouche
-
-
 @node Cosmological coverage, Building custom programs with the library, 
Angular coverage on the sky, General program usage tutorial
 @subsection Cosmological coverage
 Having found the angular coverage of the dataset in @ref{Angular coverage on 
the sky}, we can now use Gnuastro to answer a more physically motivated 
question: ``How large is this area at different redshifts?''.
@@ -2791,7 +2764,7 @@ Combined with the field's area that was measured before, 
we can calculate the ta
 
 @example
 ## If your system language uses ',' (not '.') as decimal separator.
-$ export LANG=C
+$ export LC_NUMERIC=C
 
 ## Print general cosmological properties at redshift 2 (for example).
 $ astcosmiccal -z2
@@ -2840,10 +2813,11 @@ $ for z in 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0; do  
      \
 Fortunately, the shell has a useful tool/program to print a sequence of 
numbers that is nicely called @code{seq}.
 You can use it instead of typing all the different redshifts in this example.
 For example the loop below will calculate and print the tangential coverage of 
this field across a larger range of redshifts (0.1 to 5) and with finer 
increments of 0.1.
+For more on the @code{LC_NUMERIC} command, see @ref{Numeric locale}.
 
 @example
 ## If your system language uses ',' (not '.') as decimal separator.
-$ export LANG=C
+$ export LC_NUMERIC=C
 
 ## The loop over the redshifts
 $ for z in $(seq 0.1 0.1 5); do                                  \
@@ -8847,6 +8821,7 @@ When the output is a FITS file, all the programs also 
store some very useful inf
 * Tessellation::                Tile the dataset into non-overlapping bins.
 * Automatic output::            About automatic output names.
 * Output FITS files::           Common properties when outputs are FITS.
+* Numeric locale::              Decimal point printed like 0.5 instead of 0,5.
 @end menu
 
 @node Command-line, Configuration files, Common program behavior, Common 
program behavior
@@ -10828,7 +10803,7 @@ ABC01.jpg ABC02.jpg DEF01_detected.fits
 
 
 
-@node Output FITS files,  , Automatic output, Common program behavior
+@node Output FITS files, Numeric locale, Automatic output, Common program 
behavior
 @section Output FITS files
 
 @cindex FITS
@@ -10927,6 +10902,58 @@ GNUASTRO= '0.7     '           / GNU Astronomy 
Utilities version.
 END
 @end example
 
+@node Numeric locale,  , Output FITS files, Common program behavior
+@section Numeric locale
+
+@cindex Locale
+@cindex @code{LC_ALL}
+@cindex @code{LC_NUMERIC}
+@cindex Decimal separator
+@cindex Language of command-line
+If your @url{https://en.wikipedia.org/wiki/Locale_(computer_software), system 
locale} isn't English, it may happen that the `.' is not used as the decimal 
separator of basic command-line tools for input or output.
+For example in Spanish and some other languages the decimal separator (symbol 
used to separate the integer and fractional part of a number), is a comma.
+Therefore in such systems, some programs may print @mymath{0.5} as as 
`@code{0,5}' (instead of `@code{0.5}').
+This mainly happens in some core operating system tools like @command{awk} or 
@command{seq} depend on the locale.
+This can cause problems for other programs (like those in Gnuastro that expect 
a `@key{.}' as the decimal separator).
+
+To see the effect, please try the commands below.
+The first one will print @mymath{0.5} in your default locale's format.
+The second set will use the Spanish locale for printing numbers (which will 
put a comma between the 0 and the 5).
+The third will use the English (US) locale for printing numbers (which will 
put a point between the 0 and the 5).
+
+@example
+$ seq 0.5 1
+
+$ export LC_NUMERIC=es_ES.utf8
+$ seq 0.5 1
+
+$ export LC_NUMERIC=en_US.utf8
+$ seq 0.5 1
+@end example
+
+@noindent
+With the simple command below, you can check your current locale environment 
variables for specifying the formats of various things like date, time, 
monetary, telephone, numbers and etc.
+You can change any of these, by simply giving different values to the 
respective variable like above.
+For a more complete explanation on each variable, see 
@url{https://www.baeldung.com/linux/locale-environment-variables}.
+
+@example
+$ locale
+@end example
+
+To avoid these kinds of locale-specific problems (for example another program 
not being able to read `@code{0,5}' as half of unity), you can change the 
locale by giving the value of @code{C} to the @code{LC_NUMERIC} environment 
variable (or the lower-level/generic @code{LC_ALL}).
+You will notice that @code{C} is not a human-language and country identifier 
like @code{en_US}, it is the programming locale, which is well recognized by 
programmers in all countries and is available on all Unix-like operating 
systems (others may not be pre-defined and may need installation).
+You can set the @code{LC_NUMERIC} only for a single command (the first one 
below: simply defining the variable in the same line), or all commands within 
the running session (the second command below, or ``exporting'' it to all 
subsequent commands):
+
+@example
+## Change the numeric locale, only for this 'seq' command.
+$ LC_NUMERIC=C seq 0.5 1
+
+## Change the locale to the standard, for all commands after it.
+$ export LC_NUMERIC=C
+@end example
+
+If you want to change it generally for all future sessions, you can put the 
second command in your shell's startup file.
+For more on startup files, please see @ref{Installation directory}.
 
 
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 188992bb..4d9b902a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -229,6 +229,7 @@ script/sort-by-night.sh: mkcatalog/aperturephot.sh.log
 AM_TESTS_ENVIRONMENT = \
 export LANG=C; \
 export AWK=$(AWK); \
+export LC_NUMERIC=C; \
 export mkdir_p="$(MKDIR_P)"; \
 export progbdir=programs-built; \
 export topsrc=$(abs_top_srcdir); \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]