[GRASS-SVN] r43862 - in grass/branches/develbranch_6: include
lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 11 12:13:33 EDT 2010
Author: martinl
Date: 2010-10-11 09:13:32 -0700 (Mon, 11 Oct 2010)
New Revision: 43862
Added:
grass/branches/develbranch_6/lib/gis/color_print.c
Modified:
grass/branches/develbranch_6/include/gisdefs.h
Log:
G_print_colors() added (used by r.colors -p)
Modified: grass/branches/develbranch_6/include/gisdefs.h
===================================================================
--- grass/branches/develbranch_6/include/gisdefs.h 2010-10-11 13:21:53 UTC (rev 43861)
+++ grass/branches/develbranch_6/include/gisdefs.h 2010-10-11 16:13:32 UTC (rev 43862)
@@ -304,6 +304,9 @@
/* color_org.c */
int G__organize_colors(struct Colors *);
+/* color_print.c */
+int G_print_colors(const char *, const char *, FILE *);
+
/* color_rand.c */
int G_make_random_colors(struct Colors *, CELL, CELL);
Added: grass/branches/develbranch_6/lib/gis/color_print.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/color_print.c (rev 0)
+++ grass/branches/develbranch_6/lib/gis/color_print.c 2010-10-11 16:13:32 UTC (rev 43862)
@@ -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 G_print_colors(const char *name, const char *mapset, FILE *file)
+{
+ char element[512];
+ char xname[GNAME_MAX];
+
+ strcpy(xname, name);
+ mapset = G_find_cell(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/branches/develbranch_6/lib/gis/color_print.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list