[GRASS-SVN] r33674 - in grass/trunk: raster/r.mapcalc
scripts/i.fusion.brovey scripts/r.shaded.relief
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 5 04:12:55 EDT 2008
Author: glynn
Date: 2008-10-05 04:12:55 -0400 (Sun, 05 Oct 2008)
New Revision: 33674
Modified:
grass/trunk/raster/r.mapcalc/evaluate.c
grass/trunk/raster/r.mapcalc/mapcalc.y
grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py
grass/trunk/scripts/r.shaded.relief/r.shaded.relief.py
Log:
Allow eval() at top level
Modified: grass/trunk/raster/r.mapcalc/evaluate.c
===================================================================
--- grass/trunk/raster/r.mapcalc/evaluate.c 2008-10-04 22:40:43 UTC (rev 33673)
+++ grass/trunk/raster/r.mapcalc/evaluate.c 2008-10-05 08:12:55 UTC (rev 33674)
@@ -271,10 +271,13 @@
expression *e = l->exp;
const char *var;
- if (e->type != expr_type_binding)
+ if (e->type != expr_type_binding && e->type != expr_type_function)
G_fatal_error("internal error: execute: invalid type: %d",
e->type);
+ if (e->type != expr_type_binding)
+ continue;
+
var = e->data.bind.var;
if (!overwrite && check_output_map(var))
@@ -286,12 +289,11 @@
const char *var;
expression *val;
+ initialize(e);
+
if (e->type != expr_type_binding)
- G_fatal_error("internal error: execute: invalid type: %d",
- e->type);
+ continue;
- initialize(e);
-
var = e->data.bind.var;
val = e->data.bind.val;
@@ -308,9 +310,14 @@
for (l = ee; l; l = l->next) {
expression *e = l->exp;
- int fd = e->data.bind.fd;
+ int fd;
evaluate(e);
+
+ if (e->type != expr_type_binding)
+ continue;
+
+ fd = e->data.bind.fd;
put_map_row(fd, e->buf, e->res_type);
}
@@ -322,10 +329,17 @@
for (l = ee; l; l = l->next) {
expression *e = l->exp;
- const char *var = e->data.bind.var;
- expression *val = e->data.bind.val;
- int fd = e->data.bind.fd;
+ const char *var;
+ expression *val;
+ int fd;
+ if (e->type != expr_type_binding)
+ continue;
+
+ var = e->data.bind.var;
+ val = e->data.bind.val;
+ fd = e->data.bind.fd;
+
close_output_map(fd);
e->data.bind.fd = -1;
Modified: grass/trunk/raster/r.mapcalc/mapcalc.y
===================================================================
--- grass/trunk/raster/r.mapcalc/mapcalc.y 2008-10-04 22:40:43 UTC (rev 33673)
+++ grass/trunk/raster/r.mapcalc/mapcalc.y 2008-10-05 08:12:55 UTC (rev 33674)
@@ -92,6 +92,7 @@
def : STRING '=' exp { $$ = binding($1,$3); define_variable($$); }
| NAME '=' exp { $$ = binding($1,$3); define_variable($$); }
+ | atom_func
;
map : STRING
Modified: grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py
===================================================================
--- grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py 2008-10-04 22:40:43 UTC (rev 33673)
+++ grass/trunk/scripts/i.fusion.brovey/i.fusion.brovey.py 2008-10-05 08:12:55 UTC (rev 33674)
@@ -132,9 +132,10 @@
grass.message("Calculating %s.{red,green,blue}: ..." % out)
t = string.Template(
- '''"$out.red" = eval(k = "$pan" / ("$ms1" + "$ms2" + "$ms3"), 1. * "$ms3" * k)
- "$out.green" = 1. * "$ms2" * k
- "$out.blue" = 1. * "$ms1" * k''')
+ '''eval(k = float("$pan") / ("$ms1" + "$ms2" + "$ms3"))
+ "$out.red" = "$ms3" * k
+ "$out.green" = "$ms2" * k
+ "$out.blue" = "$ms1" * k''')
e = t.substitute(out = out, pan = pan, ms1 = ms1, ms2 = ms2, ms3 = ms3)
if grass.run_command('r.mapcalc', expression = e) != 0:
grass.fatal("An error occurred while running r.mapcalc")
Modified: grass/trunk/scripts/r.shaded.relief/r.shaded.relief.py
===================================================================
--- grass/trunk/scripts/r.shaded.relief/r.shaded.relief.py 2008-10-04 22:40:43 UTC (rev 33673)
+++ grass/trunk/scripts/r.shaded.relief/r.shaded.relief.py 2008-10-05 08:12:55 UTC (rev 33674)
@@ -120,7 +120,7 @@
units = options['units']
if not grass.find_file(input)['file']:
- grass.fatal("Map <%s> not found." % elev)
+ grass.fatal("Map <%s> not found." % input)
if input == output:
grass.fatal("Input elevation map and output relief map must have different names")
@@ -152,18 +152,19 @@
grass.message("Calculating shading, please stand by.")
- t = string.Template(r'''$elev_out = eval( \
-x=($zmult*$elev[-1,-1] + 2*$zmult*$elev[0,-1] + $zmult*$elev[1,-1] - \
- $zmult*$elev[-1,1] - 2*$zmult*$elev[0,1] - $zmult*$elev[1,1])/(8.*ewres()*$scale), \
-y=($zmult*$elev[-1,-1] + 2*$zmult*$elev[-1,0] + $zmult*$elev[-1,1] - \
- $zmult*$elev[1,-1] - 2*$zmult*$elev[1,0] - $zmult*$elev[1,1])/(8.*nsres()*$scale), \
-slope=90.-atan(sqrt(x*x + y*y)), \
-a=round(atan(x,y)), \
-a=if(isnull(a),1,a), \
-aspect=if(x!=0||y!=0,if(a,a,360.)), \
-cang = sin($alt)*sin(slope) + cos($alt)*cos(slope) * cos($az-aspect), \
-if(cang < 0.,0.,100.*cang), \
-if(isnull(cang), null(), 100.*cang))''')
+ t = string.Template(
+ r'''eval( \
+ x=($zmult*$elev[-1,-1] + 2*$zmult*$elev[0,-1] + $zmult*$elev[1,-1] - \
+ $zmult*$elev[-1,1] - 2*$zmult*$elev[0,1] - $zmult*$elev[1,1])/(8.*ewres()*$scale), \
+ y=($zmult*$elev[-1,-1] + 2*$zmult*$elev[-1,0] + $zmult*$elev[-1,1] - \
+ $zmult*$elev[1,-1] - 2*$zmult*$elev[1,0] - $zmult*$elev[1,1])/(8.*nsres()*$scale), \
+ slope=90.-atan(sqrt(x*x + y*y)), \
+ a=round(atan(x,y)), \
+ a=if(isnull(a),1,a), \
+ aspect=if(x!=0||y!=0,if(a,a,360.)), \
+ cang = sin($alt)*sin(slope) + cos($alt)*cos(slope) * cos($az-aspect), \
+ )
+ $elev_out = if(isnull(cang), null(), 100.*cang)''')
expr = t.substitute(alt = alt, az = az, elev = elev, elev_out = elev_out, scale = scale, zmult = zmult)
p = grass.feed_command('r.mapcalc')
p.stdin.write(expr)
More information about the grass-commit
mailing list