too many open raster files

Martin Ameskamp ma at
Fri Dec 20 12:18:34 EST 1996

> Any grass programmers still left out there?


> I get "WARNING: too many open raster files" after about
> 20 iterations of a dynamic simulation model that uses
> r.mapcalc and other GRASS programs, as well as some
> contributed code.  If I omit the following subroutine in
> our contributed code, then the program does not produce this
> error, so this is the offending code, although other things
> going on elsewhere could be contributing other open
> raster files (?):

	There are two aspects to this problem (I think). The first is
	the origin of the warning. This warning is produced in
	file src/libes/gis/opencell.c if you try to open more than
	MAXFILES files. MAXFILES is a constant that is #defined to be
	30 in src/libes/gis/G.h

	I don't know why it's 30, probably the programmers thought that
	nobody in their right mind would need more than 30 open files
	anyawy (sounds vaguely familiar...).
	So I guess you could change this constant and recompile GRASS
	(you'd probably need to recompile or at least relink just about
	all of GRASS since this is a fairly central point).

	The second aspect is that your use of more than 30 open files
	_may_ point to a resource leakage. On the other hand, a complex
	mapcalc calculation could easily lead to a large number
	of temporary files (I don't know what mapcalc does in main-memory
	and where it uses temp files; a look at the code might help there).

	If your program is a complex one that opens and closes raster files
	all over the place, a debugger might help. Set breakpoints in
	the relevant routines (G_open_cell etc., recompile them with
	debugging information if necessary) and check if close
	is called often enough etc.

	Finally, I only use G_gisinit at the beginning of my GRASS programs
	(mostly in main()). Calling it in a subroutine makes sense if that
	routine is the only one that uses GRASS code, but calling it
	more than once might have funny effects on some bookkeeping
	details, maybe including file descriptors.

	Good luck,  Martin
> void probascii();
>   {
>     int fd;
>     char *mapset;
>     static char prog_name[] = "probascii";
>     static char filename[] = "DISTPROB";
>     G_gisinit(prog_name);
>     if((mapset = G_find_cell(filename,"")) == NULL) {
>       printf("Unable to find file %s.\n",filename);
>       exit(1);
>     }
>     if((fd = G_open_cell_old(filename, mapset)) < 0) {
>       printf("Unable to open file %s.\n",filename);
>       exit(-1);
>     }
>     G_close_cell(fd);
>   }
> I didn't write this code, but I'm trying to debug it.
> Anyone see why this fails to close the raster files?
> Or, any other clues as to what else could be
> producing this WARNING?
> Bill Baker

Martin Ameskamp, Inst. f. Informatik I (Computing Dept.)
Kiel University, Olshausenstr. 40, 24118 Kiel, Germany
Fax: ++49 431 8804054, Voice: ++49 431 8804474, 
ma at, URL

More information about the grass-user mailing list