[GRASS-dev] opening and closing rasters: hangup error on close
raster.
Duffy, Garret
gduffy at nrcan.gc.ca
Fri Nov 30 08:54:06 EST 2007
Hi,
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.
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.
Thanks,
Garret Duffy
______________________________________
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);
if (cf_bathy < 0)
{
char msg[100];
sprintf (msg, "unable to create raster map %s", fname);
G_fatal_error (msg);
exit (1);
}
cell_bathy = (FCELL *) G_allocate_f_raster_buf ();
/*open EXISTING crests raster */
strcpy (fname, crests_raster);
cf_crests = G_open_cell_old (fname, mapset);
if (cf_crests < 0)
{
char msg[100];
sprintf (msg, "unable to create raster map %s", fname);
G_fatal_error (msg);
exit (1);
}
cell_crests = (FCELL *) G_allocate_f_raster_buf ();
/*open EXISTING slope raster */
strcpy (fname, slope_raster);
cf_slope = G_open_cell_old (fname, mapset);
if (cf_slope < 0)
{
char msg[100];
sprintf (msg, "unable to create raster map %s", fname);
G_fatal_error (msg);
exit (1);
}
cell_slope = (FCELL *) G_allocate_f_raster_buf ();
/*open NEW troughs raster*/
strcpy (fname, output_troughs_raster);
cf_troughs = G_open_fp_cell_new (fname);
if (cf_troughs < 0)
{
char msg[100];
printf (msg, "unable to create raster map %s", fname);
G_fatal_error (msg);
exit (1);
}
cell_troughs = (FCELL *) G_allocate_f_raster_buf ();
/*open NEW height raster*/
strcpy (fname, output_height_raster);
cf_height = G_open_fp_cell_new (fname);
if (cf_height < 0)
{
char msg[100];
printf (msg, "unable to create raster map %s", fname);
G_fatal_error (msg);
exit (1);
}
cell_height = (FCELL *) G_allocate_f_raster_buf ();
/*open NEW spacing raster*/
strcpy (fname, output_spacing_raster);
cf_spacing = G_open_fp_cell_new (fname);
if (cf_spacing < 0)
{
char msg[100];
printf (msg, "unable to create raster map %s", fname);
G_fatal_error (msg);
exit (1);
}
cell_spacing = (FCELL *) G_allocate_f_raster_buf ();
}
___________________________
I close them like this:
printf ("Closing bathy raster... ");
G_close_cell (cf_bathy);
printf ("done!\n");
printf ("Closing crests raster... ");
G_close_cell (cf_crests);
printf ("done!\n");
printf ("Closing troughs raster... ");
G_close_cell (cf_troughs);
printf ("done!\n");
printf ("Closing slope raster... ");
G_close_cell (cf_slope);
printf ("done!\n");
printf ("Closing spacing raster... ");
G_close_cell (cf_spacing);
printf ("done!\n");
printf ("Closing height raster... ");
G_close_cell (cf_height);
printf ("done!\n");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20071130/9252dea5/attachment.html
More information about the grass-dev
mailing list