[GRASS-SVN] r33811 - grass-addons/gipe/r.uslek

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 10 20:59:22 EDT 2008


Author: ychemin
Date: 2008-10-10 20:59:22 -0400 (Fri, 10 Oct 2008)
New Revision: 33811

Added:
   grass-addons/gipe/r.uslek/r.uslek.html
Removed:
   grass-addons/gipe/r.uslek/description.html
   grass-addons/gipe/r.uslek/prct2tex.h
   grass-addons/gipe/r.uslek/tex2usle_k.h
Modified:
   grass-addons/gipe/r.uslek/main.c
Log:
preparing r.uslek to main SVN

Deleted: grass-addons/gipe/r.uslek/description.html
===================================================================
--- grass-addons/gipe/r.uslek/description.html	2008-10-10 14:48:46 UTC (rev 33810)
+++ grass-addons/gipe/r.uslek/description.html	2008-10-11 00:59:22 UTC (rev 33811)
@@ -1,23 +0,0 @@
-<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 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>

Modified: grass-addons/gipe/r.uslek/main.c
===================================================================
--- grass-addons/gipe/r.uslek/main.c	2008-10-10 14:48:46 UTC (rev 33810)
+++ grass-addons/gipe/r.uslek/main.c	2008-10-11 00:59:22 UTC (rev 33811)
@@ -21,258 +21,145 @@
 #include <string.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
-#include "prct2tex.h"
-#include "tex2usle_k.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[]) 
 {
-    struct Cell_head cellhd;	/*region+header info */
-
-    char *mapset;		/*mapset name */
-
     int nrows, ncols;
-
     int row, col;
-
     struct GModule *module;
-
     struct Option *input1, *input2, *input3, *input4, *output1;
-
     struct History history;	/*metadata */
 
-    
-
-	/************************************/ 
-	/* FMEO Declarations**************** */ 
-    char *name;			/* input raster name */
-
     char *result;		/*output raster name */
-
-    
-	/*File Descriptors */ 
     int infd_psand, infd_psilt, infd_pclay, infd_pomat;
-
     int outfd;
-
     char *psand, *psilt, *pclay, *pomat;
-
-    int i = 0, j = 0;
-
+    int i = 0;
     void *inrast_psand, *inrast_psilt, *inrast_pclay, *inrast_pomat;
-
-    DCELL * outrast;
-    RASTER_MAP_TYPE data_type_output = DCELL_TYPE;
-    RASTER_MAP_TYPE data_type_psand;
-    RASTER_MAP_TYPE data_type_psilt;
-    RASTER_MAP_TYPE data_type_pclay;
-    RASTER_MAP_TYPE data_type_pomat;
+    DCELL *outrast;
     
-
-	/************************************/ 
-	G_gisinit(argv[0]);
+    /************************************/ 
+    G_gisinit(argv[0]);
     module = G_define_module();
-    module->keywords = _("USLE, soil, erosion");
+    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);
+    /* 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]");
-    input1->answer = _("psand");
+
     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]");
-    input2->answer = _("pclay");
+
     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]");
-    input3->answer = _("psilt");
+
     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]");
-    input4->answer = _("pomat");
+
     output1 = G_define_standard_option(G_OPT_R_OUTPUT);
     output1->key = _("usle_k");
     output1->description = _("Name of the output USLE K factor layer");
-    output1->answer = _("usle_k");
-    
 
-	/********************/ 
-	if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+    /********************/ 
+    if (G_parser(argc, argv))
+        exit(EXIT_FAILURE);
+
     psand = input1->answer;
     pclay = input2->answer;
     psilt = input3->answer;
     pomat = input4->answer;
     result = output1->answer;
     
-
-	/***************************************************/ 
-	mapset = G_find_cell2(psand, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("cell file [%s] not found"), psand);
-    }
-    data_type_psand = G_raster_map_type(psand, mapset);
-    if ((infd_psand = G_open_cell_old(psand, mapset)) < 0)
+    /***************************************************/ 
+    if ((infd_psand = G_open_cell_old(psand, "")) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), psand);
-    if (G_get_cellhd(psand, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s])"), psand);
-    inrast_psand = G_allocate_raster_buf(data_type_psand);
+    inrast_psand = G_allocate_d_raster_buf();
     
-
-	/***************************************************/ 
-	mapset = G_find_cell2(psilt, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("cell file [%s] not found"), psilt);
-    }
-    data_type_psilt = G_raster_map_type(psilt, mapset);
-    if ((infd_psilt = G_open_cell_old(psilt, mapset)) < 0)
+    if ((infd_psilt = G_open_cell_old(psilt, "")) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), psilt);
-    if (G_get_cellhd(psilt, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s]"), psilt);
-    inrast_psilt = G_allocate_raster_buf(data_type_psilt);
+    inrast_psilt = G_allocate_d_raster_buf();
     
-
-	/***************************************************/ 
-	mapset = G_find_cell2(pclay, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("Cell file [%s] not found"), pclay);
-    }
-    data_type_pclay = G_raster_map_type(pclay, mapset);
-    if ((infd_pclay = G_open_cell_old(pclay, mapset)) < 0)
+    if ((infd_pclay = G_open_cell_old(pclay, "")) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), pclay);
-    if (G_get_cellhd(pclay, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s]"), pclay);
-    inrast_pclay = G_allocate_raster_buf(data_type_pclay);
+    inrast_pclay = G_allocate_d_raster_buf();
     
-
-	/***************************************************/ 
-	mapset = G_find_cell2(pomat, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("Cell file [%s] not found"), pomat);
-    }
-    data_type_pomat = G_raster_map_type(pomat, mapset);
-    if ((infd_pomat = G_open_cell_old(pomat, mapset)) < 0)
+    if ((infd_pomat = G_open_cell_old(pomat, "")) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), pomat);
-    if (G_get_cellhd(pomat, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s]"), pomat);
-    inrast_pomat = G_allocate_raster_buf(data_type_pomat);
-    
-
-	/***************************************************/ 
-	G_debug(3, "number of rows %d", cellhd.rows);
+    inrast_pomat = G_allocate_d_raster_buf();
+    /***************************************************/ 
     nrows = G_window_rows();
     ncols = G_window_cols();
-    outrast = G_allocate_raster_buf(data_type_output);
+    outrast = G_allocate_d_raster_buf();
     
-	/* Create New raster files */ 
-	if ((outfd = G_open_raster_new(result, data_type_output)) < 0)
+    /* 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++)
-	 {
+    /* Process pixels */ 
+    for (row = 0; row < nrows; row++)
+    {
 	DCELL d;
 	DCELL d_sand;
 	DCELL d_clay;
 	DCELL d_silt;
 	DCELL d_om;
-	double tex[4] = { 0.0, 0.0, 0.0, 0.0 };
 	G_percent(row, nrows, 2);
 	
-	    /* read soil input maps */ 
-	    if (G_get_raster_row
-		(infd_psand, inrast_psand, row, data_type_psand) < 0)
+	/* 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_raster_row(infd_psilt, inrast_psilt, row, data_type_psilt)
-	     < 0)
+	if (G_get_d_raster_row(infd_psilt, inrast_psilt, row) < 0)
 	    G_fatal_error(_("Could not read from <%s>"), psilt);
-	if (G_get_raster_row(infd_pclay, inrast_pclay, row, data_type_pclay)
-	     < 0)
+	if (G_get_d_raster_row(infd_pclay, inrast_pclay, row) < 0)
 	    G_fatal_error(_("Could not read from <%s>"), pclay);
-	if (G_get_raster_row(infd_pomat, inrast_pomat, row, data_type_pomat)
-	     < 0)
+	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++)
-	     {
-	    switch (data_type_psand) {
-	    case CELL_TYPE:
-		d_sand = (double)((CELL *) inrast_psand)[col];
-		break;
-	    case FCELL_TYPE:
-		d_sand = (double)((FCELL *) inrast_psand)[col];
-		break;
-	    case DCELL_TYPE:
-		d_sand = ((DCELL *) inrast_psand)[col];
-		break;
-	    }
-	    switch (data_type_psilt) {
-	    case CELL_TYPE:
-		d_silt = (double)((CELL *) inrast_psilt)[col];
-		break;
-	    case FCELL_TYPE:
-		d_silt = (double)((FCELL *) inrast_psilt)[col];
-		break;
-	    case DCELL_TYPE:
-		d_silt = ((DCELL *) inrast_psilt)[col];
-		break;
-	    }
-	    switch (data_type_pclay) {
-	    case CELL_TYPE:
-		d_clay = (double)((CELL *) inrast_pclay)[col];
-		break;
-	    case FCELL_TYPE:
-		d_clay = (double)((FCELL *) inrast_pclay)[col];
-		break;
-	    case DCELL_TYPE:
-		d_clay = ((DCELL *) inrast_pclay)[col];
-		break;
-	    }
-	    switch (data_type_pomat) {
-	    case CELL_TYPE:
-		d_om = (double)((CELL *) inrast_pomat)[col];
-		break;
-	    case FCELL_TYPE:
-		d_om = (double)((FCELL *) inrast_pomat)[col];
-		break;
-	    case DCELL_TYPE:
-		d_om = ((DCELL *) inrast_pomat)[col];
-		break;
-	    }
-	    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);
-	    }
+        /*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);
-		if ((d_sand + d_clay + d_silt) != 1.0) {
-		    G_message("d=%icol=%i||%5.3f%5.3f%5.3f\n", d, col,
-			       d_sand, d_clay, d_silt);
-		}
-		if (G_is_d_null_value(&d_om)) {
-		    d_om = 0.0;	/*if OM==NULL then make it 0.0 */
-		}
-		d = tex2usle_k((int)d, d_om);
-		
-		    /*G_message(_(" -> %5.3f",d)); */ 
-
-				/************************************/ 
-		    if (d > 1.0) {	/*in case some map input not standard */
-		    d = 0.0;
-		}
-		outrast[col] = d;
+		    d = tex2usle_k((int)d, d_om);
+		    outrast[col] = d;
+                }
 	    }
-	    }
-	if (G_put_raster_row(outfd, outrast, data_type_output) < 0)
-	    G_fatal_error(_("Cannot write to output raster file"));
 	}
+	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);
@@ -283,9 +170,11 @@
     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);
 }
 

Deleted: grass-addons/gipe/r.uslek/prct2tex.h
===================================================================
--- grass-addons/gipe/r.uslek/prct2tex.h	2008-10-10 14:48:46 UTC (rev 33810)
+++ grass-addons/gipe/r.uslek/prct2tex.h	2008-10-11 00:59:22 UTC (rev 33811)
@@ -1,7 +0,0 @@
-
-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);

Copied: grass-addons/gipe/r.uslek/r.uslek.html (from rev 33803, grass-addons/gipe/r.uslek/description.html)
===================================================================
--- grass-addons/gipe/r.uslek/r.uslek.html	                        (rev 0)
+++ grass-addons/gipe/r.uslek/r.uslek.html	2008-10-11 00:59:22 UTC (rev 33811)
@@ -0,0 +1,23 @@
+<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 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>


Property changes on: grass-addons/gipe/r.uslek/r.uslek.html
___________________________________________________________________
Name: svn:mergeinfo
   + 

Deleted: grass-addons/gipe/r.uslek/tex2usle_k.h
===================================================================
--- grass-addons/gipe/r.uslek/tex2usle_k.h	2008-10-10 14:48:46 UTC (rev 33810)
+++ grass-addons/gipe/r.uslek/tex2usle_k.h	2008-10-11 00:59:22 UTC (rev 33811)
@@ -1,3 +0,0 @@
-
-
-double tex2usle_k(int texture, double om_in);



More information about the grass-commit mailing list