[GRASSLIST:1604] Re: G_write_colors()

Glynn Clements glynn.clements at virgin.net
Wed Oct 29 22:51:55 EST 2003


Massimiliano Cannata wrote:

> I have a problem setting the color in a raster
> map,
> in my C file i call:
> 
> .......
> ......
> char *name,*result, *mapset;
> struct Colors *colr;
> 
> name = input->answer;
> result = output->answer;
> mapset = G_find_cell2(name,"");
> 
> G_init_colors(colr);

"colr" is pointing at a random memory location. Change your code to:

	struct Colors colr;
	...
	G_init_colors(&colr);
	G_add_color_rule((CELL)-50, 0,0,255, (CELL)0, 255,255,255, &colr);
	G_add_color_rule((CELL)0, 255,255,255, (CELL)50, 255,0,0, &colr);
	G_write_colors(result,mapset,&colr);
	G_free_colors(&colr);

This applies in most situations where a function accepts a pointer as
an argument; not just in GRASS, but in C generally.

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




More information about the grass-user mailing list