[GRASS-SVN] r50716 - grass/branches/develbranch_6/raster/r.le/r.le.trace

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 7 23:22:09 EST 2012


Author: hamish
Date: 2012-02-07 20:22:09 -0800 (Tue, 07 Feb 2012)
New Revision: 50716

Modified:
   grass/branches/develbranch_6/raster/r.le/r.le.trace/main.c
   grass/branches/develbranch_6/raster/r.le/r.le.trace/user_input.c
Log:
better support for map at othermapset;
remove some unused variables;
d.colormode not ported to grass6;
minor whitespace cleanup;
initialize the 'pat' pointer to NULL;
i18n; use G_std_opt()


Modified: grass/branches/develbranch_6/raster/r.le/r.le.trace/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.le/r.le.trace/main.c	2012-02-07 23:53:24 UTC (rev 50715)
+++ grass/branches/develbranch_6/raster/r.le/r.le.trace/main.c	2012-02-08 04:22:09 UTC (rev 50716)
@@ -43,7 +43,6 @@
     struct Cell_head window;
     int bot, right, t0, b0, l0, r0, clear = 0;
     double Rw_l, Rscr_wl;
-    char tmp[20];
     void set_map();
 
     setbuf(stdout, NULL);	/* unbuffered */
@@ -63,8 +62,7 @@
     user_input(argc, argv);
 
     /* setup the current window for display */
-    G_system(" d.colormode float");
-    G_system(" d.frame -e");
+    G_system("d.frame -e");
     Rw_l = (double)G_window_cols() / G_window_rows();
     R_open_driver();
     R_font("romant");
@@ -109,14 +107,13 @@
 
 
 
-				/* DISPLAY A MESSAGE AND THE MAP, THEN
-				   TRACE THE PATCHES AND DISPLAY THEM */
+	/* DISPLAY A MESSAGE AND THE MAP, THEN
+	   TRACE THE PATCHES AND DISPLAY THEM */
 
 void set_map(char *name, struct Cell_head window, int top, int bot, int left,
 	     int right, char *fn)
 {
     char cmd[30];
-    int i, k = 0, j, btn, d, class;
     double msc[2];
     void scr_cell(), cell_clip_drv(), show_patch();
 
@@ -125,9 +122,8 @@
 
     G_system("clear");
     puts("\n\nR.LE.TRACE IS WORKING...\n");
-    G_system("d.colormode mode=fixed");
-    sprintf(cmd, "d.rast %s", name);
     G_system("d.erase");
+    sprintf(cmd, "d.rast %s", name);
     G_system(cmd);
 
     /* setup the screen-cell array coordinate 
@@ -150,14 +146,11 @@
 
 
 
+	/* DISPLAY THE PATCH INFORMATION */
 
-
-				/* DISPLAY THE PATCH INFORMATION */
-
 void show_patch(char *fn, double *msc, char *cmd)
 {
     PATCH *tmp, *tmp0;
-    register int i;
     int num;
     char c;
     void draw_patch(), patch_attr();
@@ -277,7 +270,7 @@
 }
 
 
-				/* DISPLAY PATCH ATTRIBUTES ON THE SCREEN */
+	/* DISPLAY PATCH ATTRIBUTES ON THE SCREEN */
 
 void patch_attr(FILE * fp, PATCH * p, int show)
 {
@@ -329,7 +322,7 @@
 
 
 
-				/* PLACE PATCH NUMBERS ON THE SCREEN */
+	/* PLACE PATCH NUMBERS ON THE SCREEN */
 
 void draw_patch(PATCH * p, double *m)
 {
@@ -371,8 +364,8 @@
 
 
 
-				/* DRIVER FOR CELL CLIPPING, TRACING,
-				   AND CALCULATIONS */
+	/* DRIVER FOR CELL CLIPPING, TRACING,
+	   AND CALCULATIONS */
 
 void cell_clip_drv(int col0, int row0, int ncols, int nrows, double **value,
 		   int index)
@@ -430,11 +423,12 @@
        list_head =     point to the patch list
      */
 
+    pat = NULL;
 
     total_patches = 0;
 
     name = choice->fn;
-    mapset = G_mapset();
+    mapset = G_find_cell2(name, "");
     data_type = G_raster_map_type(name, mapset);
 
     /* dynamically allocate storage for the
@@ -496,8 +490,8 @@
 
 
 
-				/* OPEN THE RASTER FILE TO BE CLIPPED,
-				   AND DO THE CLIPPING */
+	/* OPEN THE RASTER FILE TO BE CLIPPED,
+	   AND DO THE CLIPPING */
 
 void cell_clip(DCELL ** buf, DCELL ** null_buf, int row0, int col0, int nrows,
 	       int ncols, int index, int *centernull)
@@ -506,7 +500,7 @@
     FCELL *ftmp;
     DCELL *dtmp;
     void *rastptr;
-    char *tmpname;
+    char *tmpname, *name, *mapset;
     int fr, x;
     register int i, j;
     double center_row = 0.0, center_col = 0.0;
@@ -552,22 +546,13 @@
     /* check for input raster map and open it; this
        map remains open on finput while all the programs
        run, so it is globally available */
+    name = choice->fn;
 
-    if (0 > (finput = G_open_cell_old(choice->fn, G_mapset()))) {
-	fprintf(stderr, "\n");
-	fprintf(stderr,
-		"   ********************************************************\n");
-	fprintf(stderr,
-		"    The raster map you specified with the 'map=' parameter \n");
-	fprintf(stderr,
-		"    was not found in your mapset.                          \n");
-	fprintf(stderr,
-		"   ********************************************************\n");
-	exit(1);
-    }
+    if (0 > (finput = G_open_cell_old(name, "")))
+	G_fatal_error(_("Unable to open raster map <%s>"), name);
 
-    else
-	data_type = G_raster_map_type(choice->fn, G_mapset());
+    mapset = G_find_cell2(name, "");
+    data_type = G_raster_map_type(name, mapset);
 
     /* allocate memory to store a row of the
        raster map, depending on the type of
@@ -728,14 +713,15 @@
 
 
 
-				/* DRIVER TO LOOK FOR NEW PATCHES, CALL
-				   THE TRACING ROUTINE, AND ADD NEW PATCHES
-				   TO THE PATCH LIST */
 
-void trace(int nrows, int ncols, DCELL ** buf, DCELL ** null_buf, CELL ** pat)
+	/* DRIVER TO LOOK FOR NEW PATCHES, CALL
+	   THE TRACING ROUTINE, AND ADD NEW PATCHES
+	   TO THE PATCH LIST */
+
+void trace(int nrows, int ncols, DCELL **buf, DCELL **null_buf, CELL **pat)
 {
     double class = 0.0;
-    register int i, j, x;
+    register int i, j;
     PATCH *tmp, *find_any, *list_head;
 
     /*
@@ -745,20 +731,20 @@
        nrows =      total number of rows in the area where tracing will occur
        ncols =      total number of cols in the area where tracing will occur
        buf =        pointer to array containing only the pixels inside the area
-       that was clipped and within which tracing will now occur, so
-       a smaller array than the original raster map
+		that was clipped and within which tracing will now occur, so
+		a smaller array than the original raster map
        null_buf =   pointer to array containing 0.0 if pixel in input raster map is
-       not null and 1.0 if pixel in input raster map is null
+		not null and 1.0 if pixel in input raster map is null
        pat =        pointer to array containing the map of patch numbers; this map
-       can only be integer
+		    can only be integer
        INTERNAL:
        class =      the attribute of each pixel
        i, j =       counts the row and column as the program goes through the area
        tmp =        pointer to a member of the PATCH list data structure, used to
-       advance through the patch list
+		advance through the patch list
        find_any =   pointer to a member of the patch list to hold the results after
-       routine get_bd is called to trace the boundary of the patch and
-       save the patch information in the PATCH data structure
+		routine get_bd is called to trace the boundary of the patch and
+		save the patch information in the PATCH data structure
        list_head =  pointer to the first member of the patch list
      */
 
@@ -787,7 +773,7 @@
 
 		list_head = patch_list;
 
-		if (find_any = get_bd(i, j, nrows, ncols, class, buf, null_buf, list_head, pat)) {	/*4 */
+		if ((find_any = get_bd(i, j, nrows, ncols, class, buf, null_buf, list_head, pat))) {	/*4 */
 
 		    /* if the first patch, make tmp point to
 		       the patch list and add the first patch
@@ -841,12 +827,10 @@
 
 
 
+  /* TRACE THE BOUNDARY OF A PATCH AND
+     SAVE THE PATCH CHARACTERISTICS IN
+     THE PATCH STRUCTURE */
 
-
-				/* TRACE THE BOUNDARY OF A PATCH AND
-				   SAVE THE PATCH CHARACTERISTICS IN
-				   THE PATCH STRUCTURE */
-
 PATCH *get_bd(int row0, int col0, int nrows, int ncols, double class,
 	      DCELL ** buf, DCELL ** null_buf, PATCH * p_list, CELL ** pat)
 {

Modified: grass/branches/develbranch_6/raster/r.le/r.le.trace/user_input.c
===================================================================
--- grass/branches/develbranch_6/raster/r.le/r.le.trace/user_input.c	2012-02-07 23:53:24 UTC (rev 50715)
+++ grass/branches/develbranch_6/raster/r.le/r.le.trace/user_input.c	2012-02-08 04:22:09 UTC (rev 50716)
@@ -18,6 +18,7 @@
  ************************************************************/
 
 #include <grass/config.h>
+#include <grass/glocale.h>
 #include "r.le.trace.h"
 
 extern struct CHOICE *choice;
@@ -31,23 +32,17 @@
 
     bound = G_define_flag();
     bound->key = 'p';
-    bound->description = "Include sampling area boundary as perimeter";
+    bound->description = _("Include sampling area boundary as perimeter");
 
     trace = G_define_flag();
     trace->key = 't';
-    trace->description = "Use 4 neighbor tracing instead of 8 neighbor";
+    trace->description = _("Use 4 neighbor tracing instead of 8 neighbor");
 
-    name = G_define_option();
-    name->key = "map";
-    name->description = "Raster map to be analyzed";
-    name->type = TYPE_STRING;
-    name->gisprompt = "old,cell,raster";
-    name->required = YES;
+    name = G_define_standard_option(G_OPT_R_MAP);
+    name->description = _("Raster map to be analyzed");
 
-    out = G_define_option();
-    out->key = "out";
-    out->description = "Name of output file to store patch data";
-    out->type = TYPE_STRING;
+    out = G_define_standard_option(G_OPT_F_OUTPUT);
+    out->description = _("Name of output file to store patch data");
     out->required = NO;
 
     if (G_parser(argc, argv))



More information about the grass-commit mailing list