[GRASS-SVN] r34197 - grass/trunk/raster/r.coin

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 8 20:48:28 EST 2008


Author: glynn
Date: 2008-11-08 20:48:28 -0500 (Sat, 08 Nov 2008)
New Revision: 34197

Removed:
   grass/trunk/raster/r.coin/cmd_parms.c
Modified:
   grass/trunk/raster/r.coin/coin.h
   grass/trunk/raster/r.coin/main.c
   grass/trunk/raster/r.coin/make_coin.c
   grass/trunk/raster/r.coin/print_coin.c
   grass/trunk/raster/r.coin/print_hdr.c
Log:
Clean-up


Deleted: grass/trunk/raster/r.coin/cmd_parms.c
===================================================================
--- grass/trunk/raster/r.coin/cmd_parms.c	2008-11-08 16:42:32 UTC (rev 34196)
+++ grass/trunk/raster/r.coin/cmd_parms.c	2008-11-09 01:48:28 UTC (rev 34197)
@@ -1,89 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       r.coin
- *
- * AUTHOR(S):    Michael O'Shea - CERL
- *               Michael Shapiro - CERL
- *
- * PURPOSE:      Calculates the coincidence of two raster map layers.
- *
- * COPYRIGHT:    (C) 2006 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 <stdlib.h>
-#include <string.h>
-#include "coin.h"
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-
-int command_version(int argc, char *argv[])
-{
-    struct GModule *module;
-    struct
-    {
-	struct Option *map1, *map2, *units;
-    } parm;
-    struct
-    {
-	struct Flag *w;
-    } flag;
-
-    module = G_define_module();
-    module->keywords = _("raster");
-    module->description =
-	_("Tabulates the mutual occurrence (coincidence) "
-	  "of categories for two raster map layers.");
-
-    parm.map1 = G_define_option();
-    parm.map1->key = "map1";
-    parm.map1->required = YES;
-    parm.map1->type = TYPE_STRING;
-    parm.map1->gisprompt = "old,cell,raster";
-    parm.map1->description = _("Name of first raster map");
-
-    parm.map2 = G_define_option();
-    parm.map2->key = "map2";
-    parm.map2->required = YES;
-    parm.map2->type = TYPE_STRING;
-    parm.map2->gisprompt = "old,cell,raster";
-    parm.map2->description = _("Name of second raster map");
-
-    parm.units = G_define_option();
-    parm.units->key = "units";
-    parm.units->required = YES;
-    parm.units->type = TYPE_STRING;
-    parm.units->label = _("Unit of measure");
-    parm.units->description =
-	_("c(ells), p(ercent), x(percent of category [column]), "
-	  "y(percent of category [row]), a(cres), h(ectares), "
-	  "k(square kilometers), m(square miles)");
-    parm.units->options = "c,p,x,y,a,h,k,m";
-
-    flag.w = G_define_flag();
-    flag.w->key = 'w';
-    flag.w->description = _("Wide report, 132 columns (default: 80)");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    strcpy(map1name, parm.map1->answer);
-    strcpy(map2name, parm.map2->answer);
-    mapset1 = G_find_cell2(map1name, "");
-    if (!mapset1)
-	G_fatal_error(_("Raster map <%s> not found"), map1name);
-    mapset2 = G_find_cell2(map2name, "");
-    if (!mapset2)
-	G_fatal_error(_("Raster map <%s> not found"), map2name);
-
-    make_coin();
-    print_coin(*parm.units->answer, flag.w->answer ? 132 : 80, 0);
-
-    exit(EXIT_SUCCESS);
-}

Modified: grass/trunk/raster/r.coin/coin.h
===================================================================
--- grass/trunk/raster/r.coin/coin.h	2008-11-08 16:42:32 UTC (rev 34196)
+++ grass/trunk/raster/r.coin/coin.h	2008-11-09 01:48:28 UTC (rev 34197)
@@ -29,7 +29,7 @@
 
 extern struct Cell_head window;
 
-extern char *title1, *title2;
+extern const char *title1, *title2;
 
 extern double window_cells;
 extern double window_area;
@@ -38,12 +38,11 @@
 extern long *catlist1, *catlist2;
 extern int no_data1, no_data2;
 extern int Rndex, Cndex;
-extern char *dumpname;
-extern char *statname;
+extern const char *dumpname;
+extern const char *statname;
 extern FILE *dumpfile;
 
-extern char map1name[GNAME_MAX], map2name[GNAME_MAX];
-extern char *mapset1, *mapset2;
+extern const char *map1name, *map2name;
 extern int ncat1, ncat2;
 
 extern char *fill, *midline;
@@ -51,9 +50,6 @@
 /* check.c */
 int check_report_size(void);
 
-/* cmd.c */
-int command_version(int, char *[]);
-
 /* format.c */
 int format_double(double, char *, int);
 

Modified: grass/trunk/raster/r.coin/main.c
===================================================================
--- grass/trunk/raster/r.coin/main.c	2008-11-08 16:42:32 UTC (rev 34196)
+++ grass/trunk/raster/r.coin/main.c	2008-11-09 01:48:28 UTC (rev 34197)
@@ -17,12 +17,14 @@
  ***************************************************************************/
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
 #include "coin.h"
 
 struct Cell_head window;
 
-char *title1, *title2;
+const char *title1, *title2;
 
 double window_cells;
 double window_area;
@@ -31,24 +33,72 @@
 long *catlist1, *catlist2;
 int no_data1, no_data2;
 int Rndex, Cndex;
-char *dumpname;
-char *statname;
+const char *dumpname;
+const char *statname;
 FILE *dumpfile;
 
-char map1name[GNAME_MAX], map2name[GNAME_MAX];
-char *mapset1, *mapset2;
+const char *map1name, *map2name;
 int ncat1, ncat2;
 
 char *fill, *midline;
 
 int main(int argc, char *argv[])
 {
+    struct GModule *module;
+    struct
+    {
+	struct Option *map1, *map2, *units;
+    } parm;
+    struct
+    {
+	struct Flag *w;
+    } flag;
+
     fill =
 	"                                                                                                                                       ";
     midline =
 	"------------------------------------------------------------------------------------------------------------------------------------";
 
     G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description =
+	_("Tabulates the mutual occurrence (coincidence) "
+	  "of categories for two raster map layers.");
+
+    parm.map1 = G_define_option();
+    parm.map1->key = "map1";
+    parm.map1->required = YES;
+    parm.map1->type = TYPE_STRING;
+    parm.map1->gisprompt = "old,cell,raster";
+    parm.map1->description = _("Name of first raster map");
+
+    parm.map2 = G_define_option();
+    parm.map2->key = "map2";
+    parm.map2->required = YES;
+    parm.map2->type = TYPE_STRING;
+    parm.map2->gisprompt = "old,cell,raster";
+    parm.map2->description = _("Name of second raster map");
+
+    parm.units = G_define_option();
+    parm.units->key = "units";
+    parm.units->required = YES;
+    parm.units->type = TYPE_STRING;
+    parm.units->label = _("Unit of measure");
+    parm.units->description =
+	_("c(ells), p(ercent), x(percent of category [column]), "
+	  "y(percent of category [row]), a(cres), h(ectares), "
+	  "k(square kilometers), m(square miles)");
+    parm.units->options = "c,p,x,y,a,h,k,m";
+
+    flag.w = G_define_flag();
+    flag.w->key = 'w';
+    flag.w->description = _("Wide report, 132 columns (default: 80)");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
     G_get_window(&window);
     /* now make a temorary region with the same boundaries only 1 x 1 */
     window.rows = 1;
@@ -68,11 +118,19 @@
 
     window_cells = G_window_rows() * G_window_cols();
 
+    map1name = parm.map1->answer;
+    map2name = parm.map2->answer;
 
-    command_version(argc, argv);
+    if (!G_find_cell2(map1name, ""))
+	G_fatal_error(_("Raster map <%s> not found"), map1name);
+    if (!G_find_cell2(map2name, ""))
+	G_fatal_error(_("Raster map <%s> not found"), map2name);
 
-    unlink(dumpname);
-    unlink(statname);
+    make_coin();
+    print_coin(*parm.units->answer, flag.w->answer ? 132 : 80, 0);
 
-    exit(0);
+    remove(dumpname);
+    remove(statname);
+
+    exit(EXIT_SUCCESS);
 }

Modified: grass/trunk/raster/r.coin/make_coin.c
===================================================================
--- grass/trunk/raster/r.coin/make_coin.c	2008-11-08 16:42:32 UTC (rev 34196)
+++ grass/trunk/raster/r.coin/make_coin.c	2008-11-09 01:48:28 UTC (rev 34197)
@@ -45,9 +45,9 @@
 	      map1name, map2name);
 
     sprintf(buf, "r.stats -anrc fs=: input=\"");
-    strcat(buf, G_fully_qualified_name(map1name, mapset1));
+    strcat(buf, map1name);
     strcat(buf, ",");
-    strcat(buf, G_fully_qualified_name(map2name, mapset2));
+    strcat(buf, map2name);
     strcat(buf, "\"");
     statfd = fopen(statname, "w");
     if (statfd == NULL)
@@ -113,8 +113,7 @@
     /* want the smaller number across, larger number down */
     reversed = 0;
     if (ncat1 > ncat2) {
-	char name[GNAME_MAX];
-	char *mp;
+	const char *name;
 	long *list;
 	int n;
 
@@ -122,12 +121,9 @@
 	ncat1 = ncat2;
 	ncat2 = n;
 
-	strcpy(name, map1name);
-	strcpy(map1name, map2name);
-	strcpy(map2name, name);
-	mp = mapset1;
-	mapset1 = mapset2;
-	mapset2 = mp;
+	name = map1name;
+	map1name = map2name;
+	map2name = name;
 
 	list = catlist1;
 	catlist1 = catlist2;
@@ -136,8 +132,8 @@
 	reversed = 1;
     }
 
-    title1 = G_get_cell_title(map1name, mapset1);
-    title2 = G_get_cell_title(map2name, mapset2);
+    title1 = G_get_cell_title(map1name, "");
+    title2 = G_get_cell_title(map2name, "");
 
     /* determine where no data (cat 0) is */
     for (no_data1 = ncat1 - 1; no_data1 >= 0; no_data1--)

Modified: grass/trunk/raster/r.coin/print_coin.c
===================================================================
--- grass/trunk/raster/r.coin/print_coin.c	2008-11-08 16:42:32 UTC (rev 34196)
+++ grass/trunk/raster/r.coin/print_coin.c	2008-11-09 01:48:28 UTC (rev 34197)
@@ -37,7 +37,7 @@
     int addflag;
     char topformat[133], midformat[133], namformat[133];
     char fillformat[133];
-    char *mapone;
+    const char *mapone;
     int col0, row0;
 
     if (tofile) {

Modified: grass/trunk/raster/r.coin/print_hdr.c
===================================================================
--- grass/trunk/raster/r.coin/print_hdr.c	2008-11-08 16:42:32 UTC (rev 34196)
+++ grass/trunk/raster/r.coin/print_hdr.c	2008-11-09 01:48:28 UTC (rev 34197)
@@ -22,7 +22,6 @@
 int print_coin_hdr(int Conformat)
 {
     char unit_type[20];
-    char *G_date();
     char *mapset, *location;
     char north[30], south[30], east[30], west[30];
 



More information about the grass-commit mailing list