[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
- [gnuastro-commits] master updated (89db01d -> dd4d43e), Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 17d6f65 004/113: Merged recent corrections in master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 42e04b6 002/113: Recent changes in master merged, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master f25b55e 005/113: Merged with recent changes in master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master a11e71c 003/113: Merged with recent changes in master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 3df6490 001/113: Crop works in 3D, except for --polygon, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master d14384a 007/113: Minor corrections in MakeProfiles manual, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 5abb468 008/113: Other minor corrections in the documentation, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 3e76e1f 010/113: MakeProfiles --kernel builds 3D kernels also, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 81f3f65 023/113: More --coordcol options acceptable in Crop,
Mohammad Akhlaghi <=
- [gnuastro-commits] master e47f8db 024/113: Merged recent work in master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 8fa5ff1 026/113: Minor edit in book (part added in last commit), Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 40f0a56 013/113: Minor corrections to MakeProfiles continued, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 8372486 020/113: NoiseChisel's detection complete in 3D, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6cc3d25 027/113: No 3D projections in function to inspect NoiseChisel outputs, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master e990860 029/113: Merged recent updates in master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6bdc5d6 030/113: Oversegmentation connectivity one less for 3D, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master be3bfd8 033/113: NoiseChisel configuration file in 3D updated, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 3b6c15d 036/113: Merged with recent work in master, no conflicts, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master fb3660f 037/113: MakeCatalog works in 3D, Mohammad Akhlaghi, 2021/04/16