<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>opening and closing rasters: hangup error on close raster.</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Hi,</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">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.</FONT></SPAN></P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">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.</FONT></SPAN></P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">I would really appreciate any suggestions since I've wasted so much time trying to fix this.</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Thanks,</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Garret Duffy</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">______________________________________</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">I open the rasters like so:</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">void</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">Open_GRASS_files ()</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">{</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char fname[1024];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (G_set_window (&working_area) < 0)</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (3);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> mapset = G_mapset ();</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> /*open EXISTING bathy raster */</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> strcpy (fname, bathy_raster);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cf_bathy = G_open_cell_old (fname, mapset);</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (cf_bathy < 0)</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> {</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char msg[100];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> sprintf (msg, "unable to create raster map %s", fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_fatal_error (msg);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (1);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> }</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cell_bathy = (FCELL *) G_allocate_f_raster_buf ();</FONT></SPAN>
</P>
<BR>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> /*open EXISTING crests raster */</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> strcpy (fname, crests_raster);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cf_crests = G_open_cell_old (fname, mapset);</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (cf_crests < 0)</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> {</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char msg[100];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> sprintf (msg, "unable to create raster map %s", fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_fatal_error (msg);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (1);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> }</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cell_crests = (FCELL *) G_allocate_f_raster_buf ();</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> /*open EXISTING slope raster */</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> strcpy (fname, slope_raster);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cf_slope = G_open_cell_old (fname, mapset);</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (cf_slope < 0)</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> {</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char msg[100];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> sprintf (msg, "unable to create raster map %s", fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_fatal_error (msg);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (1);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> }</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cell_slope = (FCELL *) G_allocate_f_raster_buf ();</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">/*open NEW troughs raster*/</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> strcpy (fname, output_troughs_raster);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cf_troughs = G_open_fp_cell_new (fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (cf_troughs < 0)</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> {</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char msg[100];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf (msg, "unable to create raster map %s", fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_fatal_error (msg);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (1);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> }</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cell_troughs = (FCELL *) G_allocate_f_raster_buf ();</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">/*open NEW height raster*/</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> strcpy (fname, output_height_raster);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cf_height = G_open_fp_cell_new (fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (cf_height < 0)</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> {</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char msg[100];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf (msg, "unable to create raster map %s", fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_fatal_error (msg);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (1);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> }</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cell_height = (FCELL *) G_allocate_f_raster_buf ();</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">/*open NEW spacing raster*/</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> strcpy (fname, output_spacing_raster);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cf_spacing = G_open_fp_cell_new (fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> if (cf_spacing < 0)</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> {</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> char msg[100];</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf (msg, "unable to create raster map %s", fname);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_fatal_error (msg);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> exit (1);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> }</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> cell_spacing = (FCELL *) G_allocate_f_raster_buf ();</FONT></SPAN>
</P>
<BR>
<BR>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">}</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">___________________________</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial">I close them like this:</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("Closing bathy raster... ");</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_close_cell (cf_bathy);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("done!\n");</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("Closing crests raster... ");</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_close_cell (cf_crests);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("done!\n");</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("Closing troughs raster... ");</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_close_cell (cf_troughs);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("done!\n");</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("Closing slope raster... ");</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_close_cell (cf_slope);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("done!\n");</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("Closing spacing raster... ");</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_close_cell (cf_spacing);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("done!\n");</FONT></SPAN>
</P>
<P><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("Closing height raster... ");</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> G_close_cell (cf_height);</FONT></SPAN>
<BR><SPAN LANG="en-ca"><FONT SIZE=2 FACE="Arial"> printf ("done!\n");</FONT></SPAN><SPAN LANG="en-us"></SPAN>
</P>
</BODY>
</HTML>