[GRASS5] variables in mapcalc, reusability

greetings -

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?

I can imagine such a preprocessor doing simple things like #include,
$1, $2, etc variable substitutions, etc. (Indeed, might such a
preprocessor be able to eventually take a graph of model descriptions
in something like MML, as per:
http://www.uvm.edu/giee/SME3/MetaModelsF.html and spit out mapcalc and
a controlling shell script to exercise it....?)

Or is this completely the wrong way to approach this kind of problem?

thanks in advance -

Chris Nicholas

cgnicholas@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@gclements.plus.com>