gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 3d52d68: Arithmetic only collapses WCS once


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 3d52d68: Arithmetic only collapses WCS once
Date: Wed, 26 Dec 2018 20:54:42 -0500 (EST)

branch: master
commit 3d52d68e39bbc4f138c0b0f9b75734c79a896850
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Arithmetic only collapses WCS once
    
    Until now, when there was more than one collapse operator, Arithmetic will
    crash with an error in `gal_wcs_remove_dimension' complaining about having
    a 2-dimensional WCS. This was because in Arithmetic, we only have one WCS
    structure and we were collapsing it two times.
    
    To fix the issue, an integer is added in the main structure to mark if the
    WCS structure has already been collapsed or not. The WCS collapse will only
    happen if it hasn't already been done.
---
 NEWS                        |  1 +
 bin/arithmetic/arithmetic.c | 13 ++++++++++---
 bin/arithmetic/main.h       |  1 +
 lib/wcs.c                   | 11 ++++++-----
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index bf2af0a..30a1673 100644
--- a/NEWS
+++ b/NEWS
@@ -153,6 +153,7 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   bug #55025: MakeCatalog's `--prepforconv' option being ignored.
   bug #55079: Blank EPS or PDF page when width options not given.
   bug #55157: No sanity check on values given to Crop's --section.
+  bug #55295: Crash when more than one collapse operator called.
 
 
 
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index d747e85..143ebd4 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -733,7 +733,11 @@ arithmetic_collapse(struct arithmeticparams *p, char 
*token, int operator)
 
   /* If a WCS structure has been read, we'll need to pass it to
      `gal_dimension_collapse', so it modifies it respectively. */
-  input->wcs=p->refdata.wcs;
+  if(p->wcs_collapsed==0)
+    {
+      p->wcs_collapsed=1;
+      input->wcs=p->refdata.wcs;
+    }
 
 
   /* Run the relevant library function. */
@@ -770,8 +774,11 @@ arithmetic_collapse(struct arithmeticparams *p, char 
*token, int operator)
      `collapsed->wcs'. So we'll let the freeing of `input' free the old
      `p->refdata.wcs' structure and we'll put the new one there, then we'll
      set `collapsed->wcs' to `NULL', so the new one isn't freed. */
-  p->refdata.wcs = collapsed->wcs;
-  collapsed->wcs = NULL;
+  if(collapsed->wcs)
+    {
+      p->refdata.wcs = collapsed->wcs;
+      collapsed->wcs = NULL;
+    }
 
 
   /* We'll also need to correct the size of the reference dataset. We'll
diff --git a/bin/arithmetic/main.h b/bin/arithmetic/main.h
index ce36ebb..48512d1 100644
--- a/bin/arithmetic/main.h
+++ b/bin/arithmetic/main.h
@@ -79,6 +79,7 @@ struct arithmeticparams
   size_t      tokencounter;  /* Counter for finding place in tokens.    */
 
   /* Operating mode: */
+  int        wcs_collapsed;  /* If the internal WCS is already collapsed.*/
 
   /* Internal: */
   struct operand *operands;  /* The operands linked list.               */
diff --git a/lib/wcs.c b/lib/wcs.c
index 3fe19cf..cb16dec 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -288,17 +288,18 @@ wcs_ctype_has_tan(char *str)
 void
 gal_wcs_remove_dimension(struct wcsprm *wcs, size_t fitsdim)
 {
-  size_t c, i, j, naxis=wcs->naxis;
+  size_t c, i, j, naxis;
+
+  /* If the WCS structure is NULL, just return. */
+  if(wcs==NULL) return;
 
   /* Sanity check. */
-  if(fitsdim==0 || fitsdim>wcs->naxis)
+  naxis=wcs->naxis;
+  if(fitsdim==0 || fitsdim>naxis)
     error(EXIT_FAILURE, 0, "%s: requested dimension (fitsdim=%zu) must be "
           "larger than zero and smaller than the number of dimensions in "
           "the given WCS structure (%zu)", __func__, fitsdim, naxis);
 
-  /* If the WCS structure is NULL, just return. */
-  if(wcs==NULL) return;
-
   /**************************************************/
 #if WCS_REMOVE_DIM_CHECK
   printf("\n\nfitsdim: %zu\n", fitsdim);



reply via email to

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