[GRASS-dev] Re: G_percent() usage;

re r34816, http://trac.osgeo.org/grass/changeset/34816

G_percent() is needed after the loop has finished, otherwise "100%\n" is
never printed, and the GUI progress bar* stalls at almost-complete.

consider the order of what happens here, and when will row==nrows (ie 100%):
  for (row = 0; row < nrows; row++) { printf("row=%d\n", row); }
  G_percent(row, nrows, 2);

[*] (at least in gis.m, I don't know if that's true for the wxGui, but
probably)

thanks,
Hamish

Hamish wrote:

re r34816, http://trac.osgeo.org/grass/changeset/34816

G_percent() is needed after the loop has finished, otherwise "100%\n" is
never printed, and the GUI progress bar* stalls at almost-complete.

consider the order of what happens here, and when will
row==nrows (ie 100%):
  for (row = 0; row < nrows; row++) { printf("row=%d\n", row); }
  G_percent(row, nrows, 2);

ok, I see what you did now with
  G_percent(row+1, nrows, 2);

in the loop. But I think that's wrong. For one thing it incorrectly skips
0% done. (typically harmlessly corrected in rounding, but still
incorrect..)

maybe it's just me, but I prefer the historical way.

:confused:
Hamish

Hamish wrote:

> G_percent() is needed after the loop has finished, otherwise "100%\n" is
> never printed, and the GUI progress bar* stalls at almost-complete.
>
> consider the order of what happens here, and when will
> row==nrows (ie 100%):
> for (row = 0; row < nrows; row++) { printf("row=%d\n", row); }
> G_percent(row, nrows, 2);

ok, I see what you did now with
  G_percent(row+1, nrows, 2);

in the loop. But I think that's wrong. For one thing it incorrectly skips
0% done. (typically harmlessly corrected in rounding, but still
incorrect..)

maybe it's just me, but I prefer the historical way.

IMHO, we want 0% at the very beginning of the operation, and we need
100% at the end.

Ergo, if there are N iterations, G_percent() needs to be called N+1
times (0 to N inclusive), which means that there must be two calls:
one inside the loop, one outside.

For that, you can either call it with 0 before the loop and row+1 at
the end of each iteration, or with row at the start of each iteration
and rows after the loop. I suggest the latter.

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