# [GRASSLIST:3366] Re: r.mapcalc syntax

Glynn Clements glynn.clements at virgin.net
Thu May 6 17:42:51 EDT 2004

```Ulrich Leopold wrote:

> I am using the following command and get an parse error expecting ")"
>
> r.mapcalc Errors="if('VAL.stone.lsk_OK.DIFF_SQRT_VAR' < -2,
> ('500.Pox0t30.STONE' - ('Pox0t30_OK_block.pred.LSK' - (2 *
> (sqrt('Pox0t30_OK_block.var.LSK')))/('500.Pox0t30.STONE') * -100),
> null() ))"
>
> parse error, expecting ")"
> Parse error
>
> What am I doing wrong. I checked the position of the parenthesis. But I
> cannot figure out where a parenthesis is missing. The similar command
> works in the statistics package 'R'.

First, I'll replace the map names by X to make the structure more
clear:

if(X < -2, (X - (X - (2 * (sqrt(X)))/(X) * -100), null() ))

Look at the nesting of the parentheses:

if(X < -2, (X - (X - (2 * (sqrt(X)))/(X) * -100), null() ))
-----------------------------------------------
---------------------------------------------------------

This expression has the form:

if(A, (B, C))

where:
A ==	X < -2
B ==	X - (X - (2 * (sqrt(X)))/(X) * -100)
C ==	null()

However, (B,C) isn't a valid expression. You probably wanted to omit
the parentheses to give:

if(A, B, C)

which is valid.

So, your command should probably be:

r.mapcalc Errors="if('VAL.stone.lsk_OK.DIFF_SQRT_VAR' < -2,
'500.Pox0t30.STONE' - ('Pox0t30_OK_block.pred.LSK' - (2 *
(sqrt('Pox0t30_OK_block.var.LSK')))/('500.Pox0t30.STONE') * -100),
null())"

Regarding the reason why the error message says "expecting ')'":

When the parser gets to:

if(A, (B,

it can't parse the comma, because a comma is only valid within a
function's argument list. However, if there had been a closing
parenthesis before the comma, it would have:

if(A, (B),

The comma would be part of the argument list for if(), and so would be
valid. Hence the "expecting ')'" message.

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

```