[GRASS-SVN] r49070 - in grass/trunk: include lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 3 08:04:22 EDT 2011


Author: martinl
Date: 2011-11-03 05:04:22 -0700 (Thu, 03 Nov 2011)
New Revision: 49070

Modified:
   grass/trunk/include/gisdefs.h
   grass/trunk/lib/gis/percent.c
Log:
libgis: add G_progress()
	update doxygen strings for percent.c


Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2011-11-03 11:15:03 UTC (rev 49069)
+++ grass/trunk/include/gisdefs.h	2011-11-03 12:04:22 UTC (rev 49070)
@@ -489,6 +489,7 @@
 /* percent.c */
 void G_percent(long, long, int);
 void G_percent_reset(void);
+void G_progress(long, int);
 void G_set_percent_routine(int (*) (int));
 void G_unset_percent_routine(void);
 

Modified: grass/trunk/lib/gis/percent.c
===================================================================
--- grass/trunk/lib/gis/percent.c	2011-11-03 11:15:03 UTC (rev 49069)
+++ grass/trunk/lib/gis/percent.c	2011-11-03 12:04:22 UTC (rev 49070)
@@ -1,16 +1,16 @@
 
-/**
- * \file gis/percent.c
- *
- * \brief GIS Library - percentage progress functions.
- *
- * (C) 2001-2009 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
- */
+/*!
+  \file lib/gis/percent.c
+  
+  \brief 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
+*/
 
 #include <stdio.h>
 #include <grass/gis.h>
@@ -23,14 +23,14 @@
 static struct state *st = &state;
 static int (*ext_percent) (int);
 
-/**
- * \brief Print percent complete messages.
- *
- * This routine prints a percentage complete message to stderr. The
- * percentage complete is <i>(<b>n</b>/<b>d</b>)*100</i>, and these are 
- * printed only for each <b>s</b> percentage. This is perhaps best 
- * explained by example:
-\code
+/*!
+  \brief Print percent complete messages.
+  
+  This routine prints a percentage complete message to stderr. The
+  percentage complete is <i>(<b>n</b>/<b>d</b>)*100</i>, and these are 
+  printed only for each <b>s</b> percentage. This is perhaps best 
+  explained by example:
+  \code
   #include <stdio.h>
   #include <grass/gis.h>
   int row;
@@ -44,24 +44,21 @@
       do_calculation(row);
   }
   G_percent(1, 1, 1);
-\endcode
- *
- * 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%.
- *
- * \param n current element
- * \param d total number of elements
- * \param s increment size
- *
- * \return always returns 0
- */
-
+  \endcode
+ 
+  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%.
+  
+  \param n current element
+  \param d total number of elements
+  \param s increment size
+*/
 void G_percent(long n, long d, int s)
 {
     int x, format;
@@ -116,36 +113,93 @@
     }
 }
 
-
-/**
- * \brief Reset G_percent() to 0%; do not add newline.
- *
- * \return always returns 0
- */
-
+/*!
+  \brief Reset G_percent() to 0%; do not add newline.
+*/
 void G_percent_reset(void)
 {
     st->prev = -1;
     st->first = 1;
 }
 
-/**
- * \brief Establishes percent_routine as the routine that will handle
- * the printing of percentage progress messages.
- * 
- * \param percent_routine routine will be called like this: percent_routine(x)
- */
+/*!
+  \brief Print progress info messages
+
+  Use G_percent() when number of elements is defined.
+  
+  This routine prints a progress info message to stderr. The value
+  <b>n</b> is printed only for each <b>s</b>. This is perhaps best
+  explained by example:
+  \code
+  #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);
+  \endcode
+ 
+  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.
+  
+  \param n current element
+  \param s increment size
+  
+  \return always returns 0
+*/
+void G_progress(long n, int s)
+{
+    int format;
+    
+    format = G_info_format();
+    
+    /* be verbose only 1> */
+    if (format == G_INFO_FORMAT_SILENT || G_verbose() < 1)
+	return;
+    
+    if (n == s && n == 1) {
+	if (format != G_INFO_FORMAT_PLAIN)
+	    fprintf(stderr, "\r");
+	else
+	    fprintf(stderr, "\n");
+	return;
+    }
+
+    if (n % s == 0) {
+	if (format == G_INFO_FORMAT_PLAIN)
+	    fprintf(stderr, "%ld..", n);
+	else
+	    fprintf(stderr, "%10ld\b\b\b\b\b\b\b\b\b\b", n);
+    }
+}
+
+/*!
+  \brief Establishes percent_routine as the routine that will handle
+  the printing of percentage progress messages.
+  
+  \param percent_routine routine will be called like this: percent_routine(x)
+*/
 void G_set_percent_routine(int (*percent_routine) (int))
 {
     ext_percent = percent_routine;
 }
 
-/**
- * \brief After this call subsequent percentage progress messages will
- * be handled in the default method.
- * 
- * Percentage progress messages are printed directly to stderr.
- */
+/*!
+  \brief After this call subsequent percentage progress messages will
+  be handled in the default method.
+  
+  Percentage progress messages are printed directly to stderr.
+*/
 void G_unset_percent_routine(void)
 {
     ext_percent = NULL;



More information about the grass-commit mailing list