gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master a6c51b7 1/4: Table's --column option can now t


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master a6c51b7 1/4: Table's --column option can now take multiple columns
Date: Wed, 21 Mar 2018 15:11:48 -0400 (EDT)

branch: master
commit a6c51b7ae44e8ce441226202e0058affa8712b2f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Table's --column option can now take multiple columns
    
    Until now, when using Table, it was necessary to identify each column with
    a separate call to `--column' (or `-c'). This is annoying! It is now
    possible to give multiple column identifiers (separated by a comma) to a
    single call of this option. Ofcourse, it is still also possible to use
    multiple calls to `column' or mixed: such that each call possibly has
    multiple columns.
---
 NEWS              | 23 ++++++++++++++---------
 bin/table/ui.c    | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 doc/gnuastro.texi | 27 ++++++++++++++++++---------
 3 files changed, 81 insertions(+), 20 deletions(-)

diff --git a/NEWS b/NEWS
index 18fd17f..3fab406 100644
--- a/NEWS
+++ b/NEWS
@@ -49,18 +49,23 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   NoiseChisel:
     --kernel: value `none' will disable convolution.
 
+  Table:
+    --column: multiple columns (comma separated) can be used in one
+              instance of this option (multiple instances of this option
+              are still acceptable also).
+
   Libraries:
-   - `gal_fits_img_read': now only reads the data not the WCS, therefore it
-     no longer needs the last two arguments. A subsequent call to
-     `gal_wcs_read' can be used to read the WCS information in the file.
+    gal_fits_img_read: now only reads the data not the WCS, therefore it no
+        longer needs the last two arguments. A subsequent call to
+        `gal_wcs_read' can be used to read the WCS information in the file.
 
-   - `gal_statistics_quantile_function': returns `inf' or `-inf' if the
-     given value is smaller than the minimum or larger than the maximum of
-     the input dataset's range. Until now, it would return blank in such
-     cases.
+    gal_statistics_quantile_function: returns `inf' or `-inf' if the given
+        value is smaller than the minimum or larger than the maximum of the
+        input dataset's range. Until now, it would return blank in such
+        cases.
 
-   - `gal_statistics_number': the output dataset now has a `size_t'
-     type. Until now it was `uint64_t'.
+    gal_statistics_number: the output dataset now has a `size_t' type. Until
+        now it was `uint64_t'.
 
 ** Bug fixes
 
diff --git a/bin/table/ui.c b/bin/table/ui.c
index 58949e4..a401692 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -262,7 +262,7 @@ ui_check_options_and_arguments(struct tableparams *p)
 /**************************************************************/
 /***************       Preparations         *******************/
 /**************************************************************/
-void
+static void
 ui_print_info_exit(struct tableparams *p)
 {
   char *tmp;
@@ -307,7 +307,51 @@ ui_print_info_exit(struct tableparams *p)
 
 
 
-void
+/* The columns can be given as comma-separated values to one option or
+   multiple calls to the column option. Here, we'll check if the input list
+   has comma-separated values. If they do then the list will be updated to
+   be fully separate. */
+static void
+ui_columns_prepare(struct tableparams *p)
+{
+  size_t i;
+  char **strarr;
+  gal_data_t *strs;
+  gal_list_str_t *tmp, *new=NULL;
+
+  /* Go over the whole original list (where each node may have more than
+     one value separated by a comma. */
+  for(tmp=p->columns;tmp!=NULL;tmp=tmp->next)
+    {
+      /* Read the different comma-separated strings into an array (within a
+         `gal_data_t'). */
+      strs=gal_options_parse_csv_strings_raw(tmp->v, NULL, 0);
+      strarr=strs->array;
+
+      /* Go over all the elements and add them to the `new' list. */
+      for(i=0;i<strs->size;++i)
+        {
+          gal_list_str_add(&new, strarr[i], 0);
+          strarr[i]=NULL;
+        }
+
+      /* Clean up. */
+      gal_data_free(strs);
+    }
+
+  /* Delete the old list. */
+  gal_list_str_free(p->columns, 1);
+
+  /* Reverse the new list, then put it into `p->columns'. */
+  gal_list_str_reverse(&new);
+  p->columns=new;
+}
+
+
+
+
+
+static void
 ui_preparations(struct tableparams *p)
 {
   struct gal_options_common_params *cp=&p->cp;
@@ -317,6 +361,9 @@ ui_preparations(struct tableparams *p)
   if(p->information)
     ui_print_info_exit(p);
 
+  /* Prepare the column names. */
+  ui_columns_prepare(p);
+
   /* Read in the table columns. */
   p->table=gal_table_read(p->filename, cp->hdu, p->columns, cp->searchin,
                           cp->ignorecase, cp->minmapsize, NULL);
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index beeace8..254706b 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -8936,17 +8936,22 @@ One line examples:
 ## Get the table column information (name, data type, or units):
 $ asttable bintab.fits --information
 
-## Only print those columns which have a name starting with "MAG_":
-$ asttable bintab.fits --column=/^MAG_/
+## Print columns named RA and DEC, followed by all the columns where
+## the name starts with "MAG_":
+$ asttable bintab.fits --column=RA --column=DEC --column=/^MAG_/
+
+## Similar to above, but with one call to --column (or -c) and writes
+## the columns to a file (with metadata) instead of the command-line.
+$ asttable bintab.fits -cRA,DEC,/^MAG_/ --output=out.txt
 
 ## Only print the 2nd column, and the third column multiplied by 5:
-$ asttable bintab.fits | awk '@{print $2, address@hidden'
+$ asttable bintab.fits -c2,5 | awk '@{print $1, address@hidden'
 
 ## Only print rows with a value in the 10th column above 100000:
 $ asttable bintab.fits | awk '$10>10e5 @address@hidden'
 
 ## Sort the output columns by the third column, save output:
-$ asttable bintab.fits | 'sort -k3 > output.txt
+$ asttable bintab.fits | 'sort -nk3 > output.txt
 
 ## Convert a plain text table to a binary FITS table:
 $ asttable plaintext.txt --output=table.fits --tabletype=fits-binary
@@ -8997,11 +9002,15 @@ last command with all the previously typed columns 
present, delete
 @cindex GNU AWK
 @item -c STR/INT
 @itemx --column=STR/INT
-Specify the columns to output, see @ref{Selecting table columns} for a
-thorough explanation on how the value to this option is interpreted. To
-select several output columns, this option can also be called any number
-times in one call to Table. The order of the output columns will be the
-same call order on the command-line.
+Specify the columns to read, see @ref{Selecting table columns} for a
+thorough explanation on how the value to this option is interpreted. There
+are two ways to specify multiple columns: 1) multiple calls to this option,
+2) using a comma between each column specifier in one call to this
+option. These different solutions may be mixed in one call to Table: for
+example, @option{-cRA,DEC -cMAG}, or @option{-cRA -cDEC -cMAG} are both
+equivalent to @option{-cRA -cDEC -cMAG}. The order of the output columns
+will be the same order given to the option or in the configuration files
+(see @ref{Configuration file precedence}).
 
 This option is not mandatory, if no specific columns are requested, all the
 input table columns are output. When this option is called multiple times,



reply via email to

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