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

Glynn Clements glynn at gclements.plus.com
Tue Mar 11 23:40:38 EDT 2008


Ivan Shmakov wrote:

>  >>> I tried running r.univar on the same map for comparison, but it
>  >>> crashed while trying to compute the percentile (the other
>  >>> statistics were computed okay).
> 
>  >> Is it due to the memory allocation issues, or?
> 
>  > I don't know. 30m cells * 8 bytes per cell = ~240MiB. The system has
>  > 1GiB of swap, so malloc() shouldn't fail.
> 
> $ nl -ba stats.c 
> ...
>    135	    /* TODO: mode, skewness, kurtosis */
>    136	    if (param.extended->answer) {
>    137		qpos_perc = (int *) G_calloc(stats->n_perc, sizeof(int));
>    138		quartile_perc = (double *) G_calloc(stats->n_perc, sizeof(double));
>    139		for (i = 0; i < stats->n_perc; i++) {
>    140		    qpos_perc[i] = (int) (stats->n * stats->perc[i] / 100. - 0.5);
>    141		}
> ...
> $ 
> 
> 	Here, it should rather be, e. g.:
> 
>    qpos_perc[i] = (int) (stats->n * 1e-2 * stats->perc[i] - 0.5);

Right.

> 	(BTW, would it benefit from an explicit round ()?)

I don't think so. Also, just removing the -0.5 would give the same
result as round().

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


More information about the grass-dev mailing list