[GRASS-dev] r.univar: allow multiple rasters to be processed

Glynn Clements glynn at gclements.plus.com
Thu Feb 21 06:53:37 EST 2008


Ivan Shmakov wrote:

> 	The following change allows multiple rasters to be processed
> 	with `r.univar'.

Is there some fundamental reason why r.univar has separate cases for
CELL/FCELL/DCELL types, rather than just working in DCELL throughout?

Most of the time, there's no value to having separate CELL/FCELL
cases. There's hardly ever a reason to have a separate FCELL case, and
a separate CELL case is only really useful if you specifically need
integer-specific operations (e.g. integer division, bitwise operations
etc).

I'm aware that r.univar was already like this, but if there isn't a
valid reason, this would be a good time to simplify it.

Apart from anything else, the calculation of the square:

>  	    if (map_type == CELL_TYPE) {
> -		val_i = *((CELL *) ptr);
> +		const int val_i = *((CELL *) ptr);
>  
>  		stats->sum += val_i;
>  		stats->sumsq += (val_i * val_i);

will wrap if abs(val_i) > 46340 (sqrt(2^31) = 46340.95).

If the three separate cases are to be kept, the last line above should
be:

		stats->sumsq += (double) val_i * val_i;

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list