GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72272
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
percent.c File Reference

GIS Library - percentage progress functions. More...

#include <stdio.h>
#include <grass/gis.h>
Include dependency graph for percent.c:

Go to the source code of this file.

Functions

void G_percent (long n, long d, int s)
 Print percent complete messages. More...
 
void G_percent_reset (void)
 Reset G_percent() to 0%; do not add newline. More...
 
void G_progress (long n, int s)
 Print progress info messages. More...
 
void G_set_percent_routine (int(*percent_routine)(int))
 Establishes percent_routine as the routine that will handle the printing of percentage progress messages. More...
 
void G_unset_percent_routine (void)
 After this call subsequent percentage progress messages will be handled in the default method. More...
 

Detailed Description

GIS Library - percentage progress functions.

(C) 2001-2009, 2011 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.

Author
GRASS GIS Development Team

Definition in file percent.c.

Function Documentation

void 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%.

Parameters
ncurrent element
dtotal number of elements
sincrement size

Definition at line 62 of file percent.c.

References G_info_format(), G_INFO_FORMAT_PLAIN, G_INFO_FORMAT_SILENT, G_INFO_FORMAT_STANDARD, G_verbose(), and x.

Referenced by G_math_cholesky_sband_decomposition(), Gs_loadmap_as_char(), Gs_loadmap_as_float(), Gs_loadmap_as_int(), Gs_loadmap_as_short(), Gs_pack_colors(), Gs_pack_colors_float(), IL_interp_segments_2d(), IL_interp_segments_2d_parallel(), IL_resample_interp_segments_2d(), N_gwflow_2d_calc_water_budget(), N_gwflow_3d_calc_water_budget(), N_read_rast3d_to_array_3d(), N_read_rast_to_array_2d(), N_write_array_2d_to_rast(), N_write_array_3d_to_rast3d(), NetA_betweenness_closeness(), NetA_spanning_tree(), P_Aux_to_Raster(), Rast3d_retile(), Vect__copy_areas(), Vect_break_polygons_file(), Vect_break_polygons_mem(), Vect_build_nat(), Vect_clean_small_angles_at_nodes(), Vect_merge_lines(), Vect_net_build_graph(), Vect_net_ttb_build_graph(), Vect_remove_duplicates(), Vect_remove_small_areas_ext(), and Vect_remove_small_areas_nat().

void G_percent_reset ( void  )

Reset G_percent() to 0%; do not add newline.

Definition at line 119 of file percent.c.

Referenced by NetA_betweenness_closeness(), and NetA_spanning_tree().

void G_progress ( long  n,
int  s 
)

Print progress info messages.

Use G_percent() when number of elements is defined.

This routine prints a progress info message to stderr. The value n is printed only for each s. This is perhaps best explained by example:

#include <grass/vector.h>
int line;
G_message(_("Reading features..."));
line = 0;
while(TRUE)
{
if (Vect_read_next_line(Map, Points, Cats) < 0)
break;
line++;
G_progress(line, 1e3);
}
G_progress(1, 1);

This example code will print progress in messages at 1000 increments; i.e., 1000, 2000, 3000, 4000, etc., up to number of features for given vector map. Each message does not appear on a new line, but rather erases the previous message.

Parameters
ncurrent element
sincrement size
Returns
always returns 0

Definition at line 160 of file percent.c.

References G_info_format(), G_INFO_FORMAT_PLAIN, G_INFO_FORMAT_SILENT, and G_verbose().

Referenced by Vect_build_nat().

void G_set_percent_routine ( int(*)(int percent_routine)

Establishes percent_routine as the routine that will handle the printing of percentage progress messages.

Parameters
percent_routineroutine will be called like this: percent_routine(x)

Definition at line 192 of file percent.c.

void G_unset_percent_routine ( void  )

After this call subsequent percentage progress messages will be handled in the default method.

Percentage progress messages are printed directly to stderr.

Definition at line 203 of file percent.c.

References NULL.