[GRASS-SVN] r33815 - in grass/trunk/raster: . r.uslek

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 11 11:17:18 EDT 2008


Author: ychemin
Date: 2008-10-11 11:17:18 -0400 (Sat, 11 Oct 2008)
New Revision: 33815

Added:
   grass/trunk/raster/r.uslek/
   grass/trunk/raster/r.uslek/Makefile
   grass/trunk/raster/r.uslek/main.c
   grass/trunk/raster/r.uslek/prct2tex.c
   grass/trunk/raster/r.uslek/r.uslek.html
   grass/trunk/raster/r.uslek/tex2usle_k.c
Modified:
   grass/trunk/raster/Makefile
Log:
Added r.uslek, with GUIs menu entries

Modified: grass/trunk/raster/Makefile
===================================================================
--- grass/trunk/raster/Makefile	2008-10-11 12:27:11 UTC (rev 33814)
+++ grass/trunk/raster/Makefile	2008-10-11 15:17:18 UTC (rev 33815)
@@ -102,6 +102,7 @@
 	r.topmodel \
 	r.transect \
 	r.univar \
+	r.uslek \
 	r.volume \
 	r.walk \
 	r.water.outlet \

Added: grass/trunk/raster/r.uslek/Makefile
===================================================================
--- grass/trunk/raster/r.uslek/Makefile	                        (rev 0)
+++ grass/trunk/raster/r.uslek/Makefile	2008-10-11 15:17:18 UTC (rev 33815)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.uslek
+
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Added: grass/trunk/raster/r.uslek/main.c
===================================================================
--- grass/trunk/raster/r.uslek/main.c	                        (rev 0)
+++ grass/trunk/raster/r.uslek/main.c	2008-10-11 15:17:18 UTC (rev 33815)
@@ -0,0 +1,181 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r.uslek
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE:      Transforms percentage of texture (sand/clay/silt)
+ *               into USDA 1951 (p209) soil texture classes and then
+ *               into USLE soil erodibility factor (K) as an output
+ *
+ * COPYRIGHT:    (C) 2002-2008 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	 License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	 for details.
+ *
+ *****************************************************************************/
+     
+    
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#define POLYGON_DIMENSION 20
+
+double tex2usle_k(int texture, double om_in);
+int prct2tex(double sand_input, double clay_input, double silt_input);
+double point_in_triangle(double point_x, double point_y, double point_z,
+			 double t1_x, double t1_y, double t1_z, double t2_x,
+			 double t2_y, double t2_z, double t3_x, double t3_y,
+			 double t3_z);
+    
+int main(int argc, char *argv[]) 
+{
+    int nrows, ncols;
+    int row, col;
+    struct GModule *module;
+    struct Option *input1, *input2, *input3, *input4, *output1;
+    struct History history;	/*metadata */
+
+    char *result;		/*output raster name */
+    int infd_psand, infd_psilt, infd_pclay, infd_pomat;
+    int outfd;
+    char *psand, *psilt, *pclay, *pomat;
+    int i = 0;
+    void *inrast_psand, *inrast_psilt, *inrast_pclay, *inrast_pomat;
+    DCELL *outrast;
+    
+    /************************************/ 
+    G_gisinit(argv[0]);
+    module = G_define_module();
+    module->keywords = _("raster, soil, erosion, USLE");
+    module->description = _("USLE Soil Erodibility Factor (K)");
+    
+    /* Define the different options */ 
+    input1 = G_define_standard_option(G_OPT_R_INPUT);
+    input1->key = _("psand");
+    input1->description = _("Name of the Soil sand fraction map [0.0-1.0]");
+
+    input2 = G_define_standard_option(G_OPT_R_INPUT);
+    input2->key = _("pclay");
+    input2->description = _("Name of the Soil clay fraction map [0.0-1.0]");
+
+    input3 = G_define_standard_option(G_OPT_R_INPUT);
+    input3->key = _("psilt");
+    input3->description = _("Name of the Soil silt fraction map [0.0-1.0]");
+
+    input4 = G_define_standard_option(G_OPT_R_INPUT);
+    input4->key = _("pomat");
+    input4->description = _("Name of the Soil Organic Matter map [0.0-1.0]");
+
+    output1 = G_define_standard_option(G_OPT_R_OUTPUT);
+    output1->key = _("usle_k");
+    output1->description = _("Name of the output USLE K factor layer");
+
+    /********************/ 
+    if (G_parser(argc, argv))
+        exit(EXIT_FAILURE);
+
+    psand = input1->answer;
+    pclay = input2->answer;
+    psilt = input3->answer;
+    pomat = input4->answer;
+    result = output1->answer;
+    
+    /***************************************************/ 
+    if ((infd_psand = G_open_cell_old(psand, "")) < 0)
+	G_fatal_error(_("Cannot open cell file [%s]"), psand);
+    inrast_psand = G_allocate_d_raster_buf();
+    
+    if ((infd_psilt = G_open_cell_old(psilt, "")) < 0)
+	G_fatal_error(_("Cannot open cell file [%s]"), psilt);
+    inrast_psilt = G_allocate_d_raster_buf();
+    
+    if ((infd_pclay = G_open_cell_old(pclay, "")) < 0)
+	G_fatal_error(_("Cannot open cell file [%s]"), pclay);
+    inrast_pclay = G_allocate_d_raster_buf();
+    
+    if ((infd_pomat = G_open_cell_old(pomat, "")) < 0)
+	G_fatal_error(_("Cannot open cell file [%s]"), pomat);
+    inrast_pomat = G_allocate_d_raster_buf();
+    /***************************************************/ 
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+    outrast = G_allocate_d_raster_buf();
+    
+    /* Create New raster files */ 
+    if ((outfd = G_open_raster_new(result, DCELL_TYPE)) < 0)
+	G_fatal_error(_("Could not open <%s>"), result);
+    
+    /* Process pixels */ 
+    for (row = 0; row < nrows; row++)
+    {
+	DCELL d;
+	DCELL d_sand;
+	DCELL d_clay;
+	DCELL d_silt;
+	DCELL d_om;
+	G_percent(row, nrows, 2);
+	
+	/* read soil input maps */ 
+	if (G_get_d_raster_row(infd_psand, inrast_psand, row) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), psand);
+	if (G_get_d_raster_row(infd_psilt, inrast_psilt, row) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), psilt);
+	if (G_get_d_raster_row(infd_pclay, inrast_pclay, row) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), pclay);
+	if (G_get_d_raster_row(infd_pomat, inrast_pomat, row) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), pomat);
+	
+        /*process the data */ 
+	for (col = 0; col < ncols; col++)
+	{
+	    d_sand = ((DCELL *) inrast_psand)[col];
+	    d_silt = ((DCELL *) inrast_psilt)[col];
+	    d_clay = ((DCELL *) inrast_pclay)[col];
+            d_om = ((DCELL *) inrast_pomat)[col];
+	    if (G_is_d_null_value(&d_sand) || 
+                G_is_d_null_value(&d_clay) ||
+		G_is_d_null_value(&d_silt)) 
+		    G_set_d_null_value(&outrast[col], 1);
+	    else {
+                /***************************************/ 
+		/* In case some map input not standard */
+		if ((d_sand + d_clay + d_silt) != 1.0) 
+		    G_set_d_null_value(&outrast[col], 1);
+		/* if OM==NULL then make it 0.0 */
+		else if (G_is_d_null_value(&d_om))
+		    d_om = 0.0;	
+		else {
+                    /************************************/ 
+		    /* convert to usle_k                */ 
+		    d = (double)prct2tex(d_sand, d_clay, d_silt);
+		    d = tex2usle_k((int)d, d_om);
+		    outrast[col] = d;
+                }
+	    }
+	}
+	if (G_put_d_raster_row(outfd, outrast) < 0)
+	    G_fatal_error(_("Unable to write output raster file"));
+    }
+    G_free(inrast_psand);
+    G_free(inrast_psilt);
+    G_free(inrast_pclay);
+    G_free(inrast_pomat);
+    G_close_cell(infd_psand);
+    G_close_cell(infd_psilt);
+    G_close_cell(infd_pclay);
+    G_close_cell(infd_pomat);
+    G_free(outrast);
+    G_close_cell(outfd);
+    
+    G_short_history(result, "raster", &history);
+    G_command_history(&history);
+    G_write_history(result, &history);
+    
+    exit(EXIT_SUCCESS);
+}
+
+

Added: grass/trunk/raster/r.uslek/prct2tex.c
===================================================================
--- grass/trunk/raster/r.uslek/prct2tex.c	                        (rev 0)
+++ grass/trunk/raster/r.uslek/prct2tex.c	2008-10-11 15:17:18 UTC (rev 33815)
@@ -0,0 +1,693 @@
+#include<stdio.h>
+
+#define POLYGON_DIMENSION 20
+/* From FAOSOIL CD, after USDA 1951, p209 */
+
+struct vector
+{
+    double sand;
+    double clay;
+    double silt;
+};
+
+double point_in_triangle(double point_x, double point_y, double point_z,
+			 double t1_x, double t1_y, double t1_z, double t2_x,
+			 double t2_y, double t2_z, double t3_x, double t3_y,
+			 double t3_z)
+{
+    /*G_message("in function: sand=%5.3f clay=%5.3f silt=%5.3f",
+				point_x,point_y,point_z); */
+    double answer;
+    double answer1_x, answer1_y, answer1_z;
+    double answer2_x, answer2_y, answer2_z;
+    double answer3_x, answer3_y, answer3_z;
+
+    /* Consider three points forming a trinagle from a given soil class boundary ABC */
+    /* Consider F an additional point in space */
+    double af1, af2, af3;	/*Points for vector AF */
+    double bf1, bf2, bf3;	/*Points for vector BF */
+    double cf1, cf2, cf3;	/*Points for vector CF */
+    double ab1, ab2, ab3;	/*Points for vector AB */
+    double bc1, bc2, bc3;	/*Points for vector BC */
+    double ca1, ca2, ca3;	/*Points for vector CA */
+
+    /* Create vectors AB, BC and CA */
+    ab1 = (t2_x - t1_x);
+    ab2 = (t2_y - t1_y);
+    ab3 = (t2_z - t1_z);
+    bc1 = (t3_x - t2_x);
+    bc2 = (t3_y - t2_y);
+    bc3 = (t3_z - t2_z);
+    ca1 = (t1_x - t3_x);
+    ca2 = (t1_y - t3_y);
+    ca3 = (t1_z - t3_z);
+    /* Create vectors AF, BF and CF */
+    af1 = (point_x - t1_x);
+    af2 = (point_y - t1_y);
+    af3 = (point_z - t1_z);
+    bf1 = (point_x - t2_x);
+    bf2 = (point_y - t2_y);
+    bf3 = (point_z - t2_z);
+    cf1 = (point_x - t3_x);
+    cf2 = (point_y - t3_y);
+    cf3 = (point_z - t3_z);
+    /* Calculate the following CrossProducts: */
+    /* AFxAB */
+    answer1_x = (af2 * ab3) - (af3 * ab2);
+    answer1_y = (af3 * ab1) - (af1 * ab3);
+    answer1_z = (af1 * ab2) - (af2 * ab1);
+    /* G_message("answer(AFxAB)= %f %f %f",answer1_x, answer1_y, answer1_z); */
+    /*BFxBC */
+    answer2_x = (bf2 * bc3) - (bf3 * bc2);
+    answer2_y = (bf3 * bc1) - (bf1 * bc3);
+    answer2_z = (bf1 * bc2) - (bf2 * bc1);
+    /* G_message("answer(BFxBC)= %f %f %f",answer2_x, answer2_y, answer2_z); */
+    /*CFxCA */
+    answer3_x = (cf2 * ca3) - (cf3 * ca2);
+    answer3_y = (cf3 * ca1) - (cf1 * ca3);
+    answer3_z = (cf1 * ca2) - (cf2 * ca1);
+    /* G_message("answer(CFxCA)= %f %f %f",answer3_x, answer3_y, answer3_z); */
+    answer = 0.0; /*initialize value */
+    if ((int)answer1_x >= 0 && (int)answer2_x >= 0 && (int)answer3_x >= 0) {
+	answer += 1.0;
+    }
+    else if ((int)answer1_x <= 0 && (int)answer2_x <= 0 &&
+	     (int)answer3_x <= 0) {
+	answer -= 1.0;
+    }
+    if ((int)answer1_y >= 0 && (int)answer2_y >= 0 && (int)answer3_y >= 0) {
+	answer += 1.0;
+    }
+    else if ((int)answer1_y <= 0 && (int)answer2_y <= 0 &&
+	     (int)answer3_y <= 0) {
+	answer -= 1.0;
+    }
+    if ((int)answer1_z >= 0 && (int)answer2_z >= 0 && (int)answer3_z >= 0) {
+	answer += 1.0;
+    }
+    else if ((int)answer1_z <= 0 && (int)answer2_z <= 0 &&
+	     (int)answer3_z <= 0) {
+	answer -= 1.0;
+    }
+    if (answer == 3 || answer == -3) {
+	answer = 1;
+    }
+    else {
+	answer = 0;
+    }
+    return answer;
+}
+
+int prct2tex(double sand_input, double clay_input, double silt_input)
+{
+    /*G_message("%5.3f||%5.3f||%5.3f",sand_input,clay_input,silt_input); */
+    int i;
+    double temp;
+
+    /* set up index for soil texture classes */
+    int index = 20;
+
+    /* set up mark index for inside/outside polygon check */
+    double mark[POLYGON_DIMENSION] = { 0.0 };
+    /*G_message("in prct2tex()"); */
+    /*setup the 3Dvectors and initialize them */
+    /* index 0 */
+    struct vector cls_clay[POLYGON_DIMENSION] = { 0.0 };
+    /* index 1 */
+    struct vector cls_sandy_clay[POLYGON_DIMENSION] = { 0.0 };
+    /* index 2 */
+    struct vector cls_silty_clay[POLYGON_DIMENSION] = { 0.0 };
+    /* index 3 */
+    struct vector cls_sandy_clay_loam[POLYGON_DIMENSION] = { 0.0 };
+    /* index 4 */
+    struct vector cls_clay_loam[POLYGON_DIMENSION] = { 0.0 };
+    /* index 5 */
+    struct vector cls_silty_clay_loam[POLYGON_DIMENSION] = { 0.0 };
+    /* index 6 */
+    struct vector cls_sand[POLYGON_DIMENSION] = { 0.0 };
+    /* index 7 */
+    struct vector cls_loamy_sand[POLYGON_DIMENSION] = { 0.0 };
+    /* index 8 */
+    struct vector cls_sandy_loam[POLYGON_DIMENSION] = { 0.0 };
+    /* index 9 */
+    struct vector cls_loam[POLYGON_DIMENSION] = { 0.0 };
+    /* index 10 */
+    struct vector cls_silt_loam[POLYGON_DIMENSION] = { 0.0 };
+    /* index 11 */
+    struct vector cls_silt[POLYGON_DIMENSION] = { 0.0 };
+
+    if ((sand_input + clay_input + silt_input) <= 10.0) {
+	sand_input = sand_input * 100.0;
+	clay_input = clay_input * 100.0;
+	silt_input = silt_input * 100.0;
+    }
+    /*G_message("%5.3f||%5.3f||%5.3f|",sand_input,clay_input,silt_input); */
+
+    /*Feed the polygons for index 0 */
+    cls_clay[0].sand = 0.0;
+    cls_clay[0].clay = 100.0;
+    cls_clay[0].silt = 0.0;
+    cls_clay[1].sand = 0.0;
+    cls_clay[1].clay = 60.0;
+    cls_clay[1].silt = 40.0;
+    cls_clay[2].sand = 20.0;
+    cls_clay[2].clay = 40.0;
+    cls_clay[2].silt = 40.0;
+    cls_clay[3].sand = 50.0;
+    cls_clay[3].clay = 40.0;
+    cls_clay[3].silt = 10.0;
+    cls_clay[4].sand = 50.0;
+    cls_clay[4].clay = 50.0;
+    cls_clay[4].silt = 0.0;
+    /* Check for index 0 */
+    /* G_message("in prct2tex(): check for index 0"); */
+    mark[0] =
+	point_in_triangle(sand_input, clay_input, silt_input,
+			  cls_clay[0].sand, cls_clay[0].clay,
+			  cls_clay[0].silt, cls_clay[1].sand,
+			  cls_clay[1].clay, cls_clay[1].silt,
+			  cls_clay[2].sand, cls_clay[2].clay,
+			  cls_clay[2].silt);
+    mark[1] =
+	point_in_triangle(sand_input, clay_input, silt_input,
+			  cls_clay[0].sand, cls_clay[0].clay,
+			  cls_clay[0].silt, cls_clay[2].sand,
+			  cls_clay[2].clay, cls_clay[2].silt,
+			  cls_clay[3].sand, cls_clay[3].clay,
+			  cls_clay[3].silt);
+    mark[2] =
+	point_in_triangle(sand_input, clay_input, silt_input,
+			  cls_clay[0].sand, cls_clay[0].clay,
+			  cls_clay[0].silt, cls_clay[3].sand,
+			  cls_clay[3].clay, cls_clay[3].silt,
+			  cls_clay[4].sand, cls_clay[4].clay,
+			  cls_clay[4].silt);
+    /* G_message("Clay: mark[0]=%f",mark[0]); */
+    /* G_message("Clay: mark[1]=%f",mark[1]); */
+    /* G_message("Clay: mark[2]=%f",mark[2]); */
+    if (mark[0] == 1 || mark[1] == 1 || mark[2] == 1) {
+	index = 0;
+	/* G_message("Clay: index labelled as 0"); */
+    }
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 1 */
+	cls_sandy_clay[0].sand = 50.0;
+	cls_sandy_clay[0].clay = 50.0;
+	cls_sandy_clay[0].silt = 0.0;
+	cls_sandy_clay[1].sand = 50.0;
+	cls_sandy_clay[1].clay = 35.0;
+	cls_sandy_clay[1].silt = 15.0;
+	cls_sandy_clay[2].sand = 65.0;
+	cls_sandy_clay[2].clay = 35.0;
+	cls_sandy_clay[2].silt = 0.0;
+	/* Check for index 1 */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_clay[0].sand, cls_sandy_clay[0].clay,
+			      cls_sandy_clay[0].silt, cls_sandy_clay[1].sand,
+			      cls_sandy_clay[1].clay, cls_sandy_clay[1].silt,
+			      cls_sandy_clay[2].sand, cls_sandy_clay[2].clay,
+			      cls_sandy_clay[2].silt);
+
+	/* G_message("Sandy Clay: mark[0]=%f",mark[0]); */
+	if (mark[0] == 1) {
+	    index = 1;
+	    /* G_message("Sandy Clay: index labelled as 1"); */
+	}
+    }
+    if (index == 20) {		/* if index not found then continue */
+	/*Feed the polygons for index 2 */
+	cls_silty_clay[0].sand = 0.0;
+	cls_silty_clay[0].clay = 60.0;
+	cls_silty_clay[0].silt = 40.0;
+	cls_silty_clay[1].sand = 0.0;
+	cls_silty_clay[1].clay = 40.0;
+	cls_silty_clay[1].silt = 60.0;
+	cls_silty_clay[2].sand = 20.0;
+	cls_silty_clay[2].clay = 40.0;
+	cls_silty_clay[2].silt = 40.0;
+	/* Check for index 2 */
+	/* G_message("sand=%5.3f||clay=%5.3f||silt=%5.3f",sand_input,
+				clay_input,silt_input); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silty_clay[0].sand, cls_silty_clay[0].clay,
+			      cls_silty_clay[0].silt, cls_silty_clay[1].sand,
+			      cls_silty_clay[1].clay, cls_silty_clay[1].silt,
+			      cls_silty_clay[2].sand, cls_silty_clay[2].clay,
+			      cls_silty_clay[2].silt);
+
+	/* G_message("Silty Clay: mark[0]=%f",mark[0]); */
+	if (mark[0] == 1) {
+	    index = 2;
+	    /* G_message("Silty Clay: index labelled as 2"); */
+	}
+    }
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 3 */
+	cls_sandy_clay_loam[0].sand = 65.0;
+	cls_sandy_clay_loam[0].clay = 35.0;
+	cls_sandy_clay_loam[0].silt = 0.0;
+	cls_sandy_clay_loam[1].sand = 50.0;
+	cls_sandy_clay_loam[1].clay = 35.0;
+	cls_sandy_clay_loam[1].silt = 15.0;
+	cls_sandy_clay_loam[2].sand = 50.0;
+	cls_sandy_clay_loam[2].clay = 30.0;
+	cls_sandy_clay_loam[2].silt = 20.0;
+	cls_sandy_clay_loam[3].sand = 55.0;
+	cls_sandy_clay_loam[3].clay = 25.0;
+	cls_sandy_clay_loam[3].silt = 20.0;
+	cls_sandy_clay_loam[4].sand = 75.0;
+	cls_sandy_clay_loam[4].clay = 25.0;
+	cls_sandy_clay_loam[4].silt = 0.0;
+	/* Check for index 0 */
+	/* G_message("in prct2tex(): check for index 3"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_clay_loam[0].sand,
+			      cls_sandy_clay_loam[0].clay,
+			      cls_sandy_clay_loam[0].silt,
+			      cls_sandy_clay_loam[1].sand,
+			      cls_sandy_clay_loam[1].clay,
+			      cls_sandy_clay_loam[1].silt,
+			      cls_sandy_clay_loam[2].sand,
+			      cls_sandy_clay_loam[2].clay,
+			      cls_sandy_clay_loam[2].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_clay_loam[0].sand,
+			      cls_sandy_clay_loam[0].clay,
+			      cls_sandy_clay_loam[0].silt,
+			      cls_sandy_clay_loam[2].sand,
+			      cls_sandy_clay_loam[2].clay,
+			      cls_sandy_clay_loam[2].silt,
+			      cls_sandy_clay_loam[3].sand,
+			      cls_sandy_clay_loam[3].clay,
+			      cls_sandy_clay_loam[3].silt);
+	mark[2] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_clay_loam[0].sand,
+			      cls_sandy_clay_loam[0].clay,
+			      cls_sandy_clay_loam[0].silt,
+			      cls_sandy_clay_loam[3].sand,
+			      cls_sandy_clay_loam[3].clay,
+			      cls_sandy_clay_loam[3].silt,
+			      cls_sandy_clay_loam[4].sand,
+			      cls_sandy_clay_loam[4].clay,
+			      cls_sandy_clay_loam[4].silt);
+	/* G_message("Sandy Clay Loam: mark[0]=%f",mark[0]); */
+	/* G_message("Sandy Clay Loam: mark[1]=%f",mark[1]); */
+	/* G_message("Sandy Clay Loam: mark[2]=%f",mark[2]); */
+	if (mark[0] == 1 || mark[1] == 1 || mark[2] == 1) {
+	    index = 3;
+	    /* G_message("Sandy Clay Loam: index labelled as 3"); */
+	}
+    }
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 4 */
+	cls_clay_loam[0].sand = 20.0;
+	cls_clay_loam[0].clay = 40.0;
+	cls_clay_loam[0].silt = 40.0;
+	cls_clay_loam[1].sand = 20.0;
+	cls_clay_loam[1].clay = 30.0;
+	cls_clay_loam[1].silt = 50.0;
+	cls_clay_loam[2].sand = 50.0;
+	cls_clay_loam[2].clay = 30.0;
+	cls_clay_loam[2].silt = 20.0;
+	cls_clay_loam[3].sand = 10.0;
+	cls_clay_loam[3].clay = 50.0;
+	cls_clay_loam[3].silt = 40.0;
+	/* Check for index 4 */
+	/* G_message("in prct2tex(): check for index 4"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_clay_loam[0].sand, cls_clay_loam[0].clay,
+			      cls_clay_loam[0].silt, cls_clay_loam[1].sand,
+			      cls_clay_loam[1].clay, cls_clay_loam[1].silt,
+			      cls_clay_loam[2].sand, cls_clay_loam[2].clay,
+			      cls_clay_loam[2].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_clay_loam[0].sand, cls_clay_loam[0].clay,
+			      cls_clay_loam[0].silt, cls_clay_loam[2].sand,
+			      cls_clay_loam[2].clay, cls_clay_loam[2].silt,
+			      cls_clay_loam[3].sand, cls_clay_loam[3].clay,
+			      cls_clay_loam[3].silt);
+	/* G_message("Clay Loam: mark[0]=%f",mark[0]); */
+	/* G_message("Clay Loam: mark[1]=%f",mark[1]); */
+	if (mark[0] == 1 || mark[1] == 1) {
+	    index = 4;
+	    /* G_message("Clay Loam: index labelled as 4"); */
+	}
+    }
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 5 */
+	cls_silty_clay_loam[0].sand = 0.0;
+	cls_silty_clay_loam[0].clay = 40.0;
+	cls_silty_clay_loam[0].silt = 60.0;
+	cls_silty_clay_loam[1].sand = 0.0;
+	cls_silty_clay_loam[1].clay = 30.0;
+	cls_silty_clay_loam[1].silt = 70.0;
+	cls_silty_clay_loam[2].sand = 20.0;
+	cls_silty_clay_loam[2].clay = 30.0;
+	cls_silty_clay_loam[2].silt = 50.0;
+	cls_silty_clay_loam[3].sand = 20.0;
+	cls_silty_clay_loam[3].clay = 40.0;
+	cls_silty_clay_loam[3].silt = 40.0;
+	/* Check for index 5 */
+	/* G_message("in prct2tex(): check for index 5"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silty_clay_loam[0].sand,
+			      cls_silty_clay_loam[0].clay,
+			      cls_silty_clay_loam[0].silt,
+			      cls_silty_clay_loam[1].sand,
+			      cls_silty_clay_loam[1].clay,
+			      cls_silty_clay_loam[1].silt,
+			      cls_silty_clay_loam[2].sand,
+			      cls_silty_clay_loam[2].clay,
+			      cls_silty_clay_loam[2].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silty_clay_loam[0].sand,
+			      cls_silty_clay_loam[0].clay,
+			      cls_silty_clay_loam[0].silt,
+			      cls_silty_clay_loam[2].sand,
+			      cls_silty_clay_loam[2].clay,
+			      cls_silty_clay_loam[2].silt,
+			      cls_silty_clay_loam[3].sand,
+			      cls_silty_clay_loam[3].clay,
+			      cls_silty_clay_loam[3].silt);
+	/* G_message("Silty Clay Loam: mark[0]=%f",mark[0]); */
+	/* G_message("Silty Clay Loam: mark[1]=%f",mark[1]); */
+	if (mark[0] == 1 || mark[1] == 1) {
+	    index = 5;
+	    /* G_message("Silty Clay Loam: index labelled as 5"); */
+	}
+    }
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 6 */
+	cls_sand[0].sand = 85.0;
+	cls_sand[0].clay = 15.0;
+	cls_sand[0].silt = 0.0;
+	cls_sand[1].sand = 85.0;
+	cls_sand[1].clay = 0.0;
+	cls_sand[1].silt = 15.0;
+	cls_sand[2].sand = 100.0;
+	cls_sand[2].clay = 0.0;
+	cls_sand[2].silt = 0.0;
+	/* Check for index 6 */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sand[0].sand, cls_sand[0].clay,
+			      cls_sand[0].silt, cls_sand[1].sand,
+			      cls_sand[1].clay, cls_sand[1].silt,
+			      cls_sand[2].sand, cls_sand[2].clay,
+			      cls_sand[2].silt);
+	/* G_message("Sand: mark[0]=%f",mark[0]); */
+	if (mark[0] == 1) {
+	    index = 6;
+	    /* G_message("Sand: index labelled as 6"); */
+	}
+    }
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 7 */
+	cls_loamy_sand[0].sand = 80.0;
+	cls_loamy_sand[0].clay = 20.0;
+	cls_loamy_sand[0].silt = 0.0;
+	cls_loamy_sand[1].sand = 70.0;
+	cls_loamy_sand[1].clay = 0.0;
+	cls_loamy_sand[1].silt = 30.0;
+	cls_loamy_sand[2].sand = 85.0;
+	cls_loamy_sand[2].clay = 0.0;
+	cls_loamy_sand[2].silt = 15.0;
+	cls_loamy_sand[3].sand = 85.0;
+	cls_loamy_sand[3].clay = 15.0;
+	cls_loamy_sand[3].silt = 0.0;
+	/* Check for index 7 */
+	/* G_message("in prct2tex(): check for index 7"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_loamy_sand[0].sand, cls_loamy_sand[0].clay,
+			      cls_loamy_sand[0].silt, cls_loamy_sand[1].sand,
+			      cls_loamy_sand[1].clay, cls_loamy_sand[1].silt,
+			      cls_loamy_sand[2].sand, cls_loamy_sand[2].clay,
+			      cls_loamy_sand[2].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_loamy_sand[0].sand, cls_loamy_sand[0].clay,
+			      cls_loamy_sand[0].silt, cls_loamy_sand[2].sand,
+			      cls_loamy_sand[2].clay, cls_loamy_sand[2].silt,
+			      cls_loamy_sand[3].sand, cls_loamy_sand[3].clay,
+			      cls_loamy_sand[3].silt);
+	/* G_message("Loamy Sand: mark[0]=%f",mark[0]); */
+	/* G_message("Loamy Sand: mark[1]=%f",mark[1]); */
+	if (mark[0] == 1 || mark[1] == 1) {
+	    index = 7;
+	    /* G_message("Loamy Sand: index labelled as 7"); */
+	}
+    }
+
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 8 */
+	cls_sandy_loam[0].sand = 75.0;
+	cls_sandy_loam[0].clay = 25.0;
+	cls_sandy_loam[0].silt = 0.0;
+	cls_sandy_loam[1].sand = 55.0;
+	cls_sandy_loam[1].clay = 25.0;
+	cls_sandy_loam[1].silt = 20.0;
+	cls_sandy_loam[2].sand = 55.0;
+	cls_sandy_loam[2].clay = 10.0;
+	cls_sandy_loam[2].silt = 35.0;
+	cls_sandy_loam[3].sand = 40.0;
+	cls_sandy_loam[3].clay = 10.0;
+	cls_sandy_loam[3].silt = 50.0;
+	cls_sandy_loam[4].sand = 50.0;
+	cls_sandy_loam[4].clay = 0.0;
+	cls_sandy_loam[4].silt = 50.0;
+	cls_sandy_loam[5].sand = 70.0;
+	cls_sandy_loam[5].clay = 0.0;
+	cls_sandy_loam[5].silt = 30.0;
+	cls_sandy_loam[6].sand = 80.0;
+	cls_sandy_loam[6].clay = 20.0;
+	cls_sandy_loam[6].silt = 0.0;
+	/* Check for index 8 */
+	/* G_message("in prct2tex(): check for index 8"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_loam[2].sand, cls_sandy_loam[2].clay,
+			      cls_sandy_loam[2].silt, cls_sandy_loam[3].sand,
+			      cls_sandy_loam[3].clay, cls_sandy_loam[3].silt,
+			      cls_sandy_loam[4].sand, cls_sandy_loam[4].clay,
+			      cls_sandy_loam[4].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_loam[2].sand, cls_sandy_loam[2].clay,
+			      cls_sandy_loam[2].silt, cls_sandy_loam[4].sand,
+			      cls_sandy_loam[4].clay, cls_sandy_loam[4].silt,
+			      cls_sandy_loam[5].sand, cls_sandy_loam[5].clay,
+			      cls_sandy_loam[5].silt);
+	mark[2] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_loam[2].sand, cls_sandy_loam[2].clay,
+			      cls_sandy_loam[2].silt, cls_sandy_loam[5].sand,
+			      cls_sandy_loam[5].clay, cls_sandy_loam[5].silt,
+			      cls_sandy_loam[6].sand, cls_sandy_loam[6].clay,
+			      cls_sandy_loam[6].silt);
+	mark[3] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_loam[2].sand, cls_sandy_loam[2].clay,
+			      cls_sandy_loam[2].silt, cls_sandy_loam[6].sand,
+			      cls_sandy_loam[6].clay, cls_sandy_loam[6].silt,
+			      cls_sandy_loam[0].sand, cls_sandy_loam[0].clay,
+			      cls_sandy_loam[0].silt);
+	mark[4] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_sandy_loam[2].sand, cls_sandy_loam[2].clay,
+			      cls_sandy_loam[2].silt, cls_sandy_loam[0].sand,
+			      cls_sandy_loam[0].clay, cls_sandy_loam[0].silt,
+			      cls_sandy_loam[1].sand, cls_sandy_loam[1].clay,
+			      cls_sandy_loam[1].silt);
+	/* G_message("Sandy Loam: mark[0]=%f",mark[0]); */
+	/* G_message("Sandy Loam: mark[1]=%f",mark[1]); */
+	if (mark[0] == 1 || mark[1] == 1 || mark[2] == 1 || mark[3] == 1 ||
+	    mark[4] == 1) {
+	    index = 8;
+	    /* G_message("Sandy Loam: index labelled as 8"); */
+	}
+    }
+
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 9 */
+	cls_loam[0].sand = 50.0;
+	cls_loam[0].clay = 30.0;
+	cls_loam[0].silt = 20.0;
+	cls_loam[1].sand = 20.0;
+	cls_loam[1].clay = 30.0;
+	cls_loam[1].silt = 50.0;
+	cls_loam[2].sand = 40.0;
+	cls_loam[2].clay = 10.0;
+	cls_loam[2].silt = 50.0;
+	cls_loam[3].sand = 55.0;
+	cls_loam[3].clay = 10.0;
+	cls_loam[3].silt = 35.0;
+	cls_loam[4].sand = 55.0;
+	cls_loam[4].clay = 25.0;
+	cls_loam[4].silt = 15.0;
+	/* Check for index 9 */
+	/* G_message("in prct2tex(): check for index 9"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_loam[0].sand, cls_loam[0].clay,
+			      cls_loam[0].silt, cls_loam[1].sand,
+			      cls_loam[1].clay, cls_loam[1].silt,
+			      cls_loam[2].sand, cls_loam[2].clay,
+			      cls_loam[2].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_loam[0].sand, cls_loam[0].clay,
+			      cls_loam[0].silt, cls_loam[2].sand,
+			      cls_loam[2].clay, cls_loam[2].silt,
+			      cls_loam[3].sand, cls_loam[3].clay,
+			      cls_loam[3].silt);
+	mark[2] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_loam[0].sand, cls_loam[0].clay,
+			      cls_loam[0].silt, cls_loam[3].sand,
+			      cls_loam[3].clay, cls_loam[3].silt,
+			      cls_loam[4].sand, cls_loam[4].clay,
+			      cls_loam[4].silt);
+	/* G_message("Sandy Loam: mark[0]=%f",mark[0]); */
+	/* G_message("Sandy Loam: mark[1]=%f",mark[1]); */
+	if (mark[0] == 1 || mark[1] == 1 || mark[2] == 1) {
+	    index = 9;
+	    /* G_message("Loam: index labelled as 9"); */
+	}
+    }
+
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 10 */
+	cls_silt_loam[0].sand = 20.0;
+	cls_silt_loam[0].clay = 30.0;
+	cls_silt_loam[0].silt = 50.0;
+	cls_silt_loam[1].sand = 0.0;
+	cls_silt_loam[1].clay = 30.0;
+	cls_silt_loam[1].silt = 70.0;
+	cls_silt_loam[2].sand = 0.0;
+	cls_silt_loam[2].clay = 10.0;
+	cls_silt_loam[2].silt = 90.0;
+	cls_silt_loam[3].sand = 15.0;
+	cls_silt_loam[3].clay = 10.0;
+	cls_silt_loam[3].silt = 75.0;
+	cls_silt_loam[4].sand = 25.0;
+	cls_silt_loam[4].clay = 0.0;
+	cls_silt_loam[4].silt = 75.0;
+	cls_silt_loam[5].sand = 50.0;
+	cls_silt_loam[5].clay = 0.0;
+	cls_silt_loam[5].silt = 50.0;
+	/* Check for index 10 */
+	/* G_message("in prct2tex(): check for index 10"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silt_loam[3].sand, cls_silt_loam[3].clay,
+			      cls_silt_loam[3].silt, cls_silt_loam[4].sand,
+			      cls_silt_loam[4].clay, cls_silt_loam[4].silt,
+			      cls_silt_loam[5].sand, cls_silt_loam[5].clay,
+			      cls_silt_loam[5].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silt_loam[3].sand, cls_silt_loam[3].clay,
+			      cls_silt_loam[3].silt, cls_silt_loam[5].sand,
+			      cls_silt_loam[5].clay, cls_silt_loam[5].silt,
+			      cls_silt_loam[0].sand, cls_silt_loam[0].clay,
+			      cls_silt_loam[0].silt);
+	mark[2] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silt_loam[3].sand, cls_silt_loam[3].clay,
+			      cls_silt_loam[3].silt, cls_silt_loam[0].sand,
+			      cls_silt_loam[0].clay, cls_silt_loam[0].silt,
+			      cls_silt_loam[1].sand, cls_silt_loam[1].clay,
+			      cls_silt_loam[1].silt);
+	mark[3] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silt_loam[3].sand, cls_silt_loam[3].clay,
+			      cls_silt_loam[3].silt, cls_silt_loam[1].sand,
+			      cls_silt_loam[1].clay, cls_silt_loam[1].silt,
+			      cls_silt_loam[2].sand, cls_silt_loam[2].clay,
+			      cls_silt_loam[2].silt);
+	/* G_message("Silt Loam: mark[0]=%f",mark[0]); */
+	/* G_message("Silt Loam: mark[1]=%f",mark[1]); */
+	/* G_message("Silt Loam: mark[2]=%f",mark[2]); */
+	/* G_message("Silt Loam: mark[3]=%f",mark[3]); */
+	if (mark[0] == 1 || mark[1] == 1 || mark[2] == 1 || mark[3] == 1) {
+	    index = 10;
+	    /* G_message("Silt Loam: index labelled as 10"); */
+	}
+    }
+
+    if (index == 20) {	/* if index not found then continue */
+	/*Feed the polygons for index 11 */
+	cls_silt[0].sand = 15.0;
+	cls_silt[0].clay = 10.0;
+	cls_silt[0].silt = 75.0;
+	cls_silt[1].sand = 0.0;
+	cls_silt[1].clay = 10.0;
+	cls_silt[1].silt = 90.0;
+	cls_silt[2].sand = 0.0;
+	cls_silt[2].clay = 0.0;
+	cls_silt[2].silt = 100.0;
+	cls_silt[3].sand = 25.0;
+	cls_silt[3].clay = 0.0;
+	cls_silt[3].silt = 75.0;
+	/* Check for index 11 */
+	/* G_message("in prct2tex(): check for index 11"); */
+	mark[0] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silt[0].sand, cls_silt[0].clay,
+			      cls_silt[0].silt, cls_silt[1].sand,
+			      cls_silt[1].clay, cls_silt[1].silt,
+			      cls_silt[2].sand, cls_silt[2].clay,
+			      cls_silt[2].silt);
+	mark[1] =
+	    point_in_triangle(sand_input, clay_input, silt_input,
+			      cls_silt[0].sand, cls_silt[0].clay,
+			      cls_silt[0].silt, cls_silt[2].sand,
+			      cls_silt[2].clay, cls_silt[2].silt,
+			      cls_silt[3].sand, cls_silt[3].clay,
+			      cls_silt[3].silt);
+	/* G_message("Silt: mark[0]=%f",mark[0]); */
+	/* G_message("Silt: mark[1]=%f",mark[1]); */
+	if (mark[0] == 1 || mark[1] == 1) {
+	    index = 11;
+	    /* G_message("Silt: index labelled as 11"); */
+	}
+    }
+    /* if(index==0){
+       G_message("clay");
+       } else if (index==1){
+       G_message("sandy clay");
+       } else if (index==2){
+       G_message("silty clay");
+       } else if (index==3){
+       G_message("sandy clay loam");
+       } else if (index==4){
+       G_message("clay loam");
+       } else if (index==5){
+       G_message("silty clay loam");
+       } else if (index==6){
+       G_message("sand");
+       } else if (index==7){
+       G_message("loamy sand");
+       } else if (index==8){
+       G_message("sandy loam");
+       } else if (index==9){
+       G_message("loam");
+       } else if (index==10){
+       G_message("silt loam");
+       } else if (index==11){
+       G_message("silt");
+       } else {
+       G_message("Unable to allocate class");
+       } */
+    return index;
+}

Added: grass/trunk/raster/r.uslek/r.uslek.html
===================================================================
--- grass/trunk/raster/r.uslek/r.uslek.html	                        (rev 0)
+++ grass/trunk/raster/r.uslek/r.uslek.html	2008-10-11 15:17:18 UTC (rev 33815)
@@ -0,0 +1,25 @@
+<H2>DESCRIPTION</H2>
+
+<EM>r.uslek</EM> calculates the USLE K factor, that is the Soil Erodibility Factor.
+It takes input of soil texture classes (sand, clay, silt) and organic matter, all in range of [0.0-1.0]. The FAO World Soil CD documentation was used to produce the conversion system between soil textures and soil classes. The soil classes are in number of 12 and apparently come from a USDA publication of 1951 (p.209). Once the soil classes have been identified (by vector cross-products tests), a general conversion table was applied for transforming soil classes into K factor.
+
+<H2>NOTES</H2>
+
+
+<H2>TODO</H2>
+
+
+<H2>SEE ALSO</H2>
+
+<em>
+<A HREF="r.watershed.html">r.watershed</A><br>
+</em>
+
+
+<H2>AUTHORS</H2>
+
+Yann Chemin, SIC-ISDC, Turkmenistan<BR>
+
+
+<p>
+<i>Last changed: $Date: 2006/09/31 15:20:43 $</i>

Added: grass/trunk/raster/r.uslek/tex2usle_k.c
===================================================================
--- grass/trunk/raster/r.uslek/tex2usle_k.c	                        (rev 0)
+++ grass/trunk/raster/r.uslek/tex2usle_k.c	2008-10-11 15:17:18 UTC (rev 33815)
@@ -0,0 +1,151 @@
+#include<stdio.h>
+
+/* From FAOSOIL CD, after USDA 1951, p209 */
+
+double tex2usle_k(int texture, double om_in)
+{
+    double usle_k = 200.0; /* Initial value */
+
+    /*G_message("texture=%i, om=%5.3f",texture, om_in); */
+    if (om_in < 0.5) {
+	if (texture == 0) /* G_message("clay"); */
+	    usle_k = 0.29;	/*Took max value @0.2 */
+	else if (texture == 1) /* G_message("sandy clay"); */
+	    usle_k = 0.14;
+	else if (texture == 2) /* G_message("silty clay"); */
+	    usle_k = 0.25;
+	else if (texture == 3) /* G_message("sandy clay loam"); */
+	    usle_k = 0.27;
+	else if (texture == 4) /* G_message("clay loam"); */
+	    usle_k = 0.28;
+	else if (texture == 5) /* G_message("silty clay loam"); */
+	    usle_k = 0.37;
+	else if (texture == 6) /* G_message("sand"); */
+	    usle_k = 0.05;
+	else if (texture == 7) /* G_message("loamy sand"); */
+	    usle_k = 0.12;
+	else if (texture == 8) /* G_message("sandy loam"); */
+	    usle_k = 0.27;
+	else if (texture == 9) /* G_message("loam"); */
+	    usle_k = 0.38;
+	else if (texture == 10) /* G_message("silt loam"); */
+	    usle_k = 0.48;
+	else if (texture == 11) /* G_message("silt"); */
+	    usle_k = 0.60;
+	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) {
+	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"); */
+	    usle_k = 0.135;
+	else if (texture == 2) /* G_message("silty clay"); */
+	    usle_k = 0.24;
+	else if (texture == 3) /* G_message("sandy clay loam"); */
+	    usle_k = 0.26;
+	else if (texture == 4) /* G_message("clay loam"); */
+	    usle_k = 0.265;
+	else if (texture == 5) /* G_message("silty clay loam"); */
+	    usle_k = 0.345;
+	else if (texture == 6) /* G_message("sand"); */
+	    usle_k = 0.04;
+	else if (texture == 7) /* G_message("loamy sand"); */
+	    usle_k = 0.11;
+	else if (texture == 8) /* G_message("sandy loam"); */
+	    usle_k = 0.255;
+	else if (texture == 9) /* G_message("loam"); */
+	    usle_k = 0.36;
+	else if (texture == 10) /* G_message("silt loam"); */
+	    usle_k = 0.45;
+	else if (texture == 11) /* G_message("silt"); */
+	    usle_k = 0.56;
+	else /*G_message("Unable to allocate class"); */
+	    usle_k = 500.0;/*change value to show it was processed */
+    }
+    else if (om_in == 0.2) {
+	if (texture == 0) /* G_message("clay"); */
+	    usle_k = 0.22; /*Range=[0.13-0.29]@0.2, took average */
+	else if (texture == 1) /* G_message("sandy clay"); */
+	    usle_k = 0.13;
+	else if (texture == 2) /* G_message("silty clay"); */
+	    usle_k = 0.23;
+	else if (texture == 3) /* G_message("sandy clay loam"); */
+	    usle_k = 0.25;
+	else if (texture == 4) /* G_message("clay loam"); */
+	    usle_k = 0.25;
+	else if (texture == 5) /* G_message("silty clay loam"); */
+	    usle_k = 0.32;
+	else if (texture == 6) /* G_message("sand"); */
+	    usle_k = 0.03;
+	else if (texture == 7) /* G_message("loamy sand"); */
+	    usle_k = 0.10;
+	else if (texture == 8) /* G_message("sandy loam"); */
+	    usle_k = 0.24;
+	else if (texture == 9) /* G_message("loam"); */
+	    usle_k = 0.34;
+	else if (texture == 10) /* G_message("silt loam"); */
+	    usle_k = 0.42;
+	else if (texture == 11) /* G_message("silt"); */
+	    usle_k = 0.52;
+	else /*G_message("Unable to allocate class"); */
+	    usle_k = 500.0;/*change value to show it was processed */
+    }
+    else if (om_in > 0.2 && om_in < 0.4) {
+	if (texture == 0) /* G_message("clay"); */
+	    usle_k = 0.13;	/*Range=[0.13-0.29]@0.2, took min */
+	else if (texture == 1) /* G_message("sandy clay"); */
+	    usle_k = 0.125;
+	else if (texture == 2) /* G_message("silty clay"); */
+	    usle_k = 0.21;
+	else if (texture == 3) /* G_message("sandy clay loam"); */
+	    usle_k = 0.23;
+	else if (texture == 4) /* G_message("clay loam"); */
+	    usle_k = 0.23;
+	else if (texture == 5) /* G_message("silty clay loam"); */
+	    usle_k = 0.29;
+	else if (texture == 6) /* G_message("sand"); */
+	    usle_k = 0.025;
+	else if (texture == 7) /* G_message("loamy sand"); */
+	    usle_k = 0.09;
+	else if (texture == 8) /* G_message("sandy loam"); */
+	    usle_k = 0.215;
+	else if (texture == 9) /* G_message("loam"); */
+	    usle_k = 0.325;
+	else if (texture == 10) /* G_message("silt loam"); */
+	    usle_k = 0.375;
+	else if (texture == 11) /* G_message("silt"); */
+	    usle_k = 0.47;
+	else /*G_message("Unable to allocate class"); */
+	    usle_k = 500.0;/*change value to show it was processed */
+    }
+    else if (om_in >= 0.4) {/*May not be right (>4), no other data */
+	if (texture == 0) /* G_message("clay\n"); */
+	    usle_k = 0.13; /*took from value min @0.2 (table empty)*/
+	else if (texture == 1) /* G_message("sandy clay\n"); */
+	    usle_k = 0.12;
+	else if (texture == 2) /* G_message("silty clay\n"); */
+	    usle_k = 0.19;
+	else if (texture == 3) /* G_message("sandy clay loam\n"); */
+	    usle_k = 0.21;
+	else if (texture == 4) /* G_message("clay loam\n"); */
+	    usle_k = 0.21;
+	else if (texture == 5) /* G_message("silty clay loam\n"); */
+	    usle_k = 0.26;
+	else if (texture == 6) /* G_message("sand\n"); */
+	    usle_k = 0.02;
+	else if (texture == 7) /* G_message("loamy sand\n"); */
+	    usle_k = 0.08;
+	else if (texture == 8) /* G_message("sandy loam\n"); */
+	    usle_k = 0.19;
+	else if (texture == 9) /* G_message("loam\n"); */
+	    usle_k = 0.29;
+	else if (texture == 10) /* G_message("silt loam\n"); */
+	    usle_k = 0.33;
+	else if (texture == 11) /* G_message("silt\n"); */
+	    usle_k = 0.42;
+	else /*G_message("Unable to allocate class"); */
+	    usle_k = 500.0;/*change value to show it was processed */
+    }
+    return usle_k;
+}



More information about the grass-commit mailing list