[GRASS-SVN] r60122 - grass/branches/releasebranch_6_4/raster/r.kappa

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 5 12:40:05 PDT 2014


Author: neteler
Date: 2014-05-05 12:40:05 -0700 (Mon, 05 May 2014)
New Revision: 60122

Modified:
   grass/branches/releasebranch_6_4/raster/r.kappa/description.html
   grass/branches/releasebranch_6_4/raster/r.kappa/main.c
   grass/branches/releasebranch_6_4/raster/r.kappa/prt_mat.c
   grass/branches/releasebranch_6_4/raster/r.kappa/stats.c
Log:
r.kappa: Replace system() with G_vspawn_ex() (backport of r40146#file2); manual: simple NC example added

Modified: grass/branches/releasebranch_6_4/raster/r.kappa/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.kappa/description.html	2014-05-05 19:38:48 UTC (rev 60121)
+++ grass/branches/releasebranch_6_4/raster/r.kappa/description.html	2014-05-05 19:40:05 UTC (rev 60122)
@@ -48,6 +48,14 @@
 
 <H2>EXAMPLE</H2>
 
+Example for North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region rast=landclass96 -p
+r.kappa -w classification=landuse96_28m reference=landclass96
+</pre></div>
+<p>
+
 Verification of classified LANDSAT scene against training areas:
 
 <div class="code"><pre>

Modified: grass/branches/releasebranch_6_4/raster/r.kappa/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.kappa/main.c	2014-05-05 19:38:48 UTC (rev 60121)
+++ grass/branches/releasebranch_6_4/raster/r.kappa/main.c	2014-05-05 19:40:05 UTC (rev 60122)
@@ -139,7 +139,7 @@
     /* generate the error matrix, kappa and variance */
     calc_kappa();
 
-    return 0;
+    return EXIT_SUCCESS;
 }
 
 

Modified: grass/branches/releasebranch_6_4/raster/r.kappa/prt_mat.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.kappa/prt_mat.c	2014-05-05 19:38:48 UTC (rev 60121)
+++ grass/branches/releasebranch_6_4/raster/r.kappa/prt_mat.c	2014-05-05 19:40:05 UTC (rev 60122)
@@ -76,6 +76,7 @@
 	    for (k = 0; k < ncat; k++)
 		if (rlst[k] == Gstats[i].cats[1])
 		    break;
+	    /* matrix: reference in columns, classification in rows */
 	    matr[j * ncat + k] = Gstats[i].count;
 	}
 
@@ -132,7 +133,7 @@
 		}
 		fprintf(fd, "\n");
 	    }
-	    /* marginal summation of columes */
+	    /* column marginal summation */
 	    fprintf(fd, "Col Sum\t\t");
 	    for (cndx = first_col; cndx < last_col; cndx++) {
 		t_col = 0;

Modified: grass/branches/releasebranch_6_4/raster/r.kappa/stats.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.kappa/stats.c	2014-05-05 19:38:48 UTC (rev 60121)
+++ grass/branches/releasebranch_6_4/raster/r.kappa/stats.c	2014-05-05 19:40:05 UTC (rev 60122)
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <grass/gis.h>
+#include <grass/spawn.h>
 #include "kappa.h"
 #include <grass/glocale.h>
 #include "local_proto.h"
@@ -23,6 +24,8 @@
     size_t ns;
     FILE *fd;
     char **tokens;
+    const char *argv[9];
+    int argc = 0;
 
     strcpy(mname, maps[0]);
     mmapset = G_find_cell2(mname, "");
@@ -35,19 +38,28 @@
 	G_fatal_error(_("Raster map <%s> not found"), maps[1]);
 
     stats_file = G_tempfile();
-    strcpy(buf, "r.stats -cin");
-    strcat(buf, " fs=:");
-    strcat(buf, " input=");
-    strcat(buf, G_fully_qualified_name(maps[1], mmapset));
-    strcat(buf, ",");
-    strcat(buf, G_fully_qualified_name(maps[0], rmapset));
-    strcat(buf, " > \"");
-    strcat(buf, stats_file);
-    strcat(buf, "\"");
 
-    if (system(buf)) {
-	unlink(stats_file);
-	exit(1);
+    argv[argc++] = "r.stats";
+
+    argv[argc++] = "-cin";
+
+    argv[argc++] = "fs=:";
+
+    sprintf(buf, "input=%s,%s",
+	    G_fully_qualified_name(maps[1], mmapset),
+	    G_fully_qualified_name(maps[0], rmapset));
+    argv[argc++] = buf;
+
+    argv[argc++] = SF_REDIRECT_FILE;
+    argv[argc++] = SF_STDOUT;
+    argv[argc++] = SF_MODE_OUT;
+    argv[argc++] = stats_file;
+
+    argv[argc++] = NULL;
+
+    if (G_vspawn_ex(argv[0], argv) != 0) {
+	remove(stats_file);
+	G_fatal_error("error running r.stats");
     }
 
     fd = fopen(stats_file, "r");



More information about the grass-commit mailing list