[GRASSLIST:3365] r.mapcalc syntax

Hi,

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'.

Ulrich
--
__________________________________________________

Ulrich Leopold MSc.

Computational Bio- and Physical Geography (CBPG)
Institute for Biodiversity and Ecosystem Dynamics (IBED)
Faculty of Science
University of Amsterdam
Nieuwe Achtergracht 166
NL-1018WV Amsterdam

Room: B2.52
Phone: +31 20 525 7456 (7451 Secretary)
Fax: +31 20 525 7431
Mobile: +31 64 220 3028
Email: uleopold@science.uva.nl
URL: www.science.uva.nl/ibed/cbpg

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@virgin.net>