[GRASSLIST:1599] G_write_colors()

Hello users,
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);
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); // this generates segmentation fault!!!
G_free_colors(colr);

What i’m doing wrong?
I can directly write an ascii file in my color folder nameing it with my raster file name,
but isn’t it a wrong solution?
Any suggestions?
Thanks


note: change my e-mail reference to massimiliano.cannata@supsi.ch
because the old one will be deleted soon.

Ing. Massimiliano Cannata
Istituto di Scienze della Terra - SUPSI
C.P. 72 - CH-6952 Canobbio (Ticino, Switzerland)
Tel +41 91 /935 12 25 - Fax +41 91 /935 12 09
eMail: massimiliano.cannata@supsi.ch
Internet: http://www.ist.supsi.ch

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@virgin.net>

Thanks a lot,
Now everythings works!
I had done in that way becouse i thougth i had segmantation falult caused by struct Colors *colr while the problem was a pointer conflict with a char *.
I had a question about programming in GRASS:

how can be done a debug of GRASS command in linux environment like is done for generic C programs?
I try Anjuta but I can only compile the command and cannot build it… and so cannot debug…

Thanks for your precious support.
Massimiliano

Glynn Clements wrote:

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@virgin.net

Massimiliano Cannata wrote:

I had done in that way becouse i thougth i had segmantation falult caused by
struct Colors *colr while the problem was a pointer conflict with a char *.
I had a question about programming in GRASS:

how can be done a debug of GRASS command in linux environment like
is done for generic C programs?

GRASS programs can be debugged with gdb like any other program.
However, you need to run the program in etc/bin/cmd or etc/bin/inter,
not the one in bin (most of the entries in that directory are actually
links to etc/front.end; that program just runs the corresponding
program from either etc/bin/cmd or etc/bin/inter).

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

On Thu, Oct 30, 2003 at 10:57:50AM +0000, Glynn Clements wrote:

Massimiliano Cannata wrote:

> I had done in that way becouse i thougth i had segmantation falult caused by
> struct Colors *colr while the problem was a pointer conflict with a char *.
> I had a question about programming in GRASS:
>
> how can be done a debug of GRASS command in linux environment like
> is done for generic C programs?

GRASS programs can be debugged with gdb like any other program.
However, you need to run the program in etc/bin/cmd or etc/bin/inter,
not the one in bin (most of the entries in that directory are actually
links to etc/front.end; that program just runs the corresponding
program from either etc/bin/cmd or etc/bin/inter).

Debugging: hints are collected in documents/debugging.txt in the source
code. See also here:
http://grass.itc.it/grassdevel.html#compile

Markus Neteler