[GRASS-dev] python percent() function: omit newlines?

Markus Neteler neteler at osgeo.org
Fri Oct 22 03:53:10 EDT 2010


On Fri, Oct 22, 2010 at 4:55 AM, Glynn Clements
<glynn at gclements.plus.com> wrote:
>
> Markus Neteler wrote:
>
>> we have a small problem with grass.core.percent; which we use
>> in a "for" loop. Unfortunately, calling the classical g.message,
>> the percent() function issues with each output a newline.
>> Since we work with very big map (around 350.000.000 cells),
>> getting that number of newlines is, say, unfortunate.
>>
>> I wonder if we need some "no newline" magic in g.message for this
>> (ne flag?) or if we can clone percent() in lib/python/core.py to not write
>> out a new line but to go just to the beginning of the line instead as
>> it is done for the topology creation progress.
>
> general/g.message/main.c:
>
>    else if (percent->answer) {
>        int i, n, s;
>        i = n = s = -1;
>        sscanf(message->answer, "%d %d %d", &i, &n, &s);
>        if (s == -1)
>            G_fatal_error(_("Unable to parse input message"));
>        G_percent(i, n, s);
>        fprintf(stderr, "\n");
>    }
>
> I really don't think that fprintf() belongs there; it should just call
> G_percent(), without adding any "enhancements" of its own.

Ah, I missed to check main.c for this. Since nothing is using "g.percent -p"
in the scripts section, I have taken out fprintf()..

Old behaviour:

GRASS 6.4.1svn (nc_spm_08):~ > g.message -p "1 1 1"
 100%

GRASS 6.4.1svn (nc_spm_08):~ >


New behaviour:

GRASS 6.4.1svn (nc_spm_08):~ > g.message -p "1 1 1"
 100%
GRASS 6.4.1svn (nc_spm_08):~ >

Markus


More information about the grass-dev mailing list