[GRASS-dev] [bug #3960] (grass) r.watershed: 0's should be NULL for basins, streams

Hamish Bowman via RT grass-bugs at intevation.de
Thu Nov 9 01:44:05 EST 2006

this bug's URL: http://intevation.de/rt/webrt?serial_num=3960

Request number 3960 was commented on by 'hbowman' (Hamish Bowman). 
Responding to this message will send mail to the requestor.
			Request Tracker
			rt at intevation.de

Cc: grass-dev at grass.itc.it

[r.watershed: 0's should be NULL for basins,half.basins,streams]

this could be done in ram/close_maps2.c:

/* basins map */
    if (bas_flag) {
        map_fd = G_open_cell_new(bas_name);
        for (r=0; r<nrows; r++) {
	    for (c=0; c<ncols; c++) {
		cellrow[c] = bas[SEG_INDEX(bas_seg, r, c)];
            G_put_raster_row(map_fd, cellrow, CELL_TYPE);
	G_write_colors(bas_name, this_mapset, &colors);

with a test for zero in the for(c=0; c<ncols; c++) loop.

Usually it would be better to put the setting to NULL in the fn that populates
the "bas" array, but AFAIC grasp the data is stored in memory in such a way
that this doesn't make sense -- only cells with real data are stored in memory.

for streams map (apparently seg_flag in close_maps2.c), this would be
something like
	    for (c=0; c<ncols; c++) {
		value = FLAG_GET(swale, r, c);
		if (value)
		    cellrow[c] = bas[SEG_INDEX(bas_seg, r, c)];
-		else cellrow[c] = 0;
+               else G_set_c_null_value(cellrow+c, 1); // ??????
            G_put_raster_row(map_fd, cellrow, CELL_TYPE);

or start each new row by init'ing it to all NULL:
G_set_c_null_value(cellrow, ncols);

and then remove the else/*if(value)*/.

I don't know which is more efficient.


-------------------------------------------- Managed by Request Tracker

More information about the grass-dev mailing list