gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 94cb19ce: Table: new --txteasy option to simpl


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 94cb19ce: Table: new --txteasy option to simply plain-text outputs
Date: Sun, 18 Dec 2022 20:42:51 -0500 (EST)

branch: master
commit 94cb19ceaf57903b0f187dd71a51d2bed044466a
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Table: new --txteasy option to simply plain-text outputs
    
    Until now, when you wanted human-friendly plain-text outputs of floating
    point columns (32-bit or 64-bit), you should have used '-Afixed -B6 -ffixed
    -p3' which is annoying to write and can be buggy!
    
    With this commit, the new '--txteasy' (or '-Y') option has been added to
    table to simplify such cases.
---
 NEWS              | 10 ++++++++++
 bin/table/args.h  | 13 +++++++++++++
 bin/table/main.h  |  1 +
 bin/table/ui.c    | 11 +++++++++++
 bin/table/ui.h    |  3 ++-
 doc/gnuastro.texi |  7 +++++++
 6 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 9f71ce66..db24a44e 100644
--- a/NEWS
+++ b/NEWS
@@ -81,6 +81,16 @@ See the end of the file for license conditions.
    --outliernumngb: see description of same option in NoiseChisel.
 
    Table:
+   --txteasy: (or '-Y') when output is a plain-text file or just gets
+     printed on standard output (terminal), all floating point columns are
+     printed in fixed point notation (as in '123.456') instead of the
+     default exponential notation (as in '1.23456e+02'). For 32-bit
+     floating points, use a precision of 3 digits and for 64-bit floating
+     points use a precision of 6 digits. This can be useful for human
+     readability, but be careful with some scenarios (for example
+     '1.23e-120', which will show only as '0.0'!). For more, see the
+     changes in Table in this version.
+
    - New column arithmetic operator:
      - sorted-to-interval: return two columns from a single (sorted) input,
        containing the minimum and maximum values of an interval. The
diff --git a/bin/table/args.h b/bin/table/args.h
index 0b8e48c8..796220b3 100644
--- a/bin/table/args.h
+++ b/bin/table/args.h
@@ -194,6 +194,19 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET,
       gal_options_parse_name_and_strings
     },
+    {
+      "txteasy",
+      UI_KEY_TXTEASY,
+      0,
+      0,
+      "Short for '-Afixed -B6 -ffixed -p3'.",
+      GAL_OPTIONS_GROUP_OUTPUT,
+      &p->txteasy,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
     {
       "txtf32format",
       UI_KEY_TXTF32FORMAT,
diff --git a/bin/table/main.h b/bin/table/main.h
index c2a02826..cdd504fe 100644
--- a/bin/table/main.h
+++ b/bin/table/main.h
@@ -122,6 +122,7 @@ struct tableparams
   gal_list_str_t  *catrowfile;  /* Filename to concat column wise.      */
   gal_list_str_t   *catrowhdu;  /* HDU/extension for the catcolumn.     */
   gal_data_t     *colmetadata;  /* Set column metadata.                 */
+  uint8_t             txteasy;  /* Easy/simple to ready txt output.     */
   char          *txtf32fmtstr;  /* Floating point formats (exp, flt).   */
   char          *txtf64fmtstr;  /* Floating point formats (exp, flt).   */
   int         txtf32precision;  /* Precision of float32 in text.        */
diff --git a/bin/table/ui.c b/bin/table/ui.c
index c4faea03..25e29ad6 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -361,6 +361,17 @@ ui_read_check_only_options(struct tableparams *p)
               "'--txtf64format'. Recognized values are 'fixed' and "
               "'exp'", p->txtf64fmtstr);
     }
+
+  /* If the user wants easy-to-read text output (this should over-write the
+     existing values in the command-line or in configuration
+     files). Because default values exist in the configuration files. */
+  if(p->txteasy)
+    {
+      p->txtf32precision=3;
+      p->txtf64precision=6;
+      p->txtf32format=GAL_TABLE_DISPLAY_FMT_FIXED;
+      p->txtf64format=GAL_TABLE_DISPLAY_FMT_FIXED;
+    }
 }
 
 
diff --git a/bin/table/ui.h b/bin/table/ui.h
index 5c273b61..b2555d9b 100644
--- a/bin/table/ui.h
+++ b/bin/table/ui.h
@@ -42,7 +42,7 @@ enum program_args_groups
 /* Available letters for short options:
 
    a g j k l t v x y z
-   G J Q Y
+   G J Q
 */
 enum option_keys_enum
 {
@@ -67,6 +67,7 @@ enum option_keys_enum
   UI_KEY_CATROWFILE      = 'R',
   UI_KEY_CATROWHDU       = 'X',
   UI_KEY_COLMETADATA     = 'm',
+  UI_KEY_TXTEASY         = 'Y',
   UI_KEY_TXTF32FORMAT    = 'f',
   UI_KEY_TXTF64FORMAT    = 'A',
   UI_KEY_TXTF32PRECISION = 'p',
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index cdebbc51..dc507038 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -15031,6 +15031,13 @@ Since we only have an integer number of digits in a 
number, we'll round it to 16
 Furthermore, the precision is only defined to the right side of the decimal 
point.
 In exponential notation (default of @option{--txtf64format}), one decimal 
digit will be printed on the left of the decimal point.
 So the default value to this option is @mymath{16-1=15}.
+
+@item -Y
+@itemx --txteasy
+When output is a plain-text file or just gets printed on standard output (the 
terminal), all floating point columns are printed in fixed point notation (as 
in @code{123.456}) instead of the default exponential notation (as in 
@code{1.23456e+02}).
+For 32-bit floating points, this option will use a precision of 3 digits (see 
@option{--txtf32precision}) and for 64-bit floating points use a precision of 6 
digits (see @option{--txtf64precision}).
+This can be useful for human readability, but be careful with some scenarios 
(for example @code{1.23e-120}, which will show only as @code{0.0}!).
+When this option is called any value given the following options is ignored: 
@option{--txtf32format}, @option{--txtf32precision}, @option{--txtf64format} 
and @option{--txtf64precision}.
 @end table
 
 



reply via email to

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