Glynn:<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<br>
</div>Note that using the same map as both input and output results in<br>
undefined behaviour. Even if it happens to work, there's no guarantee<br>
that it will continue to work in future versions.<br>
<br>
If you need to implement an iterative algorithm, you should generate a<br>
new map, then replace the original with g.remove+g.rename afterwards.<br>
<div class="im"><br></div></blockquote><div><br>Now, you scared me, because my ongoing work is pretty much based on this kind of code. I use r.mapcalc to create maps that serve as counters such as the command i++ in C. I initialize them as zero maps and then based on some logic I keep incrementing them, pretty much like the following pseudo-code to implement a sum:<br>
<br>sum = 0<br>for i = 1 to 10<br> sum = sum + i<br>end<br><br>But I do more that that. <br><br>For instance, if certain conditions are met in other maps at a given iteration and the initialized map is zero, then update the initialized map with the value of "i". If not, don't change it. In this way, my map is updated every iteration until no more cells meet the condition or some threshold is met and processing stops. I even use d.rast to display the map as it is being updated.<br>
<br>How should I proceed to avoid the "undefined behaviour" and still get what I want? (I hope I was able to make myself understood :) )<br><br>Thanks for your comments.<br><br>Glynn:<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
There is no point in referring to your original map in the r.mapcalc<br>
expression; the result will always be created with the bounds and<br>
resolution of the current region. AFAIK, the only modules which don't<br>
behave this way are r.in.*, which create the output to match the size<br>
of the input file.<br>
<div class="im"><br></div></blockquote><div class="im"><br>Yes, Moritz's suggestion showed me that. I perfectly understand it now, thanks.<br> <br><br>Glynn:<br>
<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I'm sure that there are other ways to create a map consisting of<br>
zeros, but there's no reason to suspect that any of them will be<br>
faster than r.mapcalc.<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br> There really isn't. I just suspected it was taking too long and found out in my little experiment that was only my fault, putting a logic expression where there was no need of it. Setting the region and r.mapcalc zero_map = 0 does the job. <br>
<br>Thank you.<br><br>Best,<br>Marcello.<br></div></div><br><br>