[GRASSLIST:1398] Re: r.mapcalc

Horacio hsamanie at bio.puc.cl
Wed Jan 24 07:23:50 EST 2001


Markus Neteler wrote:
> 
> On Tue, Jan 23, 2001 at 12:32:30PM -0300, Horacio wrote:
> > Hi,
> > I'm trying to embed r.mapcalc command in a bash script... I'm having
> > troubles understanding how r.mapcalc handles variables...
> >
> > for example in a for loop:
> >
> > r.mapcalc final_$sp_name = $sp_name && (dem <= $((max_$sp_name)) && (dem
> > >= $((min_$sp_name))
> >
> >
> > I understand that some characters can cause troubles in the shell
> > interpretation for wich I should use something like...
> >
> >
> > r.mapcalc final_$sp_name \= $sp_name \&\& \(dem \<\= $((max_$sp_name))
> > \&\& \(dem \>\= $((min_$sp_name))\)
> >
> >
> > but it still doesn't work...
> 
> Horacio,
> 
>  it's pretty easy:
> 
>  r.mapcalc final_$sp_name="formula"
>                           ^       ^
> 
> This will prevent the shell from expaning braces etc. wrongly.
> However, you will need to use the "if()" function if you want to
> test values.
> 
> See:
>  http://www.geog.uni-hannover.de/grass/gdp/html_grass5/html/r.mapcalc.html
> 
>  and the two refs mentioned in "SEE ALSO" on this page.
> 
> Hope this helps
> 
Dear friends, 

Of course that "quotes" do it... but i still have trouble (maybe b'cuz
i'm not a programer...) this is my script:

---------- start script ------------
max_acacia_caven=160
max_acaena_antarctica=1600
.
.
. 

min_acacia_caven=10
min_acaena_antarctica=100
.
.
.

for sp_name in acacia_caven acaena_antarctica acaena_magellanica ...

do
	r.mapcalc final_$sp_name = $sp_name && (dem <= $((max_$sp_name)) &&
(dem >= $((min_$sp_name)))
	g.remove  tmp_$sp_name 
done
exit 0
----------- end ---------------------


The error I get is just a: "you have confused me"!
So I think that the thing is how I define the $((variable))... I'm
boubting that GRASS understand it, although the SHELL does!
if I do:

sp_name=acacia_caven;max_acacia_caven=160;min_acacia_caven=10

echo $((max_$sp_name)) 
I get ->  160 
wich is what I need to "cut" my map....



Any idea?


Thank you very much.

Horacio

-- 
Horacio Samaniego
Dep. Ecologia
P. Universidad Catolica
Alameda 340
Santiago, Chile

Fono:  (56 2)686 2950
Fax:   (56 2)686 2621
Email: hsamanie at bio.puc.cl

(http://akodon.bio.puc.cl/horacio)




More information about the grass-user mailing list