[GRASS-dev] mean value bug?
Peng Du
du at cs.utk.edu
Tue Nov 24 16:52:32 EST 2009
Hi, the following part is from code grass-6.4.0RC5/imagery/i.pca/main.c
static int calc_mu(int *fds, double *mu, int bands)
{
...
...
for (row = 0; row < rows; row++) {
void *ptr = rowbuf;
if(G_verbose() > G_verbose_std())
G_percent(row, rows - 1, 2);
if (G_get_raster_row(fds[i], rowbuf, row, maptype) < 0)
G_fatal_error(_("Unable to read raster map row %d"), row);
for (col = 0; col < cols; col++) {
/* skip null cells */
if (G_is_null_value(rowbuf, maptype)) {
ptr = G_incr_void_ptr(ptr, G_raster_size(maptype));
continue;
}
sum += G_get_raster_value_d(rowbuf, maptype);
ptr = G_incr_void_ptr(ptr, G_raster_size(maptype));
}
}
...
...
}
Correct me if I'm wrong, but I can't seem to tell how variable ptr is
used. This two loops are accumulating values in a certain band and ptr
points to the data value:
sum += G_get_raster_value_d(rowbuf, maptype);
Shouldn't the first parameter of G_get_raster_value_d be ptr rather than
rowbuf? Otherwise only the very first value in a certain row of this
band is touched.
Thanks,
Peng Du
More information about the grass-dev
mailing list