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

Hi,

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.

Thanks

Jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
Zemedelska 3
613 00, Brno
Czech Republick
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

Jachym Cepicky wrote:

Hi,

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.

Jachym,

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?

Thanks for the huge portion of your recent cleanups and fixes in the
CVS! Great job!

All Best,
Maciek

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.

Maciek:

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}'
or
cut -f3 -d' '
or
...?

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:
  https://intevation.de/rt/webrt?serial_num=1848

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 ?)

Hamish

allright,
as usage of r.sum is deprecated, I added one line with comment to the
module and put the whitespaces back

jachym

On Mon, Nov 27, 2006 at 02:39:28PM +1300, Hamish wrote:

> 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.

Maciek:
> 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}'
or
cut -f3 -d' '
or
...?

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:
  https://intevation.de/rt/webrt?serial_num=1848

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 ?)

Hamish

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
Zemedelska 3
613 00, Brno
Czech Republick
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514