[GRASS-SVN] r43864 - in grass/trunk: include lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 11 12:26:45 EDT 2010


Author: martinl
Date: 2010-10-11 09:26:45 -0700 (Mon, 11 Oct 2010)
New Revision: 43864

Added:
   grass/trunk/lib/raster/color_print.c
Modified:
   grass/trunk/include/rasterdefs.h
Log:
G_print_colors() added (used by r.colors -p)
(merge from devbr6)


Modified: grass/trunk/include/rasterdefs.h
===================================================================
--- grass/trunk/include/rasterdefs.h	2010-10-11 16:14:27 UTC (rev 43863)
+++ grass/trunk/include/rasterdefs.h	2010-10-11 16:26:45 UTC (rev 43864)
@@ -174,6 +174,9 @@
 /* color_org.c */
 void Rast__organize_colors(struct Colors *);
 
+/* color_print.c */
+int Rast_print_colors(const char *, const char *, FILE *);
+
 /* color_rand.c */
 void Rast_make_random_colors(struct Colors *, CELL, CELL);
 

Added: grass/trunk/lib/raster/color_print.c
===================================================================
--- grass/trunk/lib/raster/color_print.c	                        (rev 0)
+++ grass/trunk/lib/raster/color_print.c	2010-10-11 16:26:45 UTC (rev 43864)
@@ -0,0 +1,69 @@
+/*!
+ * \file lib/gis/color_print.c
+ *
+ * \brief GIS Library - Print color table of raster map
+ *
+ * (C) 2010 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 Martin Landa <landa.martin gmail.com>
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grass/gis.h>
+
+static int print_color_table(const char *, const char *, const char *, FILE *);
+
+/*!
+  \brief Print current color table of raster map to file
+
+  \param name name of raster map
+  \param mapset mapset of raster map
+  \param file file where to print color table
+
+  \return -1 on error (raster map not found)
+  \return -2 on error (reading color table failed)
+  \return 0 on success
+*/
+int Rast_print_colors(const char *name, const char *mapset, FILE *file)
+{
+    char element[512];
+    char xname[GNAME_MAX];
+        
+    strcpy(xname, name);
+    mapset = G_find_raster(xname, mapset);
+    if (!mapset)
+	return -1;
+    name = xname;
+    
+    /* first look for secondary color table in current mapset */
+    sprintf(element, "colr2/%s", mapset);
+    if (print_color_table(element, name, mapset, file) < 0)
+	if (print_color_table("colr", name, mapset, file) < 0)
+	    return -2;
+    
+    return 0;
+}
+
+int print_color_table(const char *element, const char *name,
+		      const char *mapset, FILE *file)
+{
+    FILE *fd;
+    char buf[4096];
+    
+    fd = G_fopen_old(element, name, mapset);
+    if (!fd)
+	return -1;
+    
+    while(fgets(buf, sizeof(buf), fd)) {
+	fwrite(buf, strlen(buf), 1, file);
+    }
+    
+    fclose(fd);
+    
+    return 0;
+}


Property changes on: grass/trunk/lib/raster/color_print.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native



More information about the grass-commit mailing list