[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 7516cf0: More --coordcol options acceptable in
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 7516cf0: More --coordcol options acceptable in Crop |
Date: |
Sun, 20 Aug 2017 19:37:27 -0400 (EDT) |
branch: master
commit 7516cf080ffb015eebea141a0c1366409183ad7f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
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 | 4 ++++
bin/crop/ui.c | 38 +++++++++++++++++++++++++++++---------
doc/gnuastro.texi | 11 +++++++----
3 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/bin/crop/astcrop.conf b/bin/crop/astcrop.conf
index b616160..e24f30c 100644
--- a/bin/crop/astcrop.conf
+++ b/bin/crop/astcrop.conf
@@ -26,5 +26,9 @@
checkcenter 0
suffix _cropped.fits
+# Crop by center (when a catalog is given)
+ coordcol 2
+ coordcol 3
+
# Operating mode:
mode wcs
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index a8cc827..089a0d9 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -603,10 +603,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. */
@@ -615,13 +614,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 03755db..bca8b1c 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 7516cf0: More --coordcol options acceptable in Crop,
Mohammad Akhlaghi <=