I simply cannot find out the following: I want to repeat a calculation in GRASS GIS several times. Is there a command for r.mapcalc to repeat a calculation x times (similar to this possibility in r.mfilter, for example)....besides listing that step x times in s shell scripts (I use shell).
1 Answer
You can call r.mapcalc in for loop. In shell it could look like this:
X=5
# initialize first map
r.mapcalc "old = 10"
# loop
for I in `seq $X`
do
r.mapcalc "new = old + 10" --overwrite
g.rename rast=new,old --overwrite
done
In shell command seq 5
creates a sequence 1, 2, 3, 4 , 5.
Note that you shouldn't use r.mapcalc like this (read from and write in the same map):
r.mapcalc "old = old + 10" --overwrite
-
The loop in one line:
for I in `seq $X`; do r.mapcalc "new = old + 10" --overwrite && g.rename rast=new,old --overwrite; done
;-) Commented Dec 3, 2014 at 14:33