[GRASS-SVN] r42058 - grass-addons/raster/r.fuzzy.system
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 29 09:12:43 EDT 2010
Author: jarekj71
Date: 2010-04-29 09:12:42 -0400 (Thu, 29 Apr 2010)
New Revision: 42058
Modified:
grass-addons/raster/r.fuzzy.system/fuzzylogic.c
grass-addons/raster/r.fuzzy.system/helpers.c
grass-addons/raster/r.fuzzy.system/local_proto.h
grass-addons/raster/r.fuzzy.system/main.c
grass-addons/raster/r.fuzzy.system/system.c
Log:
small bug fixes
Modified: grass-addons/raster/r.fuzzy.system/fuzzylogic.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/fuzzylogic.c 2010-04-28 21:18:00 UTC (rev 42057)
+++ grass-addons/raster/r.fuzzy.system/fuzzylogic.c 2010-04-29 13:12:42 UTC (rev 42058)
@@ -2,6 +2,7 @@
float fuzzy(FCELL cell, SETS * set)
{
+
float x;
if (!set->side) { /* both left and right */
@@ -52,13 +53,11 @@
if (set->height < 1)
x = x * set->height;
-
return (x >= 0 && x <= 1) ? x : -1;
}
-float f_and(float x, float y, int family)
+float f_and(float x, float y, logics family)
{
-
switch (family) {
case l_ZADEH:
@@ -91,9 +90,8 @@
return -1; /* error */
}
-float f_or(float x, float y, int family)
+float f_or(float x, float y, logics family)
{
- float b;
switch (family) {
@@ -125,7 +123,7 @@
}
-float f_not(float x, int family)
+float f_not(float x, logics family)
{
if (family == l_HAMACHER)
Modified: grass-addons/raster/r.fuzzy.system/helpers.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/helpers.c 2010-04-28 21:18:00 UTC (rev 42057)
+++ grass-addons/raster/r.fuzzy.system/helpers.c 2010-04-29 13:12:42 UTC (rev 42058)
@@ -97,11 +97,12 @@
G_get_window(&window);
num_points = sscanf(answer, "%lf,%lf", &x, &y);
- r = (int)G_easting_to_col(x, &window);
- c = (int)G_northing_to_row(y, &window);
+ c = (int)G_easting_to_col(x, &window);
+ r = (int)G_northing_to_row(y, &window);
get_rows(r);
get_cells(c);
+
result = implicate(); /* jump to different function */
for (i = 0; i < nrules; ++i)
Modified: grass-addons/raster/r.fuzzy.system/local_proto.h
===================================================================
--- grass-addons/raster/r.fuzzy.system/local_proto.h 2010-04-28 21:18:00 UTC (rev 42057)
+++ grass-addons/raster/r.fuzzy.system/local_proto.h 2010-04-29 13:12:42 UTC (rev 42058)
@@ -183,9 +183,9 @@
float parse_expression(int n);
float defuzzify(float *agregate, int defuzzification, float max_antecedent);
-float f_and(float cellx, float celly, int family);
-float f_or(float cellx, float celly, int family);
-float f_not(float cellx, int family);
+float f_and(float cellx, float celly, logics family);
+float f_or(float cellx, float celly, logics family);
+float f_not(float cellx, logics family);
float fuzzy(FCELL cell, SETS * set);
Modified: grass-addons/raster/r.fuzzy.system/main.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/main.c 2010-04-28 21:18:00 UTC (rev 42057)
+++ grass-addons/raster/r.fuzzy.system/main.c 2010-04-29 13:12:42 UTC (rev 42058)
@@ -39,7 +39,7 @@
file_vars = G_define_standard_option(G_OPT_F_INPUT);
file_vars->key = "maps";
- file_vars->required = NO;
+ file_vars->required = YES;
file_vars->description = _("Name of fuzzy variable file");
file_rules = G_define_standard_option(G_OPT_F_INPUT);
@@ -85,7 +85,7 @@
in_coor_opt = G_define_option(); /* input coordinates de outlet */
in_coor_opt->key = "coors";
in_coor_opt->type = TYPE_STRING;
- in_coor_opt->key_desc = "x|y";
+ in_coor_opt->key_desc = "x,y";
in_coor_opt->answer = NULL;
in_coor_opt->required = NO;
in_coor_opt->multiple = NO;
@@ -107,6 +107,7 @@
opt_output = G_define_standard_option(G_OPT_R_OUTPUT);
opt_output->description = _("Name of output file");
+ opt_output->required = NO;
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -118,6 +119,9 @@
membership_only = (out_membership->answer != 0);
coor_proc = (in_coor_opt->answer) ? 1 : 0;
+ if(!membership_only & (!output | !rule_name_file))
+ G_fatal_error(_("for standard analysis both output and rule file are required"));
+
resolution = atoi(par_resolution->answer);
if (resolution < 10)
G_fatal_error(_("Universe resolution too small, choose greater value"));
@@ -155,19 +159,18 @@
nrows = G_window_rows();
ncols = G_window_cols();
-
- parse_map_file(var_name_file);
- parse_rule_file(rule_name_file);
-
+
+ parse_map_file(var_name_file);
if (membership_only)
show_membership();
-
+
+ parse_rule_file(rule_name_file);
get_universe();
open_maps();
- antecedents = (float *)G_malloc(nrules * sizeof(float));
- if (coor_proc)
- process_coors(in_coor_opt->answer);
+ antecedents = (float *)G_malloc(nrules * sizeof(float));
+ if (coor_proc)
+ process_coors(in_coor_opt->answer);
if ((outfd = G_open_raster_new(output, FCELL_TYPE)) < 0)
G_fatal_error(_("Unable to create raster map <%s>"), output);
@@ -176,7 +179,6 @@
if (multiple)
create_output_maps();
-
G_message("Calculate...");
Modified: grass-addons/raster/r.fuzzy.system/system.c
===================================================================
--- grass-addons/raster/r.fuzzy.system/system.c 2010-04-28 21:18:00 UTC (rev 42057)
+++ grass-addons/raster/r.fuzzy.system/system.c 2010-04-29 13:12:42 UTC (rev 42058)
@@ -22,7 +22,7 @@
antecedents[j]) ? max_antecedent : antecedents[j];
}
- if (max_antecedent == 0.)
+ if (max_antecedent == 0. && !coor_proc)
return -9999; /* for all rules value is 0 */
if (coor_proc)
@@ -87,6 +87,7 @@
int set_index;
float f_value;
+
do {
if (s_rules[n].work_stack[i] == t_START) { /* first token */
if (i > 0)
@@ -97,11 +98,9 @@
if (s_rules[n].work_stack[i] == t_VAL) {
f_value =
- fuzzy(*s_rules[n].value_stack[i].value,
- s_rules[n].value_stack[i].set);
- values_stack[++val_top] =
- (s_rules[n].value_stack[i].oper == '~') ?
- f_not(f_value, family) : f_value;
+ fuzzy(*s_rules[n].value_stack[i].value, s_rules[n].value_stack[i].set);
+ values_stack[++val_top] = (s_rules[n].value_stack[i].oper == '~') ?
+ f_not(f_value, family) : f_value;
continue;
}
More information about the grass-commit
mailing list