[GRASS-user] summation

Wolf Bergenheim wolf+grass at bergenheim.net
Fri Jul 13 02:22:54 EDT 2007


Hi.

On 13.07.2007 05:28, goldneaa at onid.orst.edu wrote:
> Thank you very much you have helped me tremendously, I am very new to
> scripting so just seeing the syntax helps a lot.

My pleasure, but beware of purists. They say you should not write
scripts in csh ;) (http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/)

> Using that script you sent me is there a way to pull in all 2000 or less
> rasters at one time using that script or by using a loop script.  Like
> if I have (temp.1 through temp.1500) and wanted to sum all of them into
> one map.

That is exactly what this script does. Hmm or should do. But there is a
bug. here is the correct version:

---------8<--------------------8<-------------
#!/usr/bin/tcsh

set tmp=2
set sstr="tmp.1"
set erase="tmp.1"
while($tmp <= 11)
  @ t = $tmp - 1
  set str="tmp.$t=ts.1"
  set i=2
  while($i <= 200)
    @ ti = $t * $i
    set str="$str+ts.$ti"
    @ i++
  end
  echo r.mapcalc $str
  r.mapcalc $str
  if($tmp <= 10) then
    set sstr="$sstr+tmp.$tmp"
    set erase="$erase,tmp.$tmp"
  endif
  @ tmp++
end
echo r.mapcalc res=$sstr
r.mapcalc res=$sstr
echo g.remove rast=$erase
g.remove rast=$erase
---------8<--------------------8<-------------

It sums up all the ts.1 through ts.2000 to res. Just change ts. to temp.
and change 200 to 150 and you will get it for temp.1 through temp.1500.
This version also cleans up the temp files it creates.

I don't know what you mean by one go, but you could also write it not to
use temporary files like this, but I suspect it will be much slower.

---------8<--------------------8<-------------
#!/usr/bin/tcsh

set tmp=2

echo r.mapcalc res=ts.1
r.mapcalc res=ts.1
while($tmp <= 2000)
  echo r.mapcalc res=res+ts.$tmp
  r.mapcalc res=res+ts.$tmp
  @ tmp++
end
---------8<--------------------8<-------------

--Wolf

-- 

<:3 )---- Wolf Bergenheim ----( 8:>




More information about the grass-user mailing list