[GRASS-dev] r.mapcalc changed to use G_parser()

Glynn Clements glynn at gclements.plus.com
Wed Aug 6 14:16:26 EDT 2008


I have changed r.mapcalc in 7.x to use G_parser():

	$ r.mapcalc --help
	
	Description:
	 Raster map calculator.
	
	Keywords:
	 raster
	
	Usage:
	 r.mapcalc [expression=string] [input=name] [--overwrite] [--verbose]
	   [--quiet]
	
	Flags:
	 --o   Allow output files to overwrite existing files
	 --v   Verbose module output
	 --q   Quiet module output
	
	Parameters:
	  expression   Expression to evaluate
	       input   File containing expression to evaluate

Note that, as expression= is the first option, it is the default. This
means that passing an expression on the command line is compatible
with both the old and new interfaces, so long as you:

a) quote the expression, and
b) include a space before the first = sign.

E.g.:
	r.mapcalc "foo = 1"
or:
	r.mapcalc 'foo = 1'

An unquoted expression (i.e. split over multiple arguments) won't
work, nor will omitting the space before the = sign:

	$ r.mapcalc 'foo=1'
	Sorry, <foo> is not a valid parameter

If no options are given, it manufactures "input=-" (which reads from
stdin), so you can continue to use e.g.:

	r.mapcalc < file
or:
	r.mapcalc <<EOF
	foo = 1
	EOF

But unless you need compatibility with previous versions, use input=
explicitly, e.g.:

	r.mapcalc input=file
or:
	r.mapcalc input=- <<EOF
	foo = 1
	EOF

Also, it now recognises --o[verwrite] and $GRASS_OVERWRITE, so you
will get an error if you try to overwrite an existing map without one
of those.

Note that older versions don't understand --o, so if you want to write
a shell script which is compatible with both versions, and which will
overwrite existing maps, use e.g.:

	GRASS_OVERWRITE=1 r.mapcalc 'foo = 1'

Python scripts only need to work with 7.x, so you can just use --o (or
overwrite=True with grass.run_command etc).

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


More information about the grass-dev mailing list