gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master cbf8a79 4/9: Table: added the --polygonname op


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master cbf8a79 4/9: Table: added the --polygonname option
Date: Fri, 21 May 2021 23:39:18 -0400 (EDT)

branch: master
commit cbf8a791610c7b7a3fa7d94881eab8255ca70827
Author: Natáli D. Anzanello <natali.anzanello@ufrgs.br>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Table: added the --polygonname option
    
    Until now, the new ds9 library allowed the option --polygonname in the Crop
    program to be extended to the Table program.
    
    With this commit, using the new ds9 library, the --polygonname option that
    was first implemented in the Crop program is now also in the Table program.
    
    NOTE: this commit message was re-formated by Natáli Anzanello to follow the
    convention about the message-line size.
---
 bin/table/args.h | 13 +++++++++++++
 bin/table/main.h |  1 +
 bin/table/ui.c   | 43 +++++++++++++++++++++++++++++++++++++++++++
 bin/table/ui.h   |  1 +
 4 files changed, 58 insertions(+)

diff --git a/bin/table/args.h b/bin/table/args.h
index 5a264a7..a3e82d5 100644
--- a/bin/table/args.h
+++ b/bin/table/args.h
@@ -236,6 +236,19 @@ struct argp_option program_options[] =
       gal_options_parse_colon_sep_csv
     },
     {
+      "polygonname",
+      UI_KEY_POLYGONNAME,
+      "REG",
+      0,
+      "Polygon filename for '--inpolygon' or '--outpolygon'.",
+      UI_GROUP_OUTROWS,
+      &p->polygonname,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+    {
       "equal",
       UI_KEY_EQUAL,
       "STR,FLT[,...]",
diff --git a/bin/table/main.h b/bin/table/main.h
index 065302a..d536367 100644
--- a/bin/table/main.h
+++ b/bin/table/main.h
@@ -98,6 +98,7 @@ struct tableparams
   gal_data_t       *inpolygon;  /* Columns to check if inside polygon.  */
   gal_data_t      *outpolygon;  /* Columns to check if outside polygon. */
   gal_data_t         *polygon;  /* Values of vertices of the polygon.   */
+  char           *polygonname;  /* Name of input polygon file           */
   gal_data_t           *equal;  /* Values to keep in output.            */
   gal_data_t        *notequal;  /* Values to not include in output.     */
   char                  *sort;  /* Column name or number for sorting.   */
diff --git a/bin/table/ui.c b/bin/table/ui.c
index 7f7d7f1..8a4715a 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -28,6 +28,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdio.h>
 #include <string.h>
 
+#include <gnuastro/ds9.h>
 #include <gnuastro/wcs.h>
 #include <gnuastro/fits.h>
 #include <gnuastro/table.h>
@@ -221,6 +222,44 @@ parse_opt(int key, char *arg, struct argp_state *state)
 /**************************************************************/
 /***************       Sanity Check         *******************/
 /**************************************************************/
+/* Do polygon-related sanity checks */
+static void
+ui_check_polygon_from_ds9(struct tableparams *p)
+{
+  int ds9regmode;
+
+  /* This is only relevant when a region file is actually given. */
+  if(p->polygonname)
+    {
+      if(p->polygon)
+      /* These two options cannot be called together. */
+       error(EXIT_FAILURE, errno, "'--polygon' and '--polygonname' "
+              "cannot be given together. With the first you specify the "
+              "polygon vertices directly on the command-line. With the "
+              "second, you give a DS9 region file and the polygon "
+              "vertices are read from that.");
+      else
+        {
+          /* Extract the polygon and the coordinate mode. */
+          p->polygon=gal_ds9_reg_read_polygon(p->polygonname,
+                                              &ds9regmode);
+
+          /* Check if the coordinate's mode in the file is valid. */
+          if(ds9regmode!=GAL_DS9_COORD_MODE_IMG &&
+             ds9regmode!=GAL_DS9_COORD_MODE_WCS)
+            error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at "
+                  "'%s' to fix the problem. The output coordinate mode "
+                  "of 'gal_ds9_reg_read_polygon' (%d) isn't recognized "
+                  "by this function", __func__, PACKAGE_BUGREPORT,
+                  ds9regmode);
+        }
+
+      /* Clean up. */
+      free(p->polygonname);
+      p->polygonname=NULL;
+    }
+}
+
 /* Read and check ONLY the options. When arguments are involved, do the
    check in 'ui_check_options_and_arguments'. */
 static void
@@ -229,6 +268,10 @@ ui_read_check_only_options(struct tableparams *p)
   double *darr;
   gal_data_t *tmp;
 
+  /* If a polygon filename is given, use it. This is done first because it
+     can set the '--polygon' option's value. */
+  ui_check_polygon_from_ds9(p);
+
   /* Check if the format of the output table is valid, given the type of
      the output. */
   gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
diff --git a/bin/table/ui.h b/bin/table/ui.h
index a898b19..4743b7f 100644
--- a/bin/table/ui.h
+++ b/bin/table/ui.h
@@ -74,6 +74,7 @@ enum option_keys_enum
   UI_KEY_INPOLYGON,
   UI_KEY_OUTPOLYGON,
   UI_KEY_CATCOLUMNRAWNAME,
+  UI_KEY_POLYGONNAME,
 };
 
 



reply via email to

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