gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 2dfa164: Corrected bad status usage in wcsp2s


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2dfa164: Corrected bad status usage in wcsp2s and wcss2p
Date: Fri, 2 Dec 2016 17:13:12 +0000 (UTC)

branch: master
commit 2dfa164645a06a6af97d65fc0d45684da21b908f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Corrected bad status usage in wcsp2s and wcss2p
    
    The status argument to WCSLIB's `wcsp2s' and `wcss2p' functions is not a
    simple variable, but an array (WCSLIB apparently writes a status value for
    each coordinate). So on some compilers, this caused a segmentation error
    when more than one coordinate was input.
    
    This bug was reported by Christopher Willmer, he also patiently helped in
    finding its cause and confirming the solution.
    
    This fixes bug #49752.
---
 THANKS                |    1 +
 bin/imgcrop/crop.c    |   11 ++++++-----
 bin/imgcrop/wcsmode.c |   13 ++++++++-----
 lib/wcs.c             |   12 ++++++------
 4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/THANKS b/THANKS
index 6a0f8c7..36d3ad5 100644
--- a/THANKS
+++ b/THANKS
@@ -27,6 +27,7 @@ support in Gnuastro. The list is ordered alphabetically.
     Yahya Sefidbakht                     address@hidden
     Richard Stallman                     address@hidden
     Ole Streicher                        address@hidden
+    Christopher Willmer                  address@hidden
 
 
 Institutions
diff --git a/bin/imgcrop/crop.c b/bin/imgcrop/crop.c
index 3bdebf4..e55b521 100644
--- a/bin/imgcrop/crop.c
+++ b/bin/imgcrop/crop.c
@@ -500,8 +500,8 @@ cropname(struct cropparams *crp)
 void
 cropflpixel(struct cropparams *crp)
 {
-  int ncoord=1, nelem=2, status;
   struct imgcropparams *p=crp->p;
+  int ncoord=1, nelem=2, status[2]={0,0};
   long *naxes=p->imgs[crp->imgindex].naxes;
   double pixcrd[2], imgcrd[2], phi[1], theta[1];
   long *fpixel=crp->fpixel, *lpixel=crp->lpixel;
@@ -539,11 +539,12 @@ cropflpixel(struct cropparams *crp)
         }
       else
         {
-          status=0;
           if(wcss2p(p->imgs[crp->imgindex].wcs, ncoord, nelem, crp->world,
-                    phi, theta, imgcrd, pixcrd, &status) )
-            error(EXIT_FAILURE, 0, "wcss2p error %d: %s", status,
-                  wcs_errmsg[status]);
+                    phi, theta, imgcrd, pixcrd, status) )
+            if(status[0] || status[1])
+              error(EXIT_FAILURE, 0, "wcss2p error %d: %s",
+                    status[0] ? status[0] : status[1],
+                    wcs_errmsg[status[0] ? status[0] : status[1]]);
           gal_box_border_from_center(pixcrd[0], pixcrd[1], p->iwidth, fpixel,
                                      lpixel);
           /*
diff --git a/bin/imgcrop/wcsmode.c b/bin/imgcrop/wcsmode.c
index 6d91135..ae894d8 100644
--- a/bin/imgcrop/wcsmode.c
+++ b/bin/imgcrop/wcsmode.c
@@ -52,7 +52,7 @@ wcscheckprepare(struct imgcropparams *p, struct inputimgs 
*img)
 {
   double twidth;
   struct wcsprm *wcs=img->wcs;
-  int status, ncoord=4, nelem=2;
+  int i, status[4]={0,0,0,0}, ncoord=4, nelem=2;
   double imgcrd[8], phi[4], theta[4], pixcrd[8];
 
 
@@ -123,10 +123,13 @@ wcscheckprepare(struct imgcropparams *p, struct inputimgs 
*img)
   pixcrd[4]=1;               pixcrd[5]=img->naxes[1];
   pixcrd[6]=img->naxes[0];   pixcrd[7]=img->naxes[1];
   wcsp2s(wcs, ncoord, nelem, pixcrd, imgcrd, phi, theta,
-         img->corners, &status);
-  if(status)
-    error(EXIT_FAILURE, 0, "wcsp2s ERROR %d: %s", status,
-          wcs_errmsg[status]);
+         img->corners, status);
+
+  /* Check if there was no error in the conversion. */
+  for(i=0;i<4;++i)
+    if(status[i])
+      error(EXIT_FAILURE, 0, "wcsp2s ERROR %d in row %d of pixcrd: %s",
+            i, status[i], wcs_errmsg[status[i]]);
 
 
   /* Fill in the size of the image in celestial degrees from the first
diff --git a/lib/wcs.c b/lib/wcs.c
index 0c716df..58967bd 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -57,7 +57,7 @@ gal_wcs_xy_array_to_radec(struct wcsprm *wcs, double *xy, 
double *radec,
 {
   size_t i;
   double imgcrd[2], phi, theta;
-  int stat, status=0, ncoord=1, nelem=2;
+  int status=0, ncoord=1, nelem=2;
 
   for(i=0;i<number;++i)
     {
@@ -65,8 +65,8 @@ gal_wcs_xy_array_to_radec(struct wcsprm *wcs, double *xy, 
double *radec,
         radec[i*stride]=radec[i*stride+1]=NAN;
       else
         {
-          status=wcsp2s(wcs, ncoord, nelem, xy+i*stride, imgcrd, &phi,
-                        &theta, radec+i*stride, &stat);
+          wcsp2s(wcs, ncoord, nelem, xy+i*stride, imgcrd, &phi,
+                 &theta, radec+i*stride, &status);
           if(status)
             error(EXIT_FAILURE, 0, "wcsp2s ERROR %d: %s", status,
                   wcs_errmsg[status]);
@@ -91,7 +91,7 @@ gal_wcs_radec_array_to_xy(struct wcsprm *wcs, double *radec, 
double *xy,
 {
   size_t i;
   double imgcrd[2], phi, theta;
-  int stat, status=0, ncoord=1, nelem=2;
+  int status=0, ncoord=1, nelem=2;
 
   for(i=0;i<number;++i)
     {
@@ -99,8 +99,8 @@ gal_wcs_radec_array_to_xy(struct wcsprm *wcs, double *radec, 
double *xy,
         radec[i*stride]=radec[i*stride+1]=NAN;
       else
         {
-          status=wcss2p(wcs, ncoord, nelem, radec+i*stride, &phi, &theta,
-                        imgcrd, xy+i*stride, &stat);
+          wcss2p(wcs, ncoord, nelem, radec+i*stride, &phi, &theta,
+                 imgcrd, xy+i*stride, &status);
           if(status)
             error(EXIT_FAILURE, 0, "wcss2p ERROR %d: %s", status,
                   wcs_errmsg[status]);



reply via email to

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