Too many raster files open

Fellow grass users,

I am very new to GRASS programming and I apologize if this is a FAQ. I'm
writing my very first program. It is a C program that uses system() to
repeatedly call r.reclass to set a new mask, then call r.stats to determine the
dominant soil series, and then call r.cats to determine the soil series name.
The program works fine for about 30 iterations, but then gives me an error
message something like "Too many raster files open". My questions are:

1) Why do raster files stay open when used by the r.reclass, r.stats, and r.cats
modules?

2) How can I close them after I use them?

Please reply directly, since I am not yet a subscriber to the programmer's list.

Thanks.

Michael Hanratty Phone: (612) 627-4590
St. Anthony Falls Laboratory Fax: (612) 627-4609
Dept. of Civil Engineering
University of Minnesota
Mississippi River @ 3rd Ave. SE
Minneapolis, MN 55414