[GRASS5] [bug #1075] (grass) bug in r.mapcalc

this bug's URL: http://intevation.de/rt/webrt?serial_num=1075
-------------------------------------------------------------------------

Subject: bug in r.mapcalc

Platform: GNU/Linux/i386
grass obtained from: Trento Italy site
grass binary for platform: Compiled from Sources
GRASS Version: grass50_exp_2002_04_26

Hello,

I have found that r.mapcalc doesn't work properly in a prompt/interactive mode:

GRASS:~ > r.mapcalc
mapcalc> newmap=2 * 3
mapcalc> exit
mapcalc>

GRASS:~ > d.rast newmap
ERROR: Raster map [newmap] not available

Problem #1: "exit" doesn't work, I had to use Ctrl-c
Problem #2: newmap was not created

Problem #3 (or just a note): in a command mode, r.mapcalc behaves differently than a few months ago. Now you must have a command without spaces around "="
while in the past this command worked OK:

GRASS:~ > r.mapcalc flow.dx = "flow * cos(aspect)"
r.mapcalc - Raster map layer data calculator

usage: r.mapcalc '<map>=<expression>'

r.mapcalc performs arithmetic on raster map layers.

New raster map layers can be created which are arithmetic expressions
involving existing raster map layers, integer or floating point constants,
and functions.

For more information use 'g.manual r.mapcalc'
---

So now I have to change my scripts, but it is not a big deal...

Best regards,

Jaro Hofierka

-------------------------------------------- Managed by Request Tracker

Request Tracker wrote:

I have found that r.mapcalc doesn't work properly in a
prompt/interactive mode:

GRASS:~ > r.mapcalc
mapcalc> newmap=2 * 3
mapcalc> exit
mapcalc>

GRASS:~ > d.rast newmap
ERROR: Raster map [newmap] not available

Problem #1: "exit" doesn't work, I had to use Ctrl-c

Ctrl-C sends SIGINT to the foreground process, which kills it. If you
want to generate an end-of-file condition under Unix, type Ctrl-D.
This will work for r.mapcalc, as does typing a blank line (this is the
method which is documented in the r.mapcalc manpage).

Problem #2: newmap was not created

You killed r.mapcalc while it was still reading the expression.

Problem #3 (or just a note): in a command mode, r.mapcalc behaves
differently than a few months ago. Now you must have a command
without spaces around "=" while in the past this command worked OK:

GRASS:~ > r.mapcalc flow.dx = "flow * cos(aspect)"

I can implement that easily enough.

However, given that you have to quote most of the command (e.g. to
prevent '*' being expanded by the shell), you may as well just quote
the whole thing, i.e.

  r.mapcalc "flow.dx = flow * cos(aspect)"

[Actually, single quotes are preferable.]

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

On Fri, May 31, 2002 at 03:55:27PM +0100, Glynn Clements wrote:

Request Tracker wrote:

[...]

> Problem #3 (or just a note): in a command mode, r.mapcalc behaves
> differently than a few months ago. Now you must have a command
> without spaces around "=" while in the past this command worked OK:
>
> GRASS:~ > r.mapcalc flow.dx = "flow * cos(aspect)"

I can implement that easily enough.

Thanks Glynn. This saves us from rewriting lots of scripts and
docs. I just tested:

GRASS:~/cvsgrass_exp > r.mapcalc test="34-43"
test = (sub(34,43))
   3%...
GRASS:~/cvsgrass_exp > r.mapcalc "test=34-43"
test = (sub(34,43))
   3%...

nice.

However, given that you have to quote most of the command (e.g. to
prevent '*' being expanded by the shell), you may as well just quote
the whole thing, i.e.

  r.mapcalc "flow.dx = flow * cos(aspect)"

Really? For my bash it works:

r.mapcalc test="34 * 43"
test = (mul(34,43))

[Actually, single quotes are preferable.]

Markus

Markus Neteler wrote:

> > Problem #3 (or just a note): in a command mode, r.mapcalc behaves
> > differently than a few months ago. Now you must have a command
> > without spaces around "=" while in the past this command worked OK:
> >
> > GRASS:~ > r.mapcalc flow.dx = "flow * cos(aspect)"
>
> I can implement that easily enough.

Thanks Glynn. This saves us from rewriting lots of scripts and
docs. I just tested:

GRASS:~/cvsgrass_exp > r.mapcalc test="34-43"
test = (sub(34,43))
   3%...
GRASS:~/cvsgrass_exp > r.mapcalc "test=34-43"
test = (sub(34,43))
   3%...

nice.

Er, that's just shell behaviour; in both cases, r.mapcalc will get a
single argument.

> However, given that you have to quote most of the command (e.g. to
> prevent '*' being expanded by the shell), you may as well just quote
> the whole thing, i.e.
>
> r.mapcalc "flow.dx = flow * cos(aspect)"

Really? For my bash it works:

r.mapcalc test="34 * 43"
test = (mul(34,43))

Same here, this is still a single argument.

The issue was regarding unquoted spaces in the command line, e.g.:

  r.mapcalc test = "34 * 34"

In this case, r.mapcalc would get three arguments, i.e.

  argc: 4
  argv[0]: "r.mapcalc"
  argv[1]: "test"
  argv[2]: "="
  argv[3]: "34 * 34"

The fix duplicates the behaviour of the old r.mapcalc which, when
given multiple arguments, concatenates them into a single string, then
parses that string.

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