[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master fe26200 1/2: Crop: added final check to see if
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master fe26200 1/2: Crop: added final check to see if there is overlap |
Date: |
Fri, 2 Oct 2020 19:29:04 -0400 (EDT) |
branch: master
commit fe262000b2cd4e8bc4389684be8a80fd55c84d31
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Crop: added final check to see if there is overlap
Until now, we would simply use the WCS to see if there is any overlap and
assumed its fine afterwards. But in some scenarios, where there is one or
two pixels offset, while the WCS condition finds an overlap, the actual
pixels fail by one pixel or so and don't find any. This caused an error in
the running of Crop.
With this commit, after attempting the crop, do one extra check to make
sure an actual overlap can be found.
---
bin/crop/crop.c | 6 ++++--
bin/crop/onecrop.c | 12 ++++++++----
bin/crop/onecrop.h | 2 +-
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index 19d2eed..7e9444c 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -313,9 +313,11 @@ crop_mode_wcs(void *inparam)
/* Increment the number of images used (necessary for the
header keywords that are written in 'onecrop'). Then do the
- crop. */
+ crop. However, the previously WCS-based overlap can be
+ slightly different from the final overlap, so if we finally
+ don't find any overlap we'll decrement the 'numimg'. */
++crp->numimg;
- onecrop(crp);
+ if( onecrop(crp)==0 ) --crp->numimg;
/* Close the file. */
status=0;
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index 5061b61..2cb337f 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -654,13 +654,14 @@ onecrop_make_array(struct onecropparams *crp, long
*fpixel_i,
'FLEN_KEYWORD' (which is 75 characters). To avoid compiler warnings, we
are just removing a few characters ('FLEN_KEYWORD-5') to allow the
suffix and remove the warnings. */
-void
+int
onecrop(struct onecropparams *crp)
{
struct cropparams *p=crp->p;
struct inputimgs *img=&p->imgs[crp->in_ind];
void *array;
+ int returnvalue=1;
int status=0, anynul=0;
fitsfile *ifp=crp->infits, *ofp;
char basekeyname[FLEN_KEYWORD-5]; /* '-5': avoid gcc 8.1+ warnings! */
@@ -763,11 +764,14 @@ onecrop(struct onecropparams *crp)
free(array);
}
else
- if(p->polygon && p->polygonout==0 && p->mode==IMGCROP_MODE_WCS)
- free(crp->ipolygon);
+ {
+ returnvalue=0;
+ if(p->polygon && p->polygonout==0 && p->mode==IMGCROP_MODE_WCS)
+ free(crp->ipolygon);
+ }
/* The crop is complete. */
- return;
+ return returnvalue;
}
diff --git a/bin/crop/onecrop.h b/bin/crop/onecrop.h
index d2ef458..75e474c 100644
--- a/bin/crop/onecrop.h
+++ b/bin/crop/onecrop.h
@@ -62,7 +62,7 @@ struct onecropparams
void
onecrop_name(struct onecropparams *crp);
-void
+int
onecrop(struct onecropparams *crp);
int