gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master aa0aca7 2/2: Table: enable multiple calls to -


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master aa0aca7 2/2: Table: enable multiple calls to --catcolumn
Date: Sun, 22 Mar 2020 11:06:12 -0400 (EDT)

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

    Table: enable multiple calls to --catcolumn
    
    Until now, only a single file could be column-concatenated with the
    `--catcolumn' option. With this commit, this option has been defined as a
    list, enabling multiple files to be concatenated with one command.
    
    Also, the `catcolumn' and `catcolhdu' option definitions in `args.h' are
    now placed after the previous input option defintions (when the order
    doesn't matter, its better to keep the older ones first, for the users its
    irrelevant).
---
 NEWS                    |  2 ++
 bin/table/args.h        | 52 ++++++++++++++++++------------------
 bin/table/asttable.conf |  3 ++-
 bin/table/main.h        |  4 +--
 bin/table/table.c       | 71 ++++++++++++++++++++++++++++++++++++++-----------
 doc/gnuastro.texi       | 20 +++++++-------
 6 files changed, 98 insertions(+), 54 deletions(-)

diff --git a/NEWS b/NEWS
index 846761a..582145a 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,8 @@ See the end of the file for license conditions.
   Table:
    --equal: Can now work on columns with string type also.
    --notequal: Can now work on columns with string type also.
+   --catcolumn: Concatenate tables by column (keeping number of rows fixed).
+   --catcolhdu: Specify the HDU/extension of the FITS files of --catcolumn.
    - New `quantile' operator in column arithmetic.
 
   Library:
diff --git a/bin/table/args.h b/bin/table/args.h
index dfceb42..e11cc5f 100644
--- a/bin/table/args.h
+++ b/bin/table/args.h
@@ -32,32 +32,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 struct argp_option program_options[] =
   {
     {
-      "catcolumn",
-      UI_KEY_CATCOLUMN,
-      "STR",
-      0,
-      "Name of files to be concat column",
-      GAL_OPTIONS_GROUP_INPUT,
-      &p->catcolumn,
-      GAL_TYPE_STRING,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET
-    },
-     {
-      "catcolhdu",
-      UI_KEY_CATCOLHDU,
-      "STR/INT",
-      0,
-      "Image extension for the calcolmn file",
-      GAL_OPTIONS_GROUP_INPUT,
-      &p->catcolhdu,
-      GAL_TYPE_STRING,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET
-    },
-    {
       "column",
       UI_KEY_COLUMN,
       "STR",
@@ -96,6 +70,32 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
     },
+    {
+      "catcolumn",
+      UI_KEY_CATCOLUMN,
+      "STR",
+      0,
+      "Name of files to be concat column",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->catcolumn,
+      GAL_TYPE_STRLL,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+    {
+      "catcolhdu",
+      UI_KEY_CATCOLHDU,
+      "STR/INT",
+      0,
+      "HDU/Extension(s) for the calcolmn files.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->catcolhdu,
+      GAL_TYPE_STRLL,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
 
 
 
diff --git a/bin/table/asttable.conf b/bin/table/asttable.conf
index 4143cd2..2d75cfd 100644
--- a/bin/table/asttable.conf
+++ b/bin/table/asttable.conf
@@ -20,4 +20,5 @@
 # warranty.
 
 # Inputs
- wcshdu        1
\ No newline at end of file
+ wcshdu        1
+ catcolhdu     1
\ No newline at end of file
diff --git a/bin/table/main.h b/bin/table/main.h
index 1f79c46..b1444e2 100644
--- a/bin/table/main.h
+++ b/bin/table/main.h
@@ -95,8 +95,8 @@ struct tableparams
   uint8_t          descending;  /* Sort columns in descending order.    */
   size_t                 head;  /* Output only the no. of top rows.     */
   size_t                 tail;  /* Output only the no. of bottom rows.  */
-  char             *catcolumn;  /* Filename to concat column wise       */
-  char             *catcolhdu;  /* Image extension for the catcolumnfile*/
+  gal_list_str_t   *catcolumn;  /* Filename to concat column wise.      */
+  gal_list_str_t   *catcolhdu;  /* HDU/extension for the catcolumn.     */
 
   /* Internal. */
   struct column_pack *outcols;  /* Output column packages.              */
diff --git a/bin/table/table.c b/bin/table/table.c
index b6a80b2..92e17a2 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -517,31 +517,71 @@ table_head_tail(struct tableparams *p)
     }
 }
 
+
+
+
+
 /*This function concatenates two table column wise .
  It  attaches catcolumn table at the back of first table */
 static void
 table_catcolumn(struct tableparams *p)
 {
-  gal_data_t *column_table, *final;
+  char *hdu;
+  gal_data_t *tocat, *final;
+  gal_list_str_t *filell, *hdull;
   struct gal_options_common_params *cp=&p->cp;
 
-  /* Reading the catcolumn table. */
-  column_table=gal_table_read(p->catcolumn, p->catcolhdu, NULL, p->columns,
-                              cp->searchin, cp->ignorecase, cp->minmapsize,
-                              p->cp.quietmmap, NULL);
+  /* Go over all the given files. */
+  hdull=p->catcolhdu;
+  for(filell=p->catcolumn; filell!=NULL; filell=filell->next)
+    {
+      /* Set the HDU (not necessary for non-FITS tables). */
+      if(gal_fits_name_is_fits(filell->v))
+        {
+          if(hdull) { hdu=hdull->v; hdull=hdull->next; }
+          else
+            error(EXIT_FAILURE, 0, "not enough `--catcolhdu's. For every "
+                  "FITS table given to `--catcolumn', a call to "
+                  "`--catcolhdu' is necessary to identify its HDU/extension");
+        }
+      else hdu=NULL;
+
+      /* Read the catcolumn table. */
+      tocat=gal_table_read(filell->v, hdu, NULL, NULL, cp->searchin,
+                           cp->ignorecase, cp->minmapsize, p->cp.quietmmap,
+                           NULL);
+
+      /* Check the number of rows. */
+      if(tocat->dsize[0]!=p->table->dsize[0])
+        error(EXIT_FAILURE, 0, "%s: incorrect number of rows. The table given "
+              "to `--catcolumn' must have the same number of rows as the "
+              "main argument (after all row-selections have been applied), "
+              "but they have %zu and %zu rows respectively",
+              gal_fits_name_save_as_string(filell->v, hdu), tocat->dsize[0],
+              p->table->dsize[0]);
+
+      /* Find the final column of the main table and add this table.*/
+      final=gal_list_data_last(p->table);
+      final->next=tocat;
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
-  /* checking if both the tables have same number of rows */
-  if(column_table->dsize[0]!=p->table->dsize[0])
-     error(EXIT_FAILURE, 0, "Number of rows are not equal in both tables.\n"
-          "Input table have %zu rows where as catcolumn table have %zu 
rows.\n",p->table->dsize[0],
-          column_table->dsize[0]);
 
-  /*final column of input table*/
-  final=gal_list_data_last(p->table);
 
-  /*connecting last column of first table to first column of column_table*/
-  final->next=column_table;
-}
 
 
 
@@ -551,7 +591,6 @@ table_catcolumn(struct tableparams *p)
 void
 table(struct tableparams *p)
 {
-
   /* Apply a certain range (if required) to the output sample. */
   if(p->selection) table_selection(p);
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index b423c6c..d5e09f6 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -9270,15 +9270,6 @@ The order of the output columns will be the same order 
given to the option or in
 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, it is possible to output one column 
more than once.
 
-@item -F STR
-@itemx --catcolumn=STR
-File whose columns to add in the main INPUTFILE.
-If any row selection is applied then first row selection is applied and  then 
concatenation is done.
-
-@item -u STR/INT
-@itemx --catcolhdu=STR/INT
-Same as @option{--hdu},Helps to choose Image extension for file given to 
@option{--catcolumn}.
-
 @item -w STR
 @itemx --wcsfile=STR
 FITS file that contains the WCS to be used in the @code{wcstoimg} and 
@code{imgtowcs} operators of @option{--column} (see above).
@@ -9289,6 +9280,17 @@ The extension name/number within the FITS file can be 
specified with @option{--w
 FITS extension/HDU that contains the WCS to be used in the @code{wcstoimg} and 
@code{imgtowcs} operators of @option{--column} (see above).
 The FITS file name can be specified with @option{--wcsfile}.
 
+@item -F STR
+@itemx --catcolumn=STR
+Concatenate/add the columns of this option's value (a filename) with the main 
input table (keeping number of rows fixed).
+The concatenation is done after any column selection (for example with 
@option{--column}) or row selection (for example with @option{--range}) is 
applied to the input.
+Note that if the file given to this option is a FITS file, its necessary to 
also define the corresponding HDU/extension with @option{--catcolhdu}.
+
+@item -u STR/INT
+@itemx --catcolhdu=STR/INT
+The HDU/extension of the FITS files that have been added.
+Same as @option{--hdu},Helps to choose Image extension for file given to 
@option{--catcolumn}.
+
 @item -O
 @itemx --colinfoinstdout
 @cindex Standard output



reply via email to

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