#include <stdio.h>
#include <grass/gis.h>
Go to the source code of this file.
Functions | |
int | G_percent (long n, long d, int s) |
Print percent complete messages. | |
int | G_percent2 (long n, long d, int s, FILE *out) |
Print percent complete messages. | |
int | G_percent_reset (void) |
Reset G_percent() to 0%; do not add newline. |
(C) 2001-2008 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file percent.c.
int G_percent | ( | long | n, | |
long | d, | |||
int | s | |||
) |
Print percent complete messages.
This routine prints a percentage complete message to stderr. The percentage complete is (n/d)*100, and these are printed only for each s percentage. This is perhaps best explained by example:
#include <stdio.h> #include <grass/gis.h> int row; int nrows; nrows = 1352; // 1352 is not a special value - example only G_message(_("Percent complete...")); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 10); do_calculation(row); } G_percent(1, 1, 1);
This example code will print completion messages at 10% increments; i.e., 0%, 10%, 20%, 30%, etc., up to 100%. Each message does not appear on a new line, but rather erases the previous message.
Note that to prevent the illusion of the module stalling, the G_percent() call is placed before the time consuming part of the for loop, and an additional call is generally needed after the loop to "finish it off" at 100%.
n | current element | |
d | total number of elements | |
s | increment size |
Definition at line 64 of file percent.c.
References G_percent2().
int G_percent2 | ( | long | n, | |
long | d, | |||
int | s, | |||
FILE * | out | |||
) |
Print percent complete messages.
This routine prints a percentage complete message to the file given by the out parameter. Otherwise usage is the same as G_percent().
n | current element | |
d | total number of elements | |
s | increment size | |
[out] | out | file to print to |
Definition at line 84 of file percent.c.
References G_info_format(), G_verbose(), and NULL.
Referenced by G_percent().
int G_percent_reset | ( | void | ) |