<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 10:42 AM, BLANDENIER Lucien <span dir="ltr"><<a href="mailto:lucien.blandenier@unine.ch" target="_blank">lucien.blandenier@unine.ch</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The -g flag is not valide for this module...<br>
<br></blockquote><div><div><br class="">OK, now I understand, r.sum was merged to <a href="http://grass.osgeo.org/grass70/manuals/r.statistics.html" title="r.statistics in the GRASS 7 manual" style="color:rgb(187,0,0);font-size:13px;text-decoration:none;border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(187,187,187);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif">r.statistics</a><span style="font-size:13px;color:rgb(0,0,0);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif">, </span><a href="http://grass.osgeo.org/grass70/manuals/r.statistics2.html" title="r.statistics2 in the GRASS 7 manual" style="color:rgb(187,0,0);font-size:13px;text-decoration:none;border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(187,187,187);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif">r.statistics2</a><span style="font-size:13px;color:rgb(0,0,0);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif">, </span><a href="http://grass.osgeo.org/grass70/manuals/r.statistics3.html" title="r.statistics3 in the GRASS 7 manual" style="color:rgb(187,0,0);font-size:13px;text-decoration:none;border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(187,187,187);font-family:Verdana,Arial,'Bitstream Vera Sans',Helvetica,sans-serif">r.statistics3</a> in GRASS 7, it is available only in GRASS 6.</div>

<div><br></div><div><a href="http://grass.osgeo.org/grass64/manuals/r.sum.html">http://grass.osgeo.org/grass64/manuals/r.sum.html</a><br></div><div><a href="https://trac.osgeo.org/grass/wiki/Grass7/NewFeatures">https://trac.osgeo.org/grass/wiki/Grass7/NewFeatures</a></div>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Do you know if there is others possibilities?<br>
<br></blockquote><div>Yes, use what I wrote before (explained in that email):</div><div> </div><div><span style="color:rgb(80,0,80)">$ eval $(echo "SUM = 16116.500006" | sed -e "s/ //g")</span><br style="color:rgb(80,0,80)">

<span style="color:rgb(80,0,80)">$ echo $SUM</span><br style="color:rgb(80,0,80)"><span style="color:rgb(80,0,80)">16116.500006</span><br></div><div><br></div><div>For r.sum in GRASS 6 in NC sample location:</div><div><br>

</div><div><div>> eval $(r.sum elevation | sed -e "s/ //g")</div></div><div><div>> echo $SUM</div><div>27569640.087723</div></div><div>> SUM_elevation=$SUM</div><div>> echo $SUM_elevation</div><div>
27569640.087723</div>
<div><br></div><div>or shorter</div><div><br></div><div><div>> SUM_elevation=$(r.sum elevation | sed -e "s/SUM = //g")</div></div><div>> echo $SUM_elevation</div><div>27569640.087723</div><div><br></div><div>

<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Thanks a lot<br>
<div class="im"><br>
Lucien<br>
<br>
<br>
________________________________<br>
De : Vaclav Petras [<a href="mailto:wenzeslaus@gmail.com">wenzeslaus@gmail.com</a>]<br>
</div>Envoyé : lundi 13 janvier 2014 16:34<br>
<div class="im">À : BLANDENIER Lucien<br>
Cc : <a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
Objet : Re: [GRASS-user] how to store results from r.sum with script<br>
<br>
</div><div class="im">Try remove spaces from r.sum command output (e.g. using `sed`) and since the results is<br>
<br>
SUM=16116.500006<br>
<br>
which is valid bash variable definition, you can use `eval` command which will define the variable, so you can use it afterwards.<br>
<br>
$ eval $(echo "SUM = 16116.500006" | sed -e "s/ //g")<br>
$ echo $SUM<br>
16116.500006<br>
<br>
I assume from what you have written that `r.sum rast=map@mapset` prints<br>
<br>
SUM = 16116.500006<br>
<br>
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<br>


<br>
SUM = 16116.500006<br>
<br>
<br>
</div><div class="im">On Mon, Jan 13, 2014 at 10:20 AM, BLANDENIER Lucien <<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a><mailto:<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a>>> wrote:<br>


Hello Vaclav,<br>
<br>
I tried with the following script:<br>
<br>
$C=$(r.sum rast=map@mapset)<br>
$echo $C<br>
SUM = 16116.500006<br>
<br>
<br>
But I think the variable C stores all the command (r.sum rast=map@mapset) and not only the result. Do you know how it would be possible to store the result "SUM = 16116.500006"<br>
<br>
<br>
Regards<br>
<br>
Lucien<br>
<br>
<br>
________________________________<br>
</div>De : Vaclav Petras [<a href="mailto:wenzeslaus@gmail.com">wenzeslaus@gmail.com</a><mailto:<a href="mailto:wenzeslaus@gmail.com">wenzeslaus@gmail.com</a>>]<br>
<div class="im">Envoyé : dimanche 12 janvier 2014 03:11<br>
À : BLANDENIER Lucien<br>
</div>Cc : <a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><mailto:<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>><br>
<div class="im">Objet : Re: [GRASS-user] how to store results from r.sum with script<br>
<br>
Hi,<br>
<br>
I might missed it but I don't know about r.sum module. (I know only r.sun).<br>
<br>
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).<br>


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


<br>
Vaclav<br>
<br>
<br>
$ A="some text"<br>
$ echo $A<br>
some text<br>
<br>
$ B=`echo "this is printed to stdout"`<br>
$ echo $B<br>
this is printed to stdout<br>
<br>
$ C=$(echo "this is printed to stdout")<br>
$ echo $C<br>
this is printed to stdout<br>
<br>
(lines beginning with $ are lines with command which are meant to by typed into the command line, the other lines are output)<br>
<br>
<br>
</div><div class="im">On Sat, Jan 11, 2014 at 9:32 AM, BLANDENIER Lucien <<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a><mailto:<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a>><mailto:<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a><mailto:<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a>>>> wrote:<br>


Dear all,<br>
<br>
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.<br>
<br>
I need to reuse these results in later calculations.<br>
<br>
Thanks<br>
<br>
<br>
Lucien<br>
<br>
_______________________________________________<br>
grass-user mailing list<br>
</div><a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><mailto:<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>><mailto:<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><mailto:<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>>><br>


<a href="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><br>
<br>
<br>
</blockquote></div><br></div></div>