[GRASS-SVN] r31322 - grass/branches/develbranch_6/lib/ogsf

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 12 11:52:14 EDT 2008


Author: martinl
Date: 2008-05-12 11:52:14 -0400 (Mon, 12 May 2008)
New Revision: 31322

Modified:
   grass/branches/develbranch_6/lib/ogsf/GS2.c
   grass/branches/develbranch_6/lib/ogsf/GSX.c
   grass/branches/develbranch_6/lib/ogsf/Gp3.c
   grass/branches/develbranch_6/lib/ogsf/Gs3.c
   grass/branches/develbranch_6/lib/ogsf/Gv3.c
   grass/branches/develbranch_6/lib/ogsf/Gvl3.c
   grass/branches/develbranch_6/lib/ogsf/gk.c
   grass/branches/develbranch_6/lib/ogsf/gsd_legend.c
   grass/branches/develbranch_6/lib/ogsf/gvl_file.c
Log:
ogsflib: doxygenization in progress
better error-handling


Modified: grass/branches/develbranch_6/lib/ogsf/GS2.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/GS2.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/GS2.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -1613,8 +1613,9 @@
     mapset = G_find_cell2(filename, "");
     if (mapset == NULL) {
 	/* Check for valid filename */
-	G_fatal_error ("Raster map <%s> not found",
-		       G_fully_qualified_name(filename, mapset));
+	G_warning ("Raster map <%s> not found",
+		   filename);
+	return -1;
     }
     filename = G_fully_qualified_name(filename, mapset);
 

Modified: grass/branches/develbranch_6/lib/ogsf/GSX.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/GSX.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/GSX.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -22,6 +22,11 @@
 
 static int Cxl = 0;
 
+/*!
+  \brief Check cancel
+
+  \return code
+*/
 int GS_check_cancel(void)
 {
     Cxl_func();
@@ -29,6 +34,9 @@
     return (Cxl);
 }
 
+/*!
+  \brief Set cancel
+*/
 void GS_set_cancel(int c)
 {
     Cxl = c;
@@ -36,6 +44,11 @@
     return;
 }
 
+/*!
+  \brief Set cxl function
+
+  \param pointer to function
+*/
 void GS_set_cxl_func(void (*f) (void))
 {
     Cxl_func = f;
@@ -43,7 +56,11 @@
     return;
 }
 
+/*!
+  \brief Set swap function
 
+  \param pointer to function
+*/
 void GS_set_swap_func(void (*f) (void))
 {
     Swap_func = f;

Modified: grass/branches/develbranch_6/lib/ogsf/Gp3.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/Gp3.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/Gp3.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -1,7 +1,7 @@
 /*!
   \file Gp3.c
  
-  \brief OGSF library - loading and manipulating point sets
+  \brief OGSF library - loading point sets (lower level functions)
  
   GRASS OpenGL gsurf OGSF Library 
  
@@ -13,18 +13,31 @@
   for details.
   
   \author Bill Brown USACERL, GMSL/University of Illinois (January 1994)
+  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
 */
 
 #include <stdlib.h>
+
 #include <grass/gis.h>
 #include <grass/site.h>
 #include <grass/Vect.h>
-
+#include <grass/glocale.h>
 #include <grass/gstypes.h>
 
-/* used when site attribute mode is ST_ATT_COLOR */
-/* Gets color structure for grass file, goes through points and
-   uses fattr as CAT, putting rgb color in iattr. */
+/*!
+  \brief Set color for point set
+
+  used when site attribute mode is ST_ATT_COLOR
+  
+  Gets color structure for grass file, goes through points and
+  uses fattr as CAT, putting rgb color in iattr.
+
+  \param grassname raster map name
+  \param gp pointer to geopoint struct
+
+  \return 1 on success
+  \return 0 on failure
+*/
 int Gp_set_color(char *grassname, geopoint * gp)
 {
     char *col_map;
@@ -36,16 +49,14 @@
     /* TODO: handle error messages */
 
     if (grassname) {
-	col_map = G_find_file2("cell", grassname, "");
-
-	if (col_map == NULL) {
-	    fprintf(stderr, "Could not find file '%s'", grassname);
-	    return (0);
+	col_map = G_find_cell2(grassname, "");
+	if (!col_map) {
+	    G_warning (_("Raster map <%s> not found"), grassname);
+	    return 0;
 	}
-	else {
-	    G_read_colors(grassname, col_map, &sc);
-	}
 
+	G_read_colors(grassname, col_map, &sc);
+
 	for (tp = gp; tp; tp = tp->next) {
 	    cat = (int) tp->fattr;
 	    color = NULL_COLOR;
@@ -63,9 +74,19 @@
     return (0);
 }
 
-/*##############################################################*/
-/* This loads to memory.  
-The other alternative may be to load to a tmp file. */
+/*!
+  \brief Load to points to memory
+
+  The other alternative may be to load to a tmp file.
+  
+  \param grassname vector point map 
+  \param nsites
+  \param has_z 2D or 3D points?
+  \param has_att attributes included
+ 
+  \return pointer to geopoint struct
+  \return NULL on failure
+*/
 geopoint *Gp_load_sites(char *grassname, int *nsites, int *has_z,
 			int *has_att)
 {
@@ -77,22 +98,30 @@
     struct Cell_head wind;
     RASTER_MAP_TYPE rtype;
     int ndim;
+    char *mapset;
 
-
-    /* TODO: handle error messages */
-
     np = 0;
     eof = 0;
     *has_z = *has_att = 0;
 
+    mapset = G_find_vector2((const char *) grassname, "");
+    if (!mapset) {
+	G_warning (_("Vector map <%s> not found"),
+		   grassname);
+	return NULL;
+    }
+
     Vect_set_open_level (2);
-    Vect_open_old (&map, grassname, "");
+    if (Vect_open_old (&map, grassname, "") == -1) {
+	G_fatal_error (_("Unable to open vector map <%s>"),
+		       grassname);
+    }
 
     Points = Vect_new_line_struct ();
     Cats = Vect_new_cats_struct ();
 
-    if (NULL == (top = gpt = (geopoint *) malloc(sizeof(geopoint)))) {
-	fprintf(stderr, "Can't malloc.\n");
+    top = gpt = (geopoint *) G_malloc(sizeof(geopoint));
+    if (!top) {
 	return (NULL);
     }
 
@@ -112,75 +141,77 @@
 	ltype =  Vect_read_next_line (&map, Points, Cats);
 	switch (ltype)
 	{
-		case -1:
-		{
-			fprintf(stderr, "Can't read vector file");
-			return (NULL);
-		}
-		case -2: /* EOF */
-		{
-			eof = 1;
-			continue;
-		}
+	case -1:
+	{
+	    G_warning(_("Unable to read vector map <%s>"),
+		      grassname);
+	    return (NULL);
 	}
+	case -2: /* EOF */
+	{
+	    eof = 1;
+	    continue;
+	}
+	}
 	if ( (ltype & GV_POINTS))
 	{
-		np++;
-		gpt->p3[X] = Points->x[0]; 
-		gpt->p3[Y] = Points->y[0];
-
-		if (ndim > 2) {
-			*has_z = 1;
+	    np++;
+	    gpt->p3[X] = Points->x[0]; 
+	    gpt->p3[Y] = Points->y[0];
+	    
+	    if (ndim > 2) {
+		*has_z = 1;
 			gpt->dims = 3;
 			gpt->p3[Z] = Points->z[0];
-		} else {
-			gpt->dims = 2;
-			*has_z = 0;
-		}
-
-		if (Cats->n_cats > 0) {
-			*has_att = 1;
-			gpt->fattr = Cats->field[0]; /* Is this correct? */
-			/* gpt->cat = ; ??***/
-			gpt->highlight_color = gpt->highlight_size = gpt->highlight_marker = FALSE;	
-		} else {
-			gpt->fattr = 0;
+	    } else {
+		gpt->dims = 2;
+		*has_z = 0;
+	    }
+	    
+	    if (Cats->n_cats > 0) {
+		*has_att = 1;
+		gpt->fattr = Cats->field[0]; /* Is this correct? */
+		/* gpt->cat = ; ??***/
+		gpt->highlight_color = gpt->highlight_size = gpt->highlight_marker = FALSE;	
+	    } else {
+		gpt->fattr = 0;
 			*has_att = 0;
-		}
-
-		gpt->iattr = gpt->fattr;
-		gpt->cattr = NULL;
-
-		G_debug(3, "loading vector point %d %f %f -- %d", 
-			np, Points->x[0], Points->y[0], Cats->n_cats);
-		if (NULL == 
-			(gpt->next = (geopoint *) malloc(sizeof(geopoint)))) {
-                		fprintf(stderr, "Can't malloc.\n");/*CLEAN UP*/
-                		return (NULL);
-            	}
-
-		prev = gpt;
-		gpt = gpt->next;
+	    }
+	    
+	    gpt->iattr = gpt->fattr;
+	    gpt->cattr = NULL;
+	    
+	    G_debug(3, "loading vector point %d %f %f -- %d", 
+		    np, Points->x[0], Points->y[0], Cats->n_cats);
+	    
+	    gpt->next = (geopoint *) G_malloc(sizeof(geopoint));/* G_fatal_error */
+	    if (!gpt->next) {
+		return (NULL);
+	    }
+	    
+	    prev = gpt;
+	    gpt = gpt->next;
 	}
-
+	
     }
     if (np > 0)
     {
 	prev->next = NULL;
-	free(gpt);
+	G_free(gpt);
     }
-
+    
     Vect_close (&map);
-
+    
     if (!np) {
-	    fprintf(stderr, "Error: No points from %s fall within current region\n", grassname);
-	    return(NULL);
+	G_warning (_("No points from %s fall within current region"),
+		   grassname);
+	return(NULL);
     } else {
-            fprintf(stderr, "Vector file %s loaded with %d points.\n",
-		grassname, np);
+	G_verbose_message(_("Vector file <%s> loaded with %d points"),
+			  grassname, np);
     }
-
+    
     *nsites = np;
-
+    
     return (top);
 }

Modified: grass/branches/develbranch_6/lib/ogsf/Gs3.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/Gs3.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/Gs3.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -1,7 +1,7 @@
 /*!
   \file Gs3.c
  
-  \brief OGSF library - loading and manipulating surfaces
+  \brief OGSF library - loading surfaces (lower level functions)
  
   GRASS OpenGL gsurf OGSF Library 
  
@@ -121,7 +121,8 @@
   \param[out] nullmap null map buffer
   \param[out] has_null indicates if raster map contains null-data
 
-  \return 1
+  \return 1 on success
+  \return 0 on failure
 */
 int Gs_loadmap_as_float(struct Cell_head *wind, char *map_name, float *buff,
 			struct BM *nullmap, int *has_null)
@@ -132,9 +133,11 @@
 
     G_debug(3, "Gs_loadmap_as_float");
 
-    map_set = G_find_file2("cell", map_name, "");
+    map_set = G_find_cell2(map_name, "");
     if (!map_set) {
-	G_fatal_error(_("Raster map <%s> not found"), map_name);
+	G_warning(_("Raster map <%s> not found"),
+		  map_name);
+	return 0;
     }
     *has_null = 0;
 
@@ -191,7 +194,8 @@
   \param[out] nullmap null map buffer
   \param[out] has_null indicates if raster map contains null-data
 
-  \return 1
+  \return 1 on success
+  \return 0 on failure
 */
 int Gs_loadmap_as_int(struct Cell_head *wind, char *map_name, int *buff,
 		      struct BM *nullmap, int *has_null)
@@ -202,9 +206,11 @@
 
     G_debug(3, "Gs_loadmap_as_int");
 
-    map_set = G_find_file2("cell", map_name, "");
+    map_set = G_find_cell2(map_name, "");
     if (!map_set) {
-	G_fatal_error(_("Raster map <%s> not found"), map_name);
+	G_warning(_("Raster map <%s> not found"),
+		  map_name);
+	return 0;
     }
     *has_null = 0;
 
@@ -284,9 +290,11 @@
 	first = 0;
     }
 
-    mapset = G_find_file2("cell", filename, "");
+    mapset = G_find_cell2(filename, "");
     if (!mapset) {
-	G_fatal_error(_("Raster map <%s> not found"), filename);
+	G_warning(_("Raster map <%s> not found"),
+		  filename);
+	return -1;
     }
 
     if (G_raster_map_is_fp(filename, mapset)) {
@@ -355,9 +363,11 @@
 
     max_short -= 1;
 
-    map_set = G_find_file2("cell", map_name, "");
+    map_set = G_find_cell2(map_name, "");
     if (!map_set) {
-	G_fatal_error(_("Raster map <%s> not found"), map_name);
+	G_warning(_("Raster map <%s> not found"),
+		  map_name);
+	return -1;
     }
     *has_null = 0;
 
@@ -467,9 +477,11 @@
 
     max_char -= 1;
 
-    map_set = G_find_file2("cell", map_name, "");
+    map_set = G_find_cell2(map_name, "");
     if (!map_set) {
-	G_fatal_error(_("Raster map <%s> not found"), map_name);
+	G_warning(_("Raster map <%s> not found"),
+		  map_name);
+	return -1;
     }
     *has_null = 0;
 
@@ -560,9 +572,11 @@
 
     G_debug(3, "Gs_loadmap_as_bitmap");
 
-    map_set = G_find_file2("cell", map_name, "");
+    map_set = G_find_cell2(map_name, "");
     if (!map_set) {
-	G_fatal_error(_("Raster map <%s> not found"), map_name);
+	G_warning(_("Raster map <%s> not found"),
+		  map_name);
+	return -1;
     }
 
     if ((cellfile = G_open_cell_old(map_name, map_set)) == -1) {
@@ -612,7 +626,8 @@
   \param filename raster map name
   \param[out] buff data buffer
 
-  \return 1
+  \return 1 on success
+  \return 0 on failure
 */
 int Gs_build_256lookup(char *filename, int *buff)
 {
@@ -624,9 +639,11 @@
 
     G_debug(3, "building color table");
 
-    map = G_find_file2("cell", filename, "");
+    map = G_find_cell2(filename, "");
     if (!map) {
-	G_fatal_error(_("Raster map <%s> not found"), filename);
+	G_warning(_("Raster map <%s> not found"),
+		  filename);
+	return 0;
     }
 
     G_read_colors(filename, map, &colrules);
@@ -679,9 +696,11 @@
     unsigned char *r, *g, *b, *set;
     int *cur, i, j;
 
-    map = G_find_file2("cell", filename, "");
+    map = G_find_cell2(filename, "");
     if (!map) {
-	G_fatal_error(_("Raster map <%s> not found"), filename);
+	G_warning(_("Raster map <%s> not found"),
+		  filename);
+	return;
     }
 
     r = (unsigned char *) G_malloc(cols);
@@ -747,9 +766,11 @@
     int i, j, *icur;
     FCELL *fcur;
 
-    map = G_find_file2("cell", filename, "");
+    map = G_find_cell2(filename, "");
     if (!map) {
-	G_fatal_error(_("Raster map <%s> not found"), filename);
+	G_warning(_("Raster map <%s> not found"),
+		  filename);
+	return;
     }
 
     r = (unsigned char *) G_malloc(cols);
@@ -803,7 +824,8 @@
   \param dcol
   \param catstr category string
 
-  \return 1
+  \return 1 on success
+  \return 0 on failure
 */
 int Gs_get_cat_label(char *filename, int drow, int dcol, char *catstr)
 {
@@ -814,8 +836,10 @@
     RASTER_MAP_TYPE map_type;
     int fd;
 
-    if ((mapset = G_find_cell(filename, "")) == NULL) {
-	G_fatal_error(_("Raster map <%s> not found"), filename);
+    if ((mapset = G_find_cell2(filename, "")) == NULL) {
+	G_warning(_("Raster map <%s> not found"),
+		  filename);
+	return 0;
     }
 
     if (-1 != G_read_cats(filename, mapset, &cats)) {

Modified: grass/branches/develbranch_6/lib/ogsf/Gv3.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/Gv3.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/Gv3.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -1,7 +1,7 @@
 /*!
   \file Gv3.c
  
-  \brief OGSF library - loading and manipulating vector sets
+  \brief OGSF library - loading vector sets (lower level functions)
  
   GRASS OpenGL gsurf OGSF Library 
  
@@ -13,12 +13,13 @@
   for details.
   
   \author Bill Brown USACERL (December 1993)
+  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
 */
 
 #include <stdlib.h>
 #include <grass/gis.h>
 #include <grass/Vect.h>
-
+#include <grass/glocale.h>
 #include <grass/gstypes.h>
 
 #define TRAK_MEM
@@ -27,8 +28,17 @@
 static int Tot_mem = 0;
 #endif
 
-/* This loads to memory.  
-The other alternative may be to load to a tmp file. */
+/*!
+  \brief Load vector map to memory
+
+  The other alternative may be to load to a tmp file
+
+  \param grassname vector map name
+  \param[out] number of loaded features
+
+  \return pointer to geoline struct
+  \return NULL on failure
+*/
 geoline *Gv_load_vect(char *grassname, int *nlines)
 {
     struct Map_info map;
@@ -37,28 +47,39 @@
     int np, i, n, nareas, nl=0, area, type, is3d;
     struct Cell_head  wind;
     float vect[2][3];
+    char *mapset;
 
-    /* TODO: handle error messages */
-
+    mapset = G_find_vector2((const char *) grassname, "");
+    if (!mapset) {
+	G_warning(_("Vector map <%s> not found"),
+		  grassname);
+	return NULL;
+    }
+    
     Vect_set_open_level (2); 
-    Vect_open_old (&map, grassname, "");
+    if (Vect_open_old (&map, grassname, "") == -1) {
+	G_warning (_("Unable to open vector map <%s>"),
+		   grassname);
+	return NULL;
+    }
     
-    if (NULL == (top=gln=(geoline *)malloc(sizeof(geoline)))) {
-	fprintf(stderr,"Can't malloc.\n");
-	return(NULL);
+    top = gln = (geoline *) G_malloc(sizeof(geoline)); /* G_fatal_error */
+    if (!top) {
+	return NULL;
     }
+    
     prev = top;
     
-    #ifdef TRAK_MEM
-    	Tot_mem+=sizeof(geoline);
-    #endif
-
+#ifdef TRAK_MEM
+    Tot_mem+=sizeof(geoline);
+#endif
+    
     points = Vect_new_line_struct ();
-
+    
     G_get_set_window (&wind) ;
     Vect_set_constraint_region(&map,wind.north,wind.south,wind.east,wind.west,
 	                       PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX);
-
+    
     is3d = Vect_is_3d ( &map );
     
     /* Read areas */
@@ -67,33 +88,33 @@
     G_debug(3, "Reading vector areas (nareas = %d)", n);
     for ( area = 1; area <= n ; area++ ) {
 	G_debug(3, " area %d", area);
-
+	
 	Vect_get_area_points ( &map, area, points ); 
 	if ( points->n_points < 3 ) continue;
 	gln->type = OGSF_POLYGON;
 	gln->npts = np = points->n_points;
         G_debug(3, "  np = %d", np);
-		
+	
 	if ( is3d ) { 
 	    gln->dims = 3; 
-	    if (NULL == (gln->p3=(Point3 *)calloc(np, sizeof(Point3)))) {
-		fprintf(stderr,"Can't calloc.\n"); /* CLEAN UP */
+	    gln->p3 = (Point3 *) G_calloc(np, sizeof(Point3)); /* G_fatal_error */
+	    if (!gln->p3) {
 		return(NULL);
 	    }
-	    #ifdef TRAK_MEM
-		Tot_mem+=(np*sizeof(Point3));
-	    #endif
+#ifdef TRAK_MEM
+	    Tot_mem+=(np*sizeof(Point3));
+#endif
 	} else {
 	    gln->dims = 2;
-	    if (NULL == (gln->p2=(Point2 *)calloc(np, sizeof(Point2)))) {
-		fprintf(stderr,"Can't calloc.\n"); /* CLEAN UP */
+	    gln->p2=(Point2 *) G_calloc(np, sizeof(Point2)); /* G_fatal_error */
+	    if (!gln->p2) {
 		return(NULL);
 	    }
-	    #ifdef TRAK_MEM
-		Tot_mem+=(np*sizeof(Point2));
-	    #endif
+#ifdef TRAK_MEM
+	    Tot_mem+=(np*sizeof(Point2));
+#endif
 	}
-    
+	
 	for (i=0; i < np; i++) {
 	    if ( is3d ) {
 		gln->p3[i][X] = points->x[i];
@@ -116,21 +137,21 @@
 	    
 	}
     
-	if (NULL == (gln->next=(geoline *)malloc (sizeof(geoline)))) {
-	    fprintf(stderr,"Can't malloc.\n"); /* CLEAN UP */
+	gln->next = (geoline *) G_malloc (sizeof(geoline)); /* G_fatal_error */
+	if (!gln->next) {
 	    return(NULL);
 	}
 
-	#ifdef TRAK_MEM
-	    Tot_mem+=sizeof(geoline);
-	#endif
-    
+#ifdef TRAK_MEM
+	Tot_mem+=sizeof(geoline);
+#endif
+	
 	prev = gln;
 	gln = gln->next;
 	nareas++;
     }
     G_debug(3, "%d areas loaded", nareas);
-
+    
     /* Read all lines */
     G_debug(3, "Reading vector lines ...");
     while (-1 < (type = Vect_read_next_line(&map, points, NULL))) {
@@ -143,31 +164,30 @@
 		gln->type = OGSF_POLYGON;
                 /* Vect_append_point ( points, points->x[0], points->y[0], points->z[0] ); */
 	    }
-
+	    
 	    gln->npts = np = points->n_points;
             G_debug(3, "  np = %d", np);
-		
+	    
 	    if ( is3d ) { 
 		gln->dims = 3; 
-		if (NULL == (gln->p3=(Point3 *)calloc(np, sizeof(Point3)))) {
-		    fprintf(stderr,"Can't calloc.\n"); /* CLEAN UP */
+		gln->p3=(Point3 *) G_calloc(np, sizeof(Point3)); /* G_fatal_error */
+		if (!gln->p3) {
 		    return(NULL);
 		}
-		#ifdef TRAK_MEM
-		    Tot_mem+=(np*sizeof(Point3));
-		#endif
+#ifdef TRAK_MEM
+		Tot_mem+=(np*sizeof(Point3));
+#endif
 	    } else {
 		gln->dims = 2;
-		if (NULL == (gln->p2=(Point2 *)calloc(np, sizeof(Point2)))) {
-		    fprintf(stderr,"Can't calloc.\n"); /* CLEAN UP */
+		gln->p2 = (Point2 *) G_calloc(np, sizeof(Point2)); /* G_fatal_error */
+		if (!gln->p2) {
 		    return(NULL);
 		}
-		#ifdef TRAK_MEM
-		    Tot_mem+=(np*sizeof(Point2));
-		#endif
+#ifdef TRAK_MEM
+		Tot_mem+=(np*sizeof(Point2));
+#endif
 	    }
-
-	
+	    
 	    for (i=0; i < np; i++) {
 		if ( is3d ) {
 		    gln->p3[i][X] = points->x[i];
@@ -189,16 +209,15 @@
 		GS_v3cross( vect[1], vect[0], gln->norm );
                 G_debug ( 3, "norm %f %f %f", gln->norm[0], gln->norm[1], gln->norm[2] );
 	    }
-	
-	    if (NULL == (gln->next=(geoline *)malloc (sizeof(geoline)))) {
-		fprintf(stderr,"Can't malloc.\n"); /* CLEAN UP */
+	    
+	    gln->next = (geoline *) G_malloc (sizeof(geoline)); /* G_fatal_error */
+	    if (!gln->next) {
 		return(NULL);
 	    }
-
-	    #ifdef TRAK_MEM
-		Tot_mem+=sizeof(geoline);
-	    #endif
-	
+#ifdef TRAK_MEM
+	    Tot_mem+=sizeof(geoline);
+#endif
+	    
 	    prev = gln;
 	    gln = gln->next;
 	    nl++;
@@ -209,59 +228,74 @@
     nl += nareas;
     
     prev->next = NULL;
-    free(gln);
+    G_free(gln);
     
-    #ifdef TRAK_MEM
-    	Tot_mem-=sizeof(geoline);
-    #endif
+#ifdef TRAK_MEM
+    Tot_mem-=sizeof(geoline);
+#endif
     
     Vect_close (&map);
-
-    fprintf(stderr,"Vector file %s loaded.\n",grassname);
+   
     if (!nl) {
-	    fprintf(stderr, "Error: No lines from %s fall within current region\n", grassname);
-	    return (NULL);
+	G_warning (_("No features from vector map <%s> fall within current region"),
+		   grassname);
+	return (NULL);
     }
+    
+    G_verbose_message (_("Vector map <%s> loaded (%d features)"),
+		       grassname, nl);
+    
     *nlines = nl;
-
-    #ifdef TRAK_MEM
-    	fprintf(stderr,"Total vect memory = %d Kbytes\n", Tot_mem/1000);
-    #endif
-
+    
+#ifdef TRAK_MEM
+    G_debug (3, "Total vect memory = %d Kbytes", Tot_mem/1000);
+#endif
+    
     return(top);
 }
 
+/*!
+  \brief Tracking memory
+
+  \param plus plus number
+*/
 void add_Vectmem(int plus)
 {
-    #ifdef TRAK_MEM
+#ifdef TRAK_MEM
     {
     	Tot_mem+=plus;
     }
-    #endif
+#endif
     
     return;
 }
 
+/*!
+  \brief Tracking memory
+
+  \param minus mimus number
+*/
 void sub_Vectmem(int minus)
 {
-    #ifdef TRAK_MEM
+#ifdef TRAK_MEM
     {
     	Tot_mem-=minus;
     }
-    #endif
+#endif
     
     return;
 }
 
+/*!
+  \brief Tracking memory (print)
+*/
 void show_Vectmem(void)
 {
-    #ifdef TRAK_MEM
+#ifdef TRAK_MEM
     {
-    	fprintf(stderr,"Total vect memory = %d Kbytes\n", Tot_mem/1000);
+    	G_message("Total vect memory = %d Kbytes", Tot_mem/1000);
     }
-    #endif
+#endif
     
     return;
 }
-
-

Modified: grass/branches/develbranch_6/lib/ogsf/Gvl3.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/Gvl3.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/Gvl3.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -1,7 +1,7 @@
 /*!
   \file Gvl3.c
  
-  \brief OGSF library - loading and manipulating volumes
+  \brief OGSF library - loading volumes (lower level functions)
  
   GRASS OpenGL gsurf OGSF Library 
  
@@ -13,19 +13,30 @@
   for details.
   
   \author Tomas Paudits (December 2003)
+  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
 */
 
 #include <grass/gis.h>
 #include <grass/G3d.h>
 #include <grass/gstypes.h>
+#include <grass/glocale.h>
 
-/***********************************************************************/
+/*!
+  \brief Load color table
+
+  \param[out] color_data color data buffer
+  \param name 3D raster map name
+
+  \return -1 on failure
+  \return 1 on success
+*/
 int Gvl_load_colors_data(void **color_data, char *name)
 {
     char *mapset;
     struct Colors *colors;
 
     if (NULL == (mapset = G_find_grid3(name,""))) {
+	G_warning(_("3D raster map <%s> not found"), name);
         return (-1);
     }
 
@@ -42,7 +53,14 @@
     return (1);
 }
 
-/***********************************************************************/
+/*!
+  \brief Unload color table
+
+  \param color_data color data buffer
+
+  \return -1 on failure
+  \return 1 on success
+*/
 int Gvl_unload_colors_data(void *color_data)
 {
     if (!G_free_colors(color_data))
@@ -53,7 +71,14 @@
     return (1);
 }
 
-/***********************************************************************/
+/*!
+  \brief Get color for value
+
+  \param color_data color data value
+  \param value data value
+
+  \return color value
+*/
 int Gvl_get_color_for_value(void *color_data, float *value)
 {
     int r, g, b;

Modified: grass/branches/develbranch_6/lib/ogsf/gk.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/gk.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/gk.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -1,7 +1,7 @@
 /*!
   \file gk.c
  
-  \brief OGSF library - setting and manipulating keyframes animation
+  \brief OGSF library - setting and manipulating keyframes animation (lower level functions)
  
   GRASS OpenGL gsurf OGSF Library 
  
@@ -13,6 +13,7 @@
   for details.
   
   \author Bill Brown USACERL, GMSL/University of Illinois
+  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
 */
 
 #include <stdlib.h>
@@ -35,13 +36,20 @@
 	     (double) tension * rderiv * (x3 - x2)));
 }
 
+/*!
+  \brief Copy keyframes
+
+  \param k source keyframes
+
+  \return pointer to Keylist struct (target)
+*/
 Keylist *gk_copy_key(Keylist * k)
 {
     Keylist *newk;
     int i;
 
-    if (NULL == (newk = (Keylist *) malloc(sizeof(Keylist)))) {
-	fprintf(stderr, "Out of memory\n");
+    newk = (Keylist *) G_malloc(sizeof(Keylist)); /* G_fatal_error */
+    if (!newk) {
 	return (NULL);
     }
 
@@ -57,8 +65,18 @@
     return (newk);
 }
 
-/* get begin & end pos, AND all masks in keys <= pos */
-/* time must be between 0.0 & 1.0 */
+/*!
+  \brief Get mask value
+
+  Get begin & end pos, AND all masks in keys <= pos
+
+  Time must be between 0.0 & 1.0
+
+  \param time timestamp
+  \param keys list of keyframes
+
+  \return mask value
+*/
 unsigned long gk_get_mask_sofar(float time, Keylist * keys)
 {
     Keylist *k;
@@ -83,6 +101,15 @@
     return (mask);
 }
 
+/*!
+  \brief ADD
+
+  \param mask mask value
+  \param keys list of keyframes
+  \param[out] keyret output list of keyframes
+
+  \return number of output keyframes
+*/
 int gk_viable_keys_for_mask(unsigned long mask, Keylist * keys,
 			    Keylist ** keyret)
 {
@@ -98,8 +125,20 @@
     return (cnt);
 }
 
-/* checks key masks because if they're masked up until the current position,
-   pre-existing (or current) field should be used. */
+/*!
+  \brief Checks key masks
+
+  Because if they're masked up until the current position,
+  pre-existing (or current) field should be used.
+
+  \param view pointer to Viewmode struct
+  \param numsteps number of steps
+  \param keys list of keyframes
+  \param step step value
+  \param onestep
+  \param render
+  \param mode
+*/
 void gk_follow_frames(Viewnode * view, int numsteps, Keylist * keys, int step,
 		      int onestep, int render, unsigned long mode)
 {
@@ -132,17 +171,15 @@
 
 	GS_moveto(tmp);
 
-#ifdef KDEBUG
-	{
-	    GS_get_from(tmp);
-	    fprintf(stderr, "MASK: %x\n", mask);
-	    fprintf(stderr, "FROM: %f %f %f\n", tmp[X], tmp[Y], tmp[Z]);
-	}
-#endif
-/* ACS 1 line: was 	GS_get_focus(tmp);
- 	with this kanimator works also for flythrough navigation
-	also changed in GK2.c
-*/
+	GS_get_from(tmp);
+	G_debug(3, "gk_follow_frames():");
+	G_debug(3, "  MASK: %x", mask);
+	G_debug(3, "  FROM: %f %f %f", tmp[X], tmp[Y], tmp[Z]);
+
+	/* ACS 1 line: was 	GS_get_focus(tmp);
+	   with this kanimator works also for flythrough navigation
+	   also changed in GK2.c
+	*/
 	GS_get_viewdir(tmp);
 	if ((mask & KF_DIRX_MASK)) {
 	    tmp[X] = v->fields[KF_DIRX];
@@ -153,20 +190,16 @@
 	if ((mask & KF_DIRZ_MASK)) {
 	    tmp[Z] = v->fields[KF_DIRZ];
 	}
-/* ACS 1 line: was 	GS_set_focus(tmp);
- 	with this kanimator works also for flythrough navigation
-	also changed in GK2.c
-*/
+	/* ACS 1 line: was 	GS_set_focus(tmp);
+	   with this kanimator works also for flythrough navigation
+	   also changed in GK2.c
+	*/
 	GS_set_viewdir(tmp);
 
+	G_debug(3, "gk_follow_frames():");
+	GS_get_viewdir(tmp);
+	G_debug(3, "  DIR: %f %f %f\n", tmp[X], tmp[Y], tmp[Z]);
 
-#ifdef KDEBUG
-	{
-	    GS_get_viewdir(tmp);
-	    fprintf(stderr, "DIR: %f %f %f\n", tmp[X], tmp[Y], tmp[Z]);
-	}
-#endif
-
 	if ((mask & KF_TWIST_MASK)) {
 	    GS_set_twist((int) v->fields[KF_TWIST]);
 	}
@@ -231,6 +264,11 @@
     return;
 }
 
+/*!
+  \brief Free keyframe list
+
+  \param ok pointer to Keylist struct
+*/
 void gk_free_key(Keylist * ok)
 {
     Keylist *k, *prev;
@@ -240,14 +278,27 @@
 	while (k) {
 	    prev = k;
 	    k = k->next;
-	    free(prev);
+	    G_free(prev);
 	}
     }
 
     return;
 }
 
-/* here we use a cardinal cubic spline */
+/*!
+  \brief Generate viewnode from keyframes
+  
+  Here we use a cardinal cubic spline
+
+  \param keys list of keyframes
+  \param keysteps keyframe step
+  \param newsteps new step value
+  \param loop loop indicator
+  \param t
+
+  \return pointer to Viewnode
+  \return NULL on failure
+*/
 Viewnode *gk_make_framesfromkeys(Keylist * keys, int keysteps, int newsteps,
 				 int loop, float t)
 {
@@ -258,8 +309,8 @@
     double dt1, dt2, x, x2, x3, range, time, time_step, len, rderiv, lderiv;
 
     /* allocate tmp keys to hold valid keys for fields */
-    if (NULL == (tkeys = (Keylist **) malloc(keysteps * sizeof(Keylist *)))) {
-	fprintf(stderr, "Unable to allocate memory\n");
+    tkeys = (Keylist **) G_malloc(keysteps * sizeof(Keylist *)); /* G_fatal_error */
+    if (!tkeys) {
 	return (NULL);
     }
 
@@ -267,8 +318,8 @@
 
     if (keys && keysteps) {
 	if (keysteps < 3) {
-	    fprintf(stderr, "Need at least 3 keyframes for spline\n");
-	    free(tkeys);
+	    G_warning (_("Need at least 3 keyframes for spline"));
+	    G_free(tkeys);
 	    return (NULL);
 	}
 
@@ -280,10 +331,9 @@
 	range = endpos - startpos;
 	time_step = range / (newsteps - 1);
 
-	if (NULL ==
-	    (newview = (Viewnode *) malloc(newsteps * sizeof(Viewnode)))) {
-	    fprintf(stderr, "Out of memory\n");
-	    free(tkeys);
+	newview = (Viewnode *) G_malloc(newsteps * sizeof(Viewnode)); /* G_fatal_error */
+	if(!newview) { /* not used */
+	    G_free(tkeys);
 	    return (NULL);
 	}
 
@@ -310,9 +360,9 @@
 					    loop, tkeys, &k, &kp1, &kp2, &km1,
 					    &dt1, &dt2);
 		}
-
+		
 /* ACS 1 line: was	if (len == 0.0) {
- 	when disabling a channel no calculation must be made at all (otherwise core dump)
+   when disabling a channel no calculation must be made at all (otherwise core dump)
 */
 		if (len == 0.0 || nvk == 0) {
 		    if (!k) {
@@ -368,23 +418,40 @@
 	    }
 	}
 
-	free(tkeys);
+	G_free(tkeys);
 	return (newview);
     }
     else {
-	free(tkeys);
+	G_free(tkeys);
 	return (NULL);
     }
 }
 
-/* finds interval containing time, putting left (or equal) key
-   at km1, right at kp1, 2nd to right at kp2, and second to left at km2.
-   dt1 is given the length of the current + left intervals
-   dt2 is given the length of the current + right intervals
-   returns the length of the current interval (0 on error)
+/*!
+  \brief Find interval containing time
+  
+  Changed June 94 to handle masks - now need to have called get_viable_keys
+  for appropriate mask first to build the ARRAY of viable keyframes.
+  
+  Putting left (or equal) key
+  at km1, right at kp1, 2nd to right at kp2, and second to left at km2.
+  dt1 is given the length of the current + left intervals
+  dt2 is given the length of the current + right intervals
+  
+  \param nvk
+  \param time
+  \param range
+  \param loop
+  \param karray
+  \param km1
+  \param kp1
+  \param kp2
+  \param km2
+  \param dt1
+  \param dt2
 
-   Changed June 94 to handle masks - now need to have called get_viable_keys
-   for appropriate mask first to build the ARRAY of viable keyframes.
+  \return the length of the current interval
+  \return 0 on error
 */
 double get_key_neighbors(int nvk, double time, double range, int loop,
 			 Keylist * karray[], Keylist ** km1, Keylist ** kp1,
@@ -461,13 +528,33 @@
     return (len);
 }
 
+/*!
+  \brief Linear interpolation
+  
+  \param dt coeficient
+  \param val2 value 2
+  \param val1 value 1
+
+  \return val1 + dt * (val2 - val1)
+*/
 double lin_interp(float dt, float val1, float val2)
 {
     return ((double) (val1 + dt * (val2 - val1)));
 }
 
-/* finds interval containing time, putting left (or equal) key
-   at km1, right at kp1
+/*!
+  \brief Finds interval containing time, putting left (or equal) key
+  at km1, right at kp1
+
+  \param nvk
+  \param time
+  \param range
+  \param loop
+  \param karray
+  \param km1
+  \param km2
+
+  \return interval value
 */
 double get_2key_neighbors(int nvk, float time, float range, int loop,
 			  Keylist * karray[], Keylist ** km1, Keylist ** kp1)
@@ -501,8 +588,20 @@
     return (len);
 }
 
-/* Here we use linear interpolation. Loop variable isn't used, but left  */
-/* in for use in possible "linear interp with smoothing" version.        */
+/*!
+  \brief Generate viewnode from keyframe list (linear interpolation)
+
+  Here we use linear interpolation. Loop variable isn't used, but left
+  in for use in possible "linear interp with smoothing" version.
+
+  \param kesy keyframe list
+  \param keysteps step value
+  \param newsteps new step value
+  \param loop loop indicator
+
+  \param pointer to viewnode struct
+  \param NULL on failure
+*/
 Viewnode *gk_make_linear_framesfromkeys(Keylist * keys, int keysteps,
 					int newsteps, int loop)
 {
@@ -512,8 +611,8 @@
     float startpos, endpos, dt, range, time, time_step, len;
 
     /* allocate tmp keys to hold valid keys for fields */
-    if (NULL == (tkeys = (Keylist **) malloc(keysteps * sizeof(Keylist *)))) {
-	fprintf(stderr, "Unable to allocate memory\n");
+    tkeys = (Keylist **) G_malloc(keysteps * sizeof(Keylist *)); /* G_fatal_error */
+    if(!tkeys) {
 	return (NULL);
     }
 
@@ -521,8 +620,8 @@
 
     if (keys && keysteps) {
 	if (keysteps < 2) {
-	    fprintf(stderr, "Need at least 2 keyframes for interpolation\n");
-	    free(tkeys);
+	    G_warning (_("Need at least 2 keyframes for interpolation"));
+	    G_free(tkeys);
 	    return (NULL);
 	}
 
@@ -534,10 +633,9 @@
 	range = endpos - startpos;
 	time_step = range / (newsteps - 1);
 
-	if (NULL ==
-	    (newview = (Viewnode *) malloc(newsteps * sizeof(Viewnode)))) {
-	    fprintf(stderr, "Out of memory\n");
-	    free(tkeys);
+	newview = (Viewnode *) G_malloc(newsteps * sizeof(Viewnode)); /* G_fatal_error */
+	if(!newview) { /* not used */
+	    G_free(tkeys);
 	    return (NULL);
 	}
 
@@ -564,7 +662,7 @@
 		}
 
 /* ACS 1 line: was	if (len == 0.0) {
- 	when disabling a channel no calculation must be made at all (otherwise core dump)
+   when disabling a channel no calculation must be made at all (otherwise core dump)
 */
 		if (len == 0.0 || nvk == 0) {
 		    if (!k1) {
@@ -583,19 +681,23 @@
 						  k1->fields[field],
 						  k2->fields[field]);
 		}
-
 	    }
 	}
 
-	free(tkeys);
+	G_free(tkeys);
 	return (newview);
     }
     else {
-	free(tkeys);
+	G_free(tkeys);
 	return (NULL);
     }
 }
 
+/*!
+  \brief Correct twist value
+
+  \param k keyframe list
+*/
 void correct_twist(Keylist * k)
 {
     Keylist *c, *p, *t;
@@ -624,6 +726,16 @@
     return;
 }
 
+/*!
+  \brief Draw path
+
+  \param views Viewnode struct
+  \param steps step value
+  \param keys keyframe list
+
+  \return 0 on failure
+  \return 1 on success
+*/
 int gk_draw_path(Viewnode * views, int steps, Keylist * keys)
 {
     Viewnode *v;

Modified: grass/branches/develbranch_6/lib/ogsf/gsd_legend.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/gsd_legend.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/gsd_legend.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -201,9 +201,10 @@
     if (flags[2])
 	do_invert = 1;
 
-    mapset = G_find_cell(name, "");
+    mapset = G_find_cell2(name, "");
     if (mapset == NULL) {
-	fprintf(stderr, "Unable to locate raster %s\n", name);
+	G_warning (_("Raster map <%s> not found"),
+		   name);
 	return (-1);
     }
 

Modified: grass/branches/develbranch_6/lib/ogsf/gvl_file.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/gvl_file.c	2008-05-12 12:36:51 UTC (rev 31321)
+++ grass/branches/develbranch_6/lib/ogsf/gvl_file.c	2008-05-12 15:52:14 UTC (rev 31322)
@@ -20,6 +20,7 @@
 #include <grass/gstypes.h>
 #include <grass/gsurf.h>
 #include <grass/G3d.h>
+#include <grass/glocale.h>
 
 #define LUCKY                 33
 
@@ -335,9 +336,8 @@
 
     /* search for g3d file a return his mapset */
     if (NULL == (mapset = G_find_grid3(filename,""))) {
-#ifdef DEBUG_MSG
-        fprintf(stderr, "can't find grid3 file : %s\n", filename);
-#endif
+	G_warning (_("3D raster map <%s> not found"),
+		   filename);
         return (NULL);
     }
 



More information about the grass-commit mailing list