gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 81f3f65 023/113: More --coordcol options accep


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 81f3f65 023/113: More --coordcol options acceptable in Crop
Date: Fri, 16 Apr 2021 10:33:35 -0400 (EDT)

branch: master
commit 81f3f657724196cfdae740edb8c9168187aea935
Author: Mohammad Akhlaghi <akhlaghi@gnu.org>
Commit: Mohammad Akhlaghi <akhlaghi@gnu.org>

    More --coordcol options acceptable in Crop
    
    Until now, in Crop, `--coordcol' had to be called exactly the same number
    times as the input's dimensions. This was because it was being used
    directly in the function to read the columns. This is inconvenient (for
    example it didn't allow using `--coordcol' in default configuration files).
    
    With this commit, if it is called more than the input's number of
    dimensions, there is no problem. The extra columns will be deleted before
    being used. Crop aborts with an error only if there is not enough
    `--coordcol' calls.
---
 bin/crop/astcrop.conf |  5 +++++
 bin/crop/ui.c         | 37 +++++++++++++++++++++++++++++--------
 doc/gnuastro.texi     | 11 +++++++----
 3 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/bin/crop/astcrop.conf b/bin/crop/astcrop.conf
index b616160..998015b 100644
--- a/bin/crop/astcrop.conf
+++ b/bin/crop/astcrop.conf
@@ -26,5 +26,10 @@
  checkcenter    0
  suffix         _cropped.fits
 
+# Crop by center (when a catalog is given)
+ coordcol       2
+ coordcol       3
+ coordcol       4
+
 # Operating mode:
  mode          wcs
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index 41eeb07..3a516de 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -601,9 +601,9 @@ static void
 ui_read_cols(struct cropparams *p)
 {
   char colname[100];
-  gal_list_str_t *colstrs=NULL;
   gal_data_t *cols, *tmp, *corrtype=NULL;
-  size_t ncoordcols, counter=0, dcounter=0, ndim=p->imgs->ndim;
+  gal_list_str_t *colstrs=NULL, *extracolstr, *lastcolstr;
+  size_t i, ncoordcols, counter=0, dcounter=0, ndim=p->imgs->ndim;
 
   /* See if the number of columns given for coordinates corresponds to the
      number of dimensions of the input dataset. */
@@ -612,13 +612,34 @@ ui_read_cols(struct cropparams *p)
       /* Check if the number of columns given for coordinates is the same
          as the number of dimensions in the input dataset(s). */
       ncoordcols=gal_list_str_number(p->coordcol);
-      if( ncoordcols != ndim)
+      if( ncoordcols < ndim)
         error(EXIT_FAILURE, 0, "`--coordcol' was called %zu times, but the "
-              "input dataset%s %zu dimensions, these values must not be "
-              "different. Recall that through `--coordcol' you are "
-              "specifying the columns containing the coordinates of the "
-              "center of the crop in a catalog", ncoordcols,
-              (p->numin==1?" has":"s have"), ndim);
+              "input dataset%s %zu dimensions. Recall that through "
+              "`--coordcol' you are specifying the columns containing the "
+              "coordinates of the center of the crop in a catalog",
+              ncoordcols, (p->numin==1?" has":"s have"), ndim);
+
+      /* If the number of given columns is more than the input's
+         dimensions, then we'll just delete all the unnecessary columns. */
+      else if( ncoordcols > ndim )
+        {
+          /* Go over the columns find the last, but first initialize the
+             two (`lastcolstr' to avoid compiler warnings). */
+          lastcolstr=extracolstr=p->coordcol;
+          for(i=0;i<ndim;++i)
+            {
+              /* Keep the last node if on the last (useful) column. */
+              if(i==ndim-1) lastcolstr=extracolstr;
+
+              /* Go onto the next one. */
+              extracolstr=extracolstr->next;
+            }
+
+          /* Set the `next' element of the last node to NULL and free the
+             extra ones. */
+          lastcolstr->next=NULL;
+          gal_list_str_free(extracolstr, 1);
+        }
     }
   else
     error(EXIT_FAILURE, 0, "no coordinate columns specified. When a catalog"
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 2b8b30a..210afcc 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -8183,10 +8183,13 @@ input.
 
 @item -x STR/INT
 @itemx --coordcol=STR/INT
-The column in a catalog to read as a coordinate. This option must be called
-multiple times depending on the number of dimensions in the input
-dataset. The value can be either the column number (starting from 1), or a
-match/search in the table meta-data, see @ref{Selecting table columns}.
+The column in a catalog to read as a coordinate. The value can be either
+the column number (starting from 1), or a match/search in the table
+meta-data, see @ref{Selecting table columns}. This option must be called
+multiple times, depending on the number of dimensions in the input
+dataset. If it is called more than necessary, the extra columns (later
+calls to this option on the command-line or configuration files) will be
+ignored, see @ref{Configuration file precedence}.
 
 @item -n STR/INT
 @item --namecol=STR/INT



reply via email to

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