# Wrong direction in r.watershed slope length calculation?

Or have I completely misunderstood something now? As a programmer I took it for granted that the row number would change if I traversed the map up and down in the program along the North-South axis while the columns would change when I traversed the map sideways from west to east. In the raster, the (0,0) coordinate would represent the north-western-most cell, with values increasing towards the south-east.

And this fact seems supported by the following line taken from init_vars.c:

``````max_length = 10 * nrows * window.ns_res + 10 * ncols * window.ew_res;
``````

But then I found this in the code for calculating the length of the slope for a given cell in slope_len.c:

``````if (r == dr)
res = window.ns_res;
else if (c == dc)
res = window.ew_res;
else
res = diag;

if (top_ls == half_res) // half_res = initialization value
top_ls = res;
else
top_ls += res;
``````

Here we are dealing with a cell given by coordinates (r,c) which flows into another cell (dr,dc). So the code reads to me that if the two cells are on the same row, add to the slope the map's North-South resolution. Should it not be West-East since the slope is horizontal rather than vertical and vice versa for the columns?

Either I misunderstand how the length is calculated or this seems like a bug in the program for me. Also on quadratic cell sizes this will not be noticeable but it is important that I get it right for other cases.

• Please tell us which GRASS version you are looking at. Furthermore, let me recommend the grass-dev mailing list for the question (grass.osgeo.org/support/mailing-lists) Apr 3 '13 at 16:55
• 6.4.2 Stable Release. This code is still present in the latest Grass 7 snapshot created last Sunday. Apr 4 '13 at 6:24
• OK, so please contact either the author or better, the indicated developers mailing list... Apr 4 '13 at 16:09
• I've sent this question to the GRASS Developers mailing list. Apr 5 '13 at 10:01
• Actually I don't see it: lists.osgeo.org/pipermail/grass-dev/2013-April/date.html Note that you need to subscribe to post there... (to avoid spam messages). Apr 5 '13 at 18:33