[GRASSLIST:279] r.mapcalc puzzler

Hi -

I'm using a modification of the script given here:
http://op.gfz-potsdam.de/GRASS-List/Archive/msg07811.html

which includes the following mapcalc magic to do a better r.grow:

r.mapcalc << EOF
grown = if( $src, $src, \\
   if($src[0,-1], $src[0,-1], \\
    if( $src[0,1], $src[0,1], \\
     if($src[-1,0], $src[-1,0], \\
      if( $src[1,0], $src[1,0] \\
  )))))
EOF

Now this was working fine.. but after playing with the script it would
break on the mapcalc line with:

undefined function:
Syntax error

Ok so looking through it, I can't make sense why it is failing. Adding a
",0" to the last "if" fixes it, but that shouldn't be necessary:

if(x,a) a if x not zero, 0 otherwise
if(x,a,b) a if x not zero, b otherwise

I tried removing all whitespace too, no luck.

I've got it working now with the extra, just can't figure out why
it broke, which bugs me. This is the r.mapcalc3 from 5.0.2, bash, and
linux.

previously, I'd gotten this error:
Illegal filename. character <> not allowed.ERROR: open_map: map not found
when I had src=grown.tmp$$. That went away sometime after I made
it just grown.tmp though.

Can't see what I'm missing.
?

thanks,
Hamish

H Bowman wrote:

I'm using a modification of the script given here:
http://op.gfz-potsdam.de/GRASS-List/Archive/msg07811.html

which includes the following mapcalc magic to do a better r.grow:

r.mapcalc << EOF
grown = if( $src, $src, \\
   if($src[0,-1], $src[0,-1], \\
    if( $src[0,1], $src[0,1], \\
     if($src[-1,0], $src[-1,0], \\
      if( $src[1,0], $src[1,0] \\
  )))))
EOF

Now this was working fine.. but after playing with the script it would
break on the mapcalc line with:

undefined function:
Syntax error

Ok so looking through it, I can't make sense why it is failing. Adding a
",0" to the last "if" fixes it, but that shouldn't be necessary:

if(x,a) a if x not zero, 0 otherwise
if(x,a,b) a if x not zero, b otherwise

I tried removing all whitespace too, no luck.

I've got it working now with the extra, just can't figure out why
it broke, which bugs me. This is the r.mapcalc3 from 5.0.2, bash, and
linux.

previously, I'd gotten this error:
Illegal filename. character <> not allowed.ERROR: open_map: map not found
when I had src=grown.tmp$$. That went away sometime after I made
it just grown.tmp though.

Can't see what I'm missing.

I can't reproduce the problem here.

Could some kind of non-printing character have crept into the script?

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

Don't you need quotes around a complicated expression like that? I've
always used %> r.mapcalc "a=sin(b)+cos(c)" so that the special
characters don't throw the shell into a tizzy.

md

-----Original Message-----
From: owner-GRASSLIST@baylor.edu [mailto:owner-GRASSLIST@baylor.edu] On
Behalf Of H Bowman
Sent: Tuesday, June 03, 2003 4:21 AM
To: grass list
Subject: [GRASSLIST:279] r.mapcalc puzzler

Hi -

I'm using a modification of the script given here:
http://op.gfz-potsdam.de/GRASS-List/Archive/msg07811.html

which includes the following mapcalc magic to do a better r.grow:

r.mapcalc << EOF
grown = if( $src, $src, \\
   if($src[0,-1], $src[0,-1], \\
    if( $src[0,1], $src[0,1], \\
     if($src[-1,0], $src[-1,0], \\
      if( $src[1,0], $src[1,0] \\
  )))))
EOF

Now this was working fine.. but after playing with the script it would
break on the mapcalc line with:

undefined function:
Syntax error

Ok so looking through it, I can't make sense why it is failing. Adding a
",0" to the last "if" fixes it, but that shouldn't be necessary:

if(x,a) a if x not zero, 0 otherwise
if(x,a,b) a if x not zero, b otherwise

I tried removing all whitespace too, no luck.

I've got it working now with the extra, just can't figure out why
it broke, which bugs me. This is the r.mapcalc3 from 5.0.2, bash, and
linux.

previously, I'd gotten this error:
Illegal filename. character <> not allowed.ERROR: open_map: map not
found
when I had src=grown.tmp$$. That went away sometime after I made
it just grown.tmp though.

Can't see what I'm missing.
?

thanks,
Hamish

> Don't you need quotes around a complicated expression like that?
> I've always used %> r.mapcalc "a=sin(b)+cos(c)" so that the special
> characters don't throw the shell into a tizzy.

Not if it is within a << EOF .. EOF; it treats whatever's inside as if
it were a file on the disk. Using ""s are necessary to protect the () *
etc from being interpreted as part of the command, ''s are even more
restrictive and stop $SHELL_VARIABLES from being expanded.

I think my problem was cutting and pasting between a Debian xterm and a
RedHat9 one. Redhat's gone and changed all their language encoding
around, and I think ASCII tabs get interpreted as special characters in
whatever Unicode system they now use..??

which includes the following mapcalc magic to do a better r.grow:

r.mapcalc << EOF
grown = if( $src, $src, \\
   if($src[0,-1], $src[0,-1], \\
    if( $src[0,1], $src[0,1], \\
     if($src[-1,0], $src[-1,0], \\
      if( $src[1,0], $src[1,0] \\
  )))))
EOF