[GRASSLIST:4532] Re: r.mapcalc and environment variables - New trouble

Glynn Clements glynn.clements at virgin.net
Wed Sep 18 16:17:10 EDT 2002


Daniel Victoria wrote:

> Thanks for all the help, now I can output from a bash
> script to r.mapcalc. But now I bumped into a new
> problem.
> In my formula line I have two integer constants that
> are calculated during the bash script but in the
> formula I need the result of the division on a
> floating point form. Since I don't think there is a
> way to do floating point calculations in bash I just
> put on my formula line something like ($m1/$m2) and
> I'd get (13/18).
> 
> The problem now is this. When I run r.mapcalc like
> this
> r.mapcalc output=blabla(13/18)blabla
> I get  different result from
> r.mapcalc output=blabla(0.722223)blabla
> 
> Is this an illigal thing in r.mapcalc (13/18)??
> How should I go about this???

r.mapcalc will treat "13/18" as integer division, with a result of
zero. You need to explicitly convert one of the values to
floating-point, e.g.:

	r.mapcalc "output=blabla($m1.0/$m2)blabla"
or:
	r.mapcalc "output=blabla(float($m1)/$m2)blabla"

The first will expand to:

	r.mapcalc "output=blabla(13.0/18)blabla"

resulting in the numerator being treated as a floating-point value.

The second will expand to:

	r.mapcalc "output=blabla(float(13)/18)blabla"

resulting in the integer value being converted to a floating-point
value by r.mapcalc's float() function.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-user mailing list