gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 5b47d08: Table: the --noblank option can now w


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5b47d08: Table: the --noblank option can now work on all columns
Date: Mon, 1 Feb 2021 07:55:18 -0500 (EST)

branch: master
commit 5b47d082b9abd821a40ff673bb91065df2b9b40c
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Table: the --noblank option can now work on all columns
    
    Until now, if you wanted to use the '--noblank' option on all the columns
    of a table, you had to specify all their names! This was frustrating when
    the table has many columns that should be checked, and could be buggy
    (making a typo in the column names for example).
    
    With this commit, this option now accepts a unique '_all' value. In this
    mode, the user just has to give '--noblank=_all' and all the columns will
    be checked.
---
 NEWS              |   7 ++++
 bin/table/table.c | 122 +++++++++++++++++++++++++++++-------------------------
 doc/gnuastro.texi |  11 +++--
 3 files changed, 80 insertions(+), 60 deletions(-)

diff --git a/NEWS b/NEWS
index dd3b9a5..e194a72 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,13 @@ See the end of the file for license conditions.
 
 ** New features
 
+  Table:
+   - When given a value of '_all', the '--noblank' option (that will remove
+     all rows with a blank value in the given columns) will check all
+     columns of the final output table. This is handy when you want a
+     "clean" (no NaN values in any column) table, but the table has many
+     columns.
+
 ** Removed features
 
 ** Changed features
diff --git a/bin/table/table.c b/bin/table/table.c
index 807d8b6..60bbc2c 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -756,66 +756,74 @@ table_noblank(struct tableparams *p)
   char **strarr=p->noblank->array;
   gal_list_sizet_t *column_indexs=NULL;
 
-  /* Go over the given list of given columns. */
-  for(i=0;i<p->noblank->size;++i)
+  /* See if all columns should be checked, or just a select few. */
+  if( p->noblank->size==1 && !strcmp(strarr[0],"_all") )
     {
-      /* First go through the column names and if they match, add
-         them. Note that we don't want to stop once a name is found, in
-         this scenario, if multiple columns have the same name, we should
-         use all.*/
-      j=0;
-      found=0;
-      for(tcol=p->table; tcol!=NULL; tcol=tcol->next)
-        {
-          if( tcol->name && !strcmp(tcol->name, strarr[i]) )
-            {
-              found=1;
-              gal_list_sizet_add(&column_indexs, j);
-            }
-          ++j;
-        }
-
-      /* If the given string didn't match any column name, it must be a
-         number, so parse it as a number and use that number. */
-      if(found==0)
-        {
-          /* Parse the given index. */
-          index=NULL;
-          if( gal_type_from_string((void **)(&index), strarr[i],
-                                   GAL_TYPE_SIZE_T) )
-            error(EXIT_FAILURE, 0, "column '%s' didn't match any of the "
-                  "final column names and can't be parsed as a column "
-                  "counter (starting from 1) either", strarr[i]);
-
-          /* Make sure its not zero (the user counts from 1). */
-          if(*index==0)
-            error(EXIT_FAILURE, 0, "the column number (given to the "
-                  "'--noblank' option) should start from 1, but you have "
-                  "given 0.");
-
-          /* Make sure that the index falls within the number (note that it
-             still counts from 1).  */
-          if(*index > gal_list_data_number(p->table))
-            error(EXIT_FAILURE, 0, "the final output table only has %zu "
-                  "columns, but you have given column %zu to '--noblank'. "
-                  "Recall that '--noblank' operates on the output columns "
-                  "and that you can also use output column names (if they "
-                  "have any)",
-                  gal_list_data_number(p->table), *index);
-
-          /* Everything is fine, add the index to the list of columns to
-             check. */
-          gal_list_sizet_add(&column_indexs, *index-1);
-
-          /* Clean up. */
-          free(index);
-        }
-
-      /* For a check.
-      printf("%zu\n", column_indexs->v);
-      */
+      for(i=0;i<gal_list_data_number(p->table);++i)
+        gal_list_sizet_add(&column_indexs, i);
     }
 
+  /* Only certain columns should be checked, so find/add their index. */
+  else
+    for(i=0;i<p->noblank->size;++i)
+      {
+        /* First go through the column names and if they match, add
+           them. Note that we don't want to stop once a name is found, in
+           this scenario, if multiple columns have the same name, we should
+           use all.*/
+        j=0;
+        found=0;
+        for(tcol=p->table; tcol!=NULL; tcol=tcol->next)
+          {
+            if( tcol->name && !strcmp(tcol->name, strarr[i]) )
+              {
+                found=1;
+                gal_list_sizet_add(&column_indexs, j);
+              }
+            ++j;
+          }
+
+        /* If the given string didn't match any column name, it must be a
+           number, so parse it as a number and use that number. */
+        if(found==0)
+          {
+            /* Parse the given index. */
+            index=NULL;
+            if( gal_type_from_string((void **)(&index), strarr[i],
+                                     GAL_TYPE_SIZE_T) )
+              error(EXIT_FAILURE, 0, "column '%s' didn't match any of the "
+                    "final column names and can't be parsed as a column "
+                    "counter (starting from 1) either", strarr[i]);
+
+            /* Make sure its not zero (the user counts from 1). */
+            if(*index==0)
+              error(EXIT_FAILURE, 0, "the column number (given to the "
+                    "'--noblank' option) should start from 1, but you have "
+                    "given 0.");
+
+            /* Make sure that the index falls within the number (note that
+               it still counts from 1).  */
+            if(*index > gal_list_data_number(p->table))
+              error(EXIT_FAILURE, 0, "the final output table only has %zu "
+                    "columns, but you have given column %zu to '--noblank'. "
+                    "Recall that '--noblank' operates on the output columns "
+                    "and that you can also use output column names (if they "
+                    "have any)",
+                    gal_list_data_number(p->table), *index);
+
+            /* Everything is fine, add the index to the list of columns to
+               check. */
+            gal_list_sizet_add(&column_indexs, *index-1);
+
+            /* Clean up. */
+            free(index);
+          }
+
+        /* For a check.
+           printf("%zu\n", column_indexs->v);
+        */
+      }
+
   /* Remove all blank rows from the output table, note that we don't need
      the flags of the removed columns here. So we can just free it up. */
   flag=gal_blank_remove_rows(p->table, column_indexs);
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index b9837de..1680de4 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -10496,11 +10496,16 @@ See @option{--head} for more.
 @itemx --noblank=STR[,STR[,STR]]
 Remove all rows in the given @emph{output} columns that have a blank value.
 Like above, the columns can be specified by their name or number (counting 
from 1).
-@code{--noblank} is applied just before writing the final table (after 
@option{--colmetadata} has finished).
-So in case you changed the column metadata, or added new columns, you can use 
the new names, or the newly defined column numbers.
-
 For example if @file{table.fits} has blank values (NaN in floating point 
types) in the @code{magnitude} and @code{sn} columns, with 
@code{--noblank=magnitude,sn}, the output will not contain any rows with blank 
values in these columns.
 
+If you want @emph{all} columns to be checked, simply set the value to 
@code{_all} (in other words: @option{--noblank=_all}).
+This mode is useful when there are many columns in the table and you want a 
``clean'' output table (with no blank values in any column): entering their 
name or number one-by-one can be buggy and frustrating.
+In this mode, no other column name should be given.
+For example if you give @option{--noblank=_all,magnitude}, then Table will 
assume that your table actually has a column named @code{_all} and 
@code{magnitude}, and if it doesn't, it will abort with an error.
+
+This option is applied just before writing the final table (after 
@option{--colmetadata} has finished).
+So in case you changed the column metadata, or added new columns, you can use 
the new names, or the newly defined column numbers.
+
 @item -m STR/INT,STR[,STR[,STR]]
 @itemx --colmetadata=STR/INT,STR[,STR[,STR]]
 Update the specified column metadata in the output table.



reply via email to

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