[GRASS5] variables in mapcalc, reusability

Glynn Clements glynn at gclements.plus.com
Fri Oct 21 09:24:18 EDT 2005


cgnicholas at alamedanet.net wrote:

> I am (finally) getting a chance to play with mapcalc in order to
> examine  "hot spots" in mosaics of aerial imagery. 
> 
> I was thinking to make a mapcalc routine similar to r.slope.aspect to
> determine angle of incidence from the camera position to anywhere on a
> DEM, so I can play with various BDRF functions and the outputs from
> r.sun.
> 
> But I'm wondering: is there an elegant way to pass global parameters
> (like x,y,z, input DEM, output files, etc) into a *reusable* chunk of
> mapcalc, that I can script for a lot of photos? Or do I need to invent
> some kind of (m4-based?) preprocessor that spits out a fresh piece of
> mapcalc for each frame? 

The usual approach is to use the shell as a preprocessor. If you pass
the expression on the command line in double quotes, or if you use a
"here document" (the "<<" syntax), the shell will substitute any
variable references.

See scripts/r.blend for an example of the former, or
scripts/r.shaded.relief for the latter.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list