[GRASSLIST:2395] Re: code example plotRasterMap from progmangrass50

Glynn Clements glynn.clements at virgin.net
Thu Jan 29 12:37:37 EST 2004


Daniel Isenegger wrote:

> I try to get started with Grass programming with the code example on 
> p.264 from the progmangrass50.

I don't know how much has changed since the version which I'm looking
at, but the code in my version needed quite a few changes just to
compile.

> After getting help concerning the 
> Gmakefile i got stuck now:
> when executing the executable, it stops with (i guess it hangs)
> B
> 
> (after some typing some returns)
> 
> =full_screen
> full_screen : unknown error
> Bfull_screen
> ERROR: Current graphics frame not available
> 
> 
> I tried to debug the error, but i get deeper and deeper into the source 
> code:
> framestack (with backtrace in gdb). somewhere in D_get_cur_wind it stops.
> 
> #0  D_get_cur_wind (name=0xbfffed70 "\200ý\034@") at window.c:153
> #1  0x0804ac76 in D_setup (clear=1) at setup.c:32
> #2  0x080498db in plot_raster_map (name=0x8062bf4 "elevation.dem",
>     mapset=0x8062bea "PERMANENT", overlay=0) at plotRasterMap.c:12
> #3  0x080498ae in main (argc=1, argv=0x1) at ctest.c:18
> #4  0x400b58ae in __libc_start_main () from /lib/libc.so.6

AFAICT, this is because you haven't called R_open_driver().

One other problem with my version of the code is that the line:

	if (D_cell_draw_setup(&top, &bottom, &left, &right))

should be:

	if (D_cell_draw_setup(top, bottom, left, right))

I've attached a modified version which actually runs.

> - I work with Grass 5.0.3 (compiled from source). Since I'm not root, 
> i've installed grass on custom paths.
> - I use tcsh. I've experimented to start Grass from bash, but this 
> didn't help
> - I've read smth about writing a graphics driver (p. 407 in 
> progmangrass50), i tried to look a the mentioned files, e.g 
> Gisbase/src.D/devices or GENERIC, but in my installation there not 
> there. ???

The driver code is in src/display/devices. Common code is in the lib
subdirectory; the driver-specific code is in the CELL, PNGdriver and
XDRIVER directories.

-- 
Glynn Clements <glynn.clements at virgin.net>

-------------- next part --------------
#include <stdlib.h>

#include "gis.h"
#include "raster.h"
#include "display.h"

void plot_raster_map(char *name, char *mapset, int overlay)
{
	struct Colors colors;
	CELL *raster;
	int row, fd, top, bottom, left, right;

	/* perform plotting setup */
	D_setup(0);
	D_get_screen_window(&top, &bottom, &left, &right);

	if (D_cell_draw_setup(top, bottom, left, right))
		G_fatal_error("D_cell_draw_setup");

	raster = G_allocate_cell_buf();

	/* open raster map, read and set the colors */
	if((fd = G_open_cell_old(name, mapset)) < 0)
		G_fatal_error("G_open_cell_old");
	if (G_read_colors(name, mapset, &colors) < 0)
		G_fatal_error("G_read_colors");
	D_set_colors(&colors);

	/* plot */
	D_set_overlay_mode(overlay);
	for (row=0; row >= 0; )
	{
		if (G_get_map_row(fd, raster, row) < 0)
			G_fatal_error("G_get_map_row");
		row = D_draw_cell(row, raster, &colors);
	}
	G_close_cell(fd);
	G_free_colors(&colors);
	G_free(raster);
}

int main(int argc, char **argv)
{
	char name[] = "elevation.dem";
	char *mapset;

	G_gisinit(argv[0]);

	mapset = G_find_cell2(name, "");

	if (R_open_driver() != 0)
		G_fatal_error("R_open_driver");

	plot_raster_map(name, mapset, 0);

	R_close_driver();

	return 0;
}



More information about the grass-user mailing list