gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master c7daa04 1/2: Table library: Added an option fo


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master c7daa04 1/2: Table library: Added an option for concatenating columns of two tables.
Date: Sun, 22 Mar 2020 11:06:12 -0400 (EDT)

branch: master
commit c7daa04cffc176c1056f529afb5193236a1ce3e9
Author: Madhav Bansal <address@hidden>
Commit: Madhav Bansal <address@hidden>

    Table library: Added an option for concatenating columns of two tables.
    
    Until now, There was no option to concatenate columns of two
    tables. With this commit you can concatenate columns of two
    tables. One table is given as an must input file and another one
    is given to "--catcolumn" option. The column of the table given to
    "--catcolumn" option are attached at the back of given input table.
---
 bin/table/args.h  | 26 ++++++++++++++++++++++++++
 bin/table/main.h  |  2 ++
 bin/table/table.c | 28 ++++++++++++++++++++++++++++
 bin/table/ui.h    |  7 ++++---
 doc/gnuastro.texi |  9 +++++++++
 5 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/bin/table/args.h b/bin/table/args.h
index fa2b6cb..dfceb42 100644
--- a/bin/table/args.h
+++ b/bin/table/args.h
@@ -32,6 +32,32 @@ 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",
diff --git a/bin/table/main.h b/bin/table/main.h
index 1b461cd..1f79c46 100644
--- a/bin/table/main.h
+++ b/bin/table/main.h
@@ -95,6 +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*/
 
   /* Internal. */
   struct column_pack *outcols;  /* Output column packages.              */
diff --git a/bin/table/table.c b/bin/table/table.c
index f6c0928..b6a80b2 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -517,7 +517,31 @@ 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;
+  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);
+
+  /* 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;
+}
 
 
 
@@ -527,6 +551,7 @@ table_head_tail(struct tableparams *p)
 void
 table(struct tableparams *p)
 {
+
   /* Apply a certain range (if required) to the output sample. */
   if(p->selection) table_selection(p);
 
@@ -541,6 +566,9 @@ table(struct tableparams *p)
   if(p->outcols)
     arithmetic_operate(p);
 
+  /* Concatenate the columns of tables(if required)*/
+  if(p->catcolumn) table_catcolumn(p);
+
   /* Write the output. */
   gal_table_write(p->table, NULL, p->cp.tableformat, p->cp.output,
                   "TABLE", p->colinfoinstdout);
diff --git a/bin/table/ui.h b/bin/table/ui.h
index 6782f63..72fa2d5 100644
--- a/bin/table/ui.h
+++ b/bin/table/ui.h
@@ -41,8 +41,8 @@ enum program_args_groups
 
 /* Available letters for short options:
 
-   a b d f g j k l m p t u v x y z
-   A B C E G H J L O Q R X Y
+   a b d f g j k l m p t v x y z
+   A B E G H J L O Q R X Y
 */
 enum option_keys_enum
 {
@@ -59,7 +59,8 @@ enum option_keys_enum
   UI_KEY_DESCENDING      = 'd',
   UI_KEY_HEAD            = 'H',
   UI_KEY_TAIL            = 't',
-
+  UI_KEY_CATCOLUMN       = 'C',
+  UI_KEY_CATCOLHDU       = 'u',
   /* Only with long version (start with a value 1000, the rest will be set
      automatically). */
 };
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 5cc057e..b423c6c 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -9270,6 +9270,15 @@ 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).



reply via email to

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