[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);
- [gnuastro-commits] master ff0b76d 018/125: New Data types section in book, bitwise not added, (continued)
- [gnuastro-commits] master ff0b76d 018/125: New Data types section in book, bitwise not added, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c62b01e 031/125: Corrected incrementation issue with and and or operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0a32a82 027/125: Any number of searched columns from FITS are read, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master d0aa78e 005/125: Arithmetic operation on data structures in library, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0ad0906 014/125: Bitwise operators available in arithmetic operations, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 3ad83a4 010/125: data-arithmetic and data-copy separated from data.c, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 6c6382a 013/125: Use of function instead of macros for binary operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ce73959 030/125: Reading FITS keywords into linked list not array, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master e0e8679 017/125: Removed `anyblank' from datastructure, several new operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 6d68470 033/125: Column info format for writing ASCII tables, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0fd75fe 040/125: With no columns, Table program will print all columns,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 8090e6d 038/125: Corrections to FITS table reading, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 1156793 035/125: ASCII table information fully ready for selection, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 3c7773f 037/125: Table library prints ASCII columns with blanks, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 1dca684 047/125: Minor corrections to Gnuastro plain text table format, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 620146e 028/125: Library function for writing columns to txt file, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 9ec7556 039/125: Table's output file type set common sense, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master de80e97 046/125: Further explanations on Gnuastro's plain text tables, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master a5a7c45 048/125: Correction in Gnuastro text table format, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 7b33afa 043/125: FITS ascii and binary table I/O done with tests, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master beeb995 055/125: Corrected options added for make check, Mohammad Akhlaghi, 2017/04/23