[GRASS-user] GRASS Scripting questions

António Rocha antonio.rocha at deimos.com.pt
Mon Jan 4 12:04:10 EST 2010


After a few emails exchanged with Glynn I finally solved this:
*export GRASS_OVERWRITE=1

r.mapcalc "$GIS_OPT_CONTADOR= float(0)"

tmp=tmp.dwe.ndviserie.$$

IFS=,
for opt in $GIS_OPT_INPUT; do
    r.mapcalc "$tmp = $opt + $GIS_OPT_CONTADOR"
    g.rename  rast=$tmp,$GIS_OPT_CONTADOR
done

r.info -r $GIS_OPT_CONTADOR*

To be noted:
- export is used in order to overwrite files
- I use a TMP that is defined by *tmp=tmp.dwe.ndviserie.$$
*- IFS is essential in order to define , as a separator symbol.

One question, Glynn: Where can I get more information about Bash script 
expression such as "export"?
Thanks

Antonio

António Rocha wrote:
> Hey
>
> I have tried Glynn's solution like this:
>
> r.mapcalc "$GIS_OPT_COUNTER= float(0)"
> tmp=tmp.myscript.$$
> for opt in $GIS_OPT_INPUT; do
>     r.mapcalc "$tmp = $opt + $GIS_OPT_COUNTER"
>     g.rename  rast=$tmp,$GIS_OPT_COUNTER
> done
>
> And I got
> */syntax error, unexpected ',', expecting $end
> Parse error
> raster <tmp.myscript.724> not found/*
>
> I changed myscript to r.ndviserie/* */(myscript filename) and i got this:
> /*syntax error, unexpected ',', expecting $end
> Parse error
> raster <tmp.dwe.ndviserie.3692> not found*/
>
> It seems that he is not recognizing tmp as a file where to store an 
> image.
> yesterday I found a reference of initializing TMP files with a 
> "r_fillnulls_". I try to find this function, or any reference to this, 
> but nothing was found. What is this?
>
> Thanks Glynn and everyone else
>
> Antonio
>
> Glynn Clements wrote:
>> António Rocha wrote:
>>
>>   
>>> Greetings Achim
>>> You are absolutely right. I made a mistake copying the expression.
>>>
>>> Here it goes:
>>> #itinialization of counter1
>>> r.mapcalc $GIS_OPT_COUNTER1= "float (0)"
>>>
>>> The cycle:
>>> IFS=,
>>> for opt in $GIS_OPT_INPUT; do
>>>    r.mapcalc $GIS_OPT_COUNTER= "$opt+$GIS_OPT_COUNTER"
>>> done                      
>>>     
>>
>> Don't use the same map as both input and output. Instead:
>>
>> 	tmp=tmp.myscript.$$
>> 	for opt in $GIS_OPT_INPUT; do
>> 		r.mapcalc "$tmp = $opt + $GIS_OPT_COUNTER"
>> 		g.rename --o rast=$tmp,$GIS_OPT_COUNTER
>> 	done
>>
>> Although for this specific task (adding a list of maps), use
>> "r.series ... method=sum".
>>
>>   
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus 
> signature database 4698 (20091218) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus 
> signature database 4743 (20100104) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4743 (20100104) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




More information about the grass-user mailing list