[GRASS-SVN] r70685 - grass/branches/releasebranch_7_0/raster/r.mapcalc

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 26 06:14:52 PST 2017


Author: mmetz
Date: 2017-02-26 06:14:52 -0800 (Sun, 26 Feb 2017)
New Revision: 70685

Modified:
   grass/branches/releasebranch_7_0/raster/r.mapcalc/xnmedian.c
Log:
r.mapcalc: fix for #3296 (backport trunk r70683)

Modified: grass/branches/releasebranch_7_0/raster/r.mapcalc/xnmedian.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.mapcalc/xnmedian.c	2017-02-26 14:11:40 UTC (rev 70684)
+++ grass/branches/releasebranch_7_0/raster/r.mapcalc/xnmedian.c	2017-02-26 14:14:52 UTC (rev 70685)
@@ -70,8 +70,8 @@
 	    CELL *res = args[0];
 	    CELL **argv = (CELL **) &args[1];
 	    CELL *a = array;
-	    CELL *a1 = &a[(argc - 1) / 2];
-	    CELL *a2 = &a[argc / 2];
+	    CELL *a1;
+	    CELL *a2;
 
 	    for (i = 0; i < columns; i++) {
 		int n = 0;
@@ -84,10 +84,10 @@
 
 		if (!n)
 		    SET_NULL_C(&res[i]);
-                else if (n == 1)
-                    res[i] = *a1;
 		else {
 		    qsort(a, n, sizeof(CELL), icmp);
+		    a1 = &a[(n - 1) / 2];
+		    a2 = &a[n / 2];
 		    res[i] = (*a1 + *a2) / 2;
 		}
 	    }
@@ -99,8 +99,8 @@
 	    FCELL *res = args[0];
 	    FCELL **argv = (FCELL **) &args[1];
 	    FCELL *a = array;
-	    FCELL *a1 = &a[(argc - 1) / 2];
-	    FCELL *a2 = &a[argc / 2];
+	    FCELL *a1;
+	    FCELL *a2;
 
 	    for (i = 0; i < columns; i++) {
 		int n = 0;
@@ -113,10 +113,10 @@
 
 		if (!n)
 		    SET_NULL_F(&res[i]);
-                else if (n == 1)
-                    res[i] = *a1;
 		else {
 		    qsort(a, n, sizeof(FCELL), fcmp);
+		    a1 = &a[(n - 1) / 2];
+		    a2 = &a[n / 2];
 		    res[i] = (*a1 + *a2) / 2;
 		}
 	    }
@@ -128,8 +128,8 @@
 	    DCELL *res = args[0];
 	    DCELL **argv = (DCELL **) &args[1];
 	    DCELL *a = array;
-	    DCELL *a1 = &a[(argc - 1) / 2];
-	    DCELL *a2 = &a[argc / 2];
+	    DCELL *a1;
+	    DCELL *a2;
 
 	    for (i = 0; i < columns; i++) {
 		int n = 0;
@@ -142,10 +142,10 @@
 
 		if (!n)
 		    SET_NULL_D(&res[i]);
-                else if (n == 1)
-                    res[i] = *a1;
 		else {
 		    qsort(a, n, sizeof(DCELL), dcmp);
+		    a1 = &a[(n - 1) / 2];
+		    a2 = &a[n / 2];
 		    res[i] = (*a1 + *a2) / 2;
 		}
 	    }



More information about the grass-commit mailing list