gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 0fd75fe 040/125: With no columns, Table progra


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 0fd75fe 040/125: With no columns, Table program will print all columns
Date: Sun, 23 Apr 2017 22:36:33 -0400 (EDT)

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

    With no columns, Table program will print all columns
    
    When no columns are selected for Gnuastro's Table program, it will get the
    table information, artifically make a list of all the columns, so the rest
    of the program can be the same as before.
    
    This feature wasn't implemented in the library because it is not a generic
    thing: other programs will also be using the library and when there is no
    columns, it is not acceptable to choose everything.
---
 bin/table/ui.c    | 26 ++++++++++++++++++++++++++
 doc/gnuastro.texi | 42 ++++++++++++++++++++++--------------------
 lib/table.c       |  9 ++++-----
 3 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/bin/table/ui.c b/bin/table/ui.c
index 3357c56..4464efa 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -373,6 +373,32 @@ print_information_exit(struct tableparams *p)
 void
 preparearrays(struct tableparams *p)
 {
+  char *numstr;
+  int tabletype;
+  gal_data_t *allcols;
+  size_t i, numcols, numrows;
+
+  /* If there were no columns specified, we want the full set of
+     columns. */
+  if(p->columns==NULL)
+    {
+      /* Read the table information for the number of columns and rows. */
+      allcols=gal_table_info(p->up.filename, p->cp.hdu, &numcols,
+                             &numrows, &tabletype);
+
+      /* Free the information from all the columns. */
+      for(i=0;i<numcols;++i)
+        gal_data_free(&allcols[i], 1);
+      free(allcols);
+
+      /* Add the number of columns to the list. */
+      for(i=1;i<=numcols;++i)
+        {
+          asprintf(&numstr, "%zu", i);
+          gal_linkedlist_add_to_stll(&p->columns, numstr);
+        }
+    }
+
   /* Reverse the list of column search criteria that we are looking for
      (since this is a last-in-first-out linked list, the order that
      elements were added to the list is the reverse of the order that they
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 32f4e13..bf5fd2c 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -6267,11 +6267,11 @@ some very simple examples.
 @node Invoking asttable,  , Table, Table
 @subsection Invoking Table
 
-Table will convert FITS binary and ASCII tables into other such tables, or
-print them on the command-line, or save them in a plain text file. Output
-columns can also be determined by number or regular expression matching of
-column names. The executable name is @file{asttable} with the following
-general template
+Table will read/wwrite, select, convert, or show the information of the
+columns in FITS ASCII table, FITS binary table and plain text table
+files. Output columns can also be determined by number or regular
+expression matching of column names. The executable name is @file{asttable}
+with the following general template
 
 @example
 $ asttable [OPTION...] InputFile
@@ -6285,7 +6285,7 @@ One line examples:
 $ asttable bintab.fits --information
 
 ## Only print those columns which have a name starting with "MAG_"
-$ asttable bintab.fits --columns=/^MAG_/
+$ asttable bintab.fits --column=/^MAG_/
 
 ## Only print the 2nd column, and the third column multiplied by 5
 $ asttable bintab.fits | awk '@{print $2, address@hidden'
@@ -6300,14 +6300,12 @@ $ asttable bintab.fits | sort -k3 > output.txt
 $ asttable plaintext.txt --output=inbinary.fits
 @end example
 
-Table can accept plain text files, or binary and ASCII FITS table
-extensions in a FITS file. For the full list of options common to all
-Gnuastro utilities please see @ref{Common options}. Options can also be
-stored in directory, user or system-wide configuration files to avoid
-repeating on the command-line, see @ref{Configuration files}. Currently all
-plain text files are processed (and thus printed, or saved to a binary FITS
-table) as double floating point types. We are still working on this many
-many more features.
+In the absence of an output file, the selected columns will be printed on
+the command-line. In the absence of selected columns, all columns will be
+output. For the full list of options common to all Gnuastro utilities
+please see @ref{Common options}. Options can also be stored in directory,
+user or system-wide configuration files to avoid repeating on the
+command-line, see @ref{Configuration files}.
 
 Table does not follow Automatic output that is common in most Gnuastro, see
 @ref{Automatic output}. If no value is given to the @option{--output}
@@ -6334,12 +6332,13 @@ mandatory.
 @itemx --column
 (@option{=STR} or @option{=INT}) Specify the columns to output for this
 table. If the value to this option is an integer number, the column number
-will be used (counting from 1, Table will abort with an error if negative
-values are given). When the value isn't a number, the value's string of
-characters will be used to match one of the pieces of information for the
-columns. See the @option{--searchin} option description for more on where
-the matching/searching will take place. The matching will be done following
-this convention (similar to AWK):
+will be used (counting from 1, Table will abort with an error if zero or
+negative values are given). When the value can't be interpretted as an a
+integer number, the value's string of characters will be used to match one
+of the pieces of information for the columns. See the @option{--searchin}
+option description for more on where the matching/searching will take
+place. The matching will be done following this convention (similar to
+AWK):
 
 @itemize
 @item
@@ -6370,6 +6369,9 @@ specific columns are requested, all the input table 
columns are
 output. When this option is called multiple times, it is possible to output
 one column more than once.
 
+Specifying a column isn't mandatory, if no column is specified all the
+table columns will be chosen.
+
 @item -s
 @itemx --searchin
 Where to match/search for columns (if the value to @option{--column} wasn't
diff --git a/lib/table.c b/lib/table.c
index d12cdaa..23e4343 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -424,6 +424,9 @@ gal_table_read(char *filename, char *hdu, struct 
gal_linkedlist_stll *cols,
   gal_data_t *allcols, *out=NULL;
   struct gal_linkedlist_sll *indexll;
 
+  /* If the column string linked list is empty, no need to continue. */
+  if(cols==NULL) return NULL;
+
   /* First get the information of all the columns. */
   allcols=gal_table_info(filename, hdu, &numcols, &numrows, &tabletype);
 
@@ -464,11 +467,7 @@ gal_table_read(char *filename, char *hdu, struct 
gal_linkedlist_stll *cols,
 
   /* Clean up. */
   for(i=0;i<numcols;++i)
-    {
-      allcols[i].wcs=NULL;
-      allcols[i].mmapname=NULL;
-      gal_data_free(&allcols[i], 1);
-    }
+    gal_data_free(&allcols[i], 1);
   free(allcols);
   gal_linkedlist_free_sll(indexll);
 



reply via email to

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