[GRASS-user] how to store results from r.sum with script

BLANDENIER Lucien lucien.blandenier at unine.ch
Mon Jan 13 07:42:08 PST 2014


The -g flag is not valide for this module...

Do you know if there is others possibilities?

Thanks a lot

Lucien


________________________________
De : Vaclav Petras [wenzeslaus at gmail.com]
Envoyé : lundi 13 janvier 2014 16:34
À : BLANDENIER Lucien
Cc : grass-user at lists.osgeo.org
Objet : Re: [GRASS-user] how to store results from r.sum with script

Try remove spaces from r.sum command output (e.g. using `sed`) and since the results is

SUM=16116.500006

which is valid bash variable definition, you can use `eval` command which will define the variable, so you can use it afterwards.

$ eval $(echo "SUM = 16116.500006" | sed -e "s/ //g")
$ echo $SUM
16116.500006

I assume from what you have written that `r.sum rast=map at mapset` prints

SUM = 16116.500006

to standard output. Knowing what is the output of that module is crucial. What module is this, do you have documentation? GRASS modules (in GRASS distribution) use the convention that if you use `-g` flag they print the variables in "shell script style", so you can use the output in eval function or parse it easily. They output would be

SUM = 16116.500006


On Mon, Jan 13, 2014 at 10:20 AM, BLANDENIER Lucien <lucien.blandenier at unine.ch<mailto:lucien.blandenier at unine.ch>> wrote:
Hello Vaclav,

I tried with the following script:

$C=$(r.sum rast=map at mapset)
$echo $C
SUM = 16116.500006


But I think the variable C stores all the command (r.sum rast=map at mapset) and not only the result. Do you know how it would be possible to store the result "SUM = 16116.500006"


Regards

Lucien


________________________________
De : Vaclav Petras [wenzeslaus at gmail.com<mailto:wenzeslaus at gmail.com>]
Envoyé : dimanche 12 janvier 2014 03:11
À : BLANDENIER Lucien
Cc : grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org>
Objet : Re: [GRASS-user] how to store results from r.sum with script

Hi,

I might missed it but I don't know about r.sum module. (I know only r.sun).

Saving standard output of module (if it prints something to standard output) is the same as for any other command line tool in bash. If the output is a map (in GRASS) just use it as input to some other module (using the map name).

Examples bellow show saving outputs of echo command to variables (echo command just print its parameters to standard output, i.e. to command line). Working with numbers (additions, multiplications) can be more difficult (requires different syntax) but there should be some online guides.

Vaclav


$ A="some text"
$ echo $A
some text

$ B=`echo "this is printed to stdout"`
$ echo $B
this is printed to stdout

$ C=$(echo "this is printed to stdout")
$ echo $C
this is printed to stdout

(lines beginning with $ are lines with command which are meant to by typed into the command line, the other lines are output)


On Sat, Jan 11, 2014 at 9:32 AM, BLANDENIER Lucien <lucien.blandenier at unine.ch<mailto:lucien.blandenier at unine.ch><mailto:lucien.blandenier at unine.ch<mailto:lucien.blandenier at unine.ch>>> wrote:
Dear all,

I would like to know if there is a way to store results of a calculation done with r.sum on many raster with a bash script.

I need to reuse these results in later calculations.

Thanks


Lucien

_______________________________________________
grass-user mailing list
grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org><mailto:grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org>>
http://lists.osgeo.org/mailman/listinfo/grass-user




More information about the grass-user mailing list