[GRASS-SVN] r42012 - grass-addons/raster/r.fuzzy.system
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 24 04:02:12 EDT 2010
Author: jarekj71
Date: 2010-04-24 04:02:11 -0400 (Sat, 24 Apr 2010)
New Revision: 42012
Modified:
grass-addons/raster/r.fuzzy.system/description.html
grass-addons/raster/r.fuzzy.system/main.c
grass-addons/raster/r.fuzzy.system/map_parser.c
grass-addons/raster/r.fuzzy.system/rule_parser.c
grass-addons/raster/r.fuzzy.system/system.c
Log:
fix some memory leaks
Modified: grass-addons/raster/r.fuzzy.system/description.html
===================================================================
--- grass-addons/raster/r.fuzzy.system/description.html 2010-04-23 16:19:59 UTC (rev 42011)
+++ grass-addons/raster/r.fuzzy.system/description.html 2010-04-24 08:02:11 UTC (rev 42012)
@@ -44,7 +44,7 @@
<P>An example of fuzzy rules definiton:
<PRE>
-$ small {distance = high & elev = high};
+$ small {distance = high & elev = high}
</PRE>
</DD>
<h2>ADVANCED OPTIONS</h2>
@@ -153,7 +153,7 @@
<PRE>
r.stream.extract elevation=elevation.10m at PERMANENT threshold=2000 stream_rast=streams direction=dirs
r.stream.order stream=streams dir=dirs horton=horton
-r.mapcalc "horton3=if(horton>2,horton,null()"
+r.mapcalc "horton3=if(horton>2,horton,null())"
r.stream.distance stream=streams dir=dirs dem=elevation.10m method=downstream distance=distance elevation=elevation
</PRE>
@@ -178,14 +178,14 @@
<P>RULES:
<PRE>
#flood.rul
-$ unprob {elevation = high & distance = far};
-$ prob {distance = near | elevation = low};
-$ veryprob {distance = near & elevation = low};
+$ unprob {elevation = high & distance = far}
+$ prob {distance = near | elevation = low}
+$ veryprob {distance = near & elevation = low}
</PRE>
finally we need run r.fuzzy.system:
<PRE>
-r.fuzzy.system vars=flood.map rules=flod.rul output=flood
+r.fuzzy.system maps=flood.map rules=flod.rul output=flood
</PRE>
Resulting map should look like this below. Yellow color means no risk, red high risk, green, blue end so on moderate risk.
Modified: grass-addons/raster/r.fuzzy.system/main.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/main.c 2010-04-23 16:19:59 UTC (rev 42011)
+++ grass-addons/raster/r.fuzzy.system/main.c 2010-04-24 08:02:11 UTC (rev 42012)
@@ -166,7 +166,8 @@
if (multiple)
create_output_maps();
-
+ antecedents = (float *)G_malloc(nrules * sizeof(float));
+
G_message("Calculate...");
for (row = 0; row < nrows; ++row) {
@@ -217,6 +218,7 @@
G_close_cell(s_maps[i].cfd);
}
+ G_free(antecedents);
G_free(out_buf);
G_close_cell(outfd);
G_short_history(output, "raster", &history);
Modified: grass-addons/raster/r.fuzzy.system/map_parser.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/map_parser.c 2010-04-23 16:19:59 UTC (rev 42011)
+++ grass-addons/raster/r.fuzzy.system/map_parser.c 2010-04-24 08:02:11 UTC (rev 42012)
@@ -16,7 +16,7 @@
fd = fopen(file, "r");
if (!fd)
- G_fatal_error(_("Cannot open varaible file '%s'"), file);
+ G_fatal_error(_("Cannot open map file '%s'"), file);
fgetpos(fd, &init);
@@ -39,7 +39,7 @@
continue;
if (*buf != '%' && *buf != '$')
- G_fatal_error(_("Wrong syntax at line %d: line must start with #, % or $ or be empty line"),
+ G_fatal_error(_("Wrong syntax at line %d: line must start with <#>, <%> or <$> or be empty line"),
line);
if (*buf == '%') {
@@ -109,7 +109,7 @@
G_strcpy(set->setname, tmp);
else
G_fatal_error(_("Map: <%s>, Membership: <%s>: Value name cannot be longer than 20 chars, but has %d chars"),
- mapname, tmp, strlen(tmp));
+ mapname, tmp, (int)strlen(tmp));
} /* check length of fuzzy value */
{ /* check if side is valid (both,left,right) */
Modified: grass-addons/raster/r.fuzzy.system/rule_parser.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/rule_parser.c 2010-04-23 16:19:59 UTC (rev 42011)
+++ grass-addons/raster/r.fuzzy.system/rule_parser.c 2010-04-24 08:02:11 UTC (rev 42012)
@@ -64,7 +64,7 @@
int done = 1;
int stack_top;
char tmp[30];
- char opr[] = { '=', '&', '|', ';', '~', '(', ')', '{', '}' };
+ char opr[] = { '=', '&', '|', '~', '(', ')', '{', '}' };
i = j = stack_top = 0; /* variables of the while loop */
char_strip(buf, '$');
@@ -136,7 +136,7 @@
/* ******************************************************************* */
- { /* adding weight */
+/* { adding weight: not implemented yet
char local[900];
char weight[10];
@@ -150,7 +150,7 @@
if (s_rules[rule_num].weight <= 0.)
G_fatal_error(_("Weight must be grater than 0 or non-number character"));
- }
+ } */
{ /* check if rule syntax is proper and map names and vars values exist */
int k;
Modified: grass-addons/raster/r.fuzzy.system/system.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/system.c 2010-04-23 16:19:59 UTC (rev 42011)
+++ grass-addons/raster/r.fuzzy.system/system.c 2010-04-24 08:02:11 UTC (rev 42012)
@@ -8,11 +8,11 @@
int set_index;
float consequent;
float max_antecedent = 0;
+ float result;
agregate = (float *)G_calloc(resolution, sizeof(float));
- antecedents = (float *)G_malloc(nrules * sizeof(float));
- if (coor_proc)
+ if (coor_proc) /* this is allocated only once */
visual_output = (float **)G_malloc(resolution * sizeof(float *));
for (j = 0; j < nrules; ++j) {
@@ -53,7 +53,9 @@
for (i = 0; i < resolution; ++i)
visual_output[i][j + 1] = agregate[i];
- return defuzzify(agregate, defuzzyfication, max_antecedent);
+ result=defuzzify(agregate, defuzzyfication, max_antecedent);
+ G_free(agregate);
+ return result;
}
float parse_expression(int n)
More information about the grass-commit
mailing list