[GRASS-dev] opening and closing rasters: hangup error on close raster.

Glynn Clements glynn at gclements.plus.com
Fri Nov 30 11:57:24 EST 2007


Duffy, Garret wrote:

> I'm having major problems with some C code I'm writing within the GRASS
> environment.  Basically, my code opens 6 rasters, 3 of which exist
> already the other 3 are new.  When I look at the code with ddd
> everything seems fine, i.e. the arrays for the new rasters are created
> as required but when it comes to closing the rasters, the
> previously-existing rasters close fine but I get 'hangup' error when I
> try to close the first newly-created raster, the code crashes and I lose
> the new rasters.

"Hangup" normally refers to closing the terminal. It's possible that
one of the variables which holds a descriptor has the wrong value, and
closing it closes the terminal.

> Following is the mechanisms I use to open and close the files.  I would
> like some expert advice on whether anything looks strange just so I can
> debug elsewhere in the code.
> 
> I would really appreciate any suggestions since I've wasted so much time
> trying to fix this.

> I open the rasters like so:
> 
> void
> Open_GRASS_files ()
> {
> 
>   char fname[1024];
>   if (G_set_window (&working_area) < 0)
>     exit (3);
>   mapset = G_mapset ();
> 
>   /*open EXISTING bathy raster */
>   strcpy (fname, bathy_raster);
>   cf_bathy = G_open_cell_old (fname, mapset);

Input map names need to be resolved with G_find_cell() or
G_find_cell2(), e.g.:

	mapset = G_find_cell2(fname, "");
	cf_bathy = G_open_cell_old(fname, mapset);

This accounts for the fact that the map name may be fully qualified,
i.e. map at mapset.

>   if (cf_bathy < 0)
> 
>     {
>       char msg[100];
>       sprintf (msg, "unable to create raster map %s", fname);
>       G_fatal_error (msg);
>       exit (1);
>     }

G_fatal_error() accepts a printf()-style format string and arguments,
so there's no need to use sprintf(); you can just use e.g.:

	G_fatal_error ("unable to create raster map %s", fname);

> ___________________________
> I close them like this:
> 
>   printf ("Closing bathy raster... ");
>   G_close_cell (cf_bathy);
>   printf ("done!\n");

Apart from the issues noted above (which wouldn't cause the problems
you describe), I don't see anything wrong with your code.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list