[GRASS-SVN] r62888 - grass/trunk/raster/r.uslek

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 24 09:00:06 PST 2014


Author: neteler
Date: 2014-11-24 09:00:06 -0800 (Mon, 24 Nov 2014)
New Revision: 62888

Modified:
   grass/trunk/raster/r.uslek/main.c
   grass/trunk/raster/r.uslek/tex2usle_k.c
Log:
r.uslek: organic matter range fix; fp precision fix

Modified: grass/trunk/raster/r.uslek/main.c
===================================================================
--- grass/trunk/raster/r.uslek/main.c	2014-11-24 16:50:51 UTC (rev 62887)
+++ grass/trunk/raster/r.uslek/main.c	2014-11-24 17:00:06 UTC (rev 62888)
@@ -1,4 +1,3 @@
-
 /****************************************************************************
  *
  * MODULE:       r.uslek
@@ -19,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
@@ -136,17 +136,19 @@
 	    else {
                 /***************************************/ 
 		/* In case some map input not standard */
-		if ((d_sand + d_clay + d_silt) != 1.0) 
+		if (fabs(d_sand + d_clay + d_silt - 1.0) > GRASS_EPSILON )
 		    Rast_set_d_null_value(&outrast[col], 1);
 		/* if OM==NULL then make it 0.0 */
-		else if (Rast_is_d_null_value(&d_om))
-		    d_om = 0.0;	
 		else {
-                    /************************************/ 
+		    if (Rast_is_d_null_value(&d_om))
+		        d_om = 0.0;
+		    /************************************/ 
 		    /* convert to usle_k                */ 
 		    d = (double)prct2tex(d_sand, d_clay, d_silt);
-		    d = tex2usle_k((int)d, d_om);
-		    outrast[col] = d;
+		    if(d > 11.0) /* 11 is highest class */
+			Rast_set_d_null_value(&outrast[col], 1);
+		    else
+			outrast[col] = tex2usle_k((int)d, d_om);
                 }
 	    }
 	}

Modified: grass/trunk/raster/r.uslek/tex2usle_k.c
===================================================================
--- grass/trunk/raster/r.uslek/tex2usle_k.c	2014-11-24 16:50:51 UTC (rev 62887)
+++ grass/trunk/raster/r.uslek/tex2usle_k.c	2014-11-24 17:00:06 UTC (rev 62888)
@@ -7,8 +7,8 @@
 {
     double usle_k = 200.0; /* Initial value */
 
-    G_debug(1, "texture=%i, om=%5.3f",texture, om_in);
-    if (om_in < 0.5) {
+    G_verbose_message("tex2usle_k: texture=%i, om=%5.3f", texture, om_in);
+    if (om_in < 0.05) {
 	if (texture == 0) /* G_message("clay"); */
 	    usle_k = 0.29;	/*Took max value @0.2 */
 	else if (texture == 1) /* G_message("sandy clay"); */
@@ -36,7 +36,7 @@
 	else /*G_message("Unable to allocate class"); */
 	    usle_k = 500.0;/*change value to show it was processed */
     }
-    else if (om_in >= 0.5 && om_in < 0.2) {
+    else if (om_in >= 0.05 && om_in < 0.2) {
 	if (texture == 0) /* G_message("clay"); */
 	    usle_k = 0.29; /*Range=[0.13-0.29]@0.2, took max */
 	else if (texture == 1) /* G_message("sandy clay"); */



More information about the grass-commit mailing list