[GRASS-dev] r.sum - parsable for shell scripts

Hamish hamish_nospam at yahoo.com
Sun Nov 26 20:39:28 EST 2006

> Jachym wrote:
> > r.sum produced result with spaces:
> > SUM = 8787936.000000
> > 
> > which makes it hard parable for shell scripts:
> > eval `r.sum rast=soils --q`
> > bash: SUM: command not found
> > 
> > IMHO there is no barrier to remove this white spaces, so the that
> > result looks like 
> > SUM=8787936.000000
> > 
> > and one can easily perform something like 
> > eval `r.sum rast=soils --q`
> > echo $SUM
> > 8787936.000000
> > 
> > I allready sent this to cvs - I'm just asking, to be sure.

> This is certainly a good approach what you have done, but I'm not
> really sure such changes should be allowed during 6.x. Maybe postpone
> it until GRASS 7? There might be users scripts that use r.sum and we
> never know how they parse r.sum's output. But maybe I'm just too
> cautious. What do others think?

cautious is good. This module is very likely to be used in scripts, so
I'd suggest keeping it's output the same during GRASS 6.x.

just guessing how folks might parse that currently,
awk '{print $3}'
cut -f3 -d' '

If parsable output is desired, add a "-g" flag to do that.

As this module gives the same result as r.univar, for future development
I suggest depreciating the module and recommending the user just use
r.univar instead of r.sum. It is slightly slower but the more code
consolidation we do the better IMO.

see also:

ie these modules:
  r.sum, r.mode, r.median, r.average, r.statistics, r.univar, r.univar2
might be reduced to just:
  r.statistics and r.univar ?

(I don't use r.mode, r.median, r.average, r.statistics, so don't know if
it is worth keeping r.statistics or push r.univar + r.mask|r.reclass ?)


More information about the grass-dev mailing list