r.covar and closing raster files problem

Tom Charnock charnotw at helios.aston.ac.uk
Fri Sep 6 08:00:00 EDT 1996



Putting: 

for (i = 0; i < nfiles; i++)
  {
  G_close_cell(fd[i]);
  }

in the code just before exit(0); will close all the rasters
opened by that particular call to r.covar. Though there is also
the problem that if r.covar encounters a raster it cannot open
(i.e it does not exist or there is some other problem) then it exits
immediately without closing the rasters it did manage to open, simlar
code could be put in to deal with this.

However I'm not sure if this is your problem, my understanding
was that when a program exits, as r.covar must do when the system
call returns to the parent program, then all open files are closed
by the operating system. Though you are right, it is good practice
to close files when they are finished with. 

let me know if you need more info on modifying the code.

Good luck 

Tom  Charnock

P.S. I didn't know The Environment Agency had gone for GRASS, 
are there any jobs going ? 8-)



Tom Charnock                       O--O
Dept Civil Engineering            (~~~~)
Aston University                 (  __  )
Birmingham B4 7ET UK             /|\  /|\
charnotw at sun.aston.ac.uk


> 
> Hello,
> 
> I'm trying to write a C programme that uses a system call to r.covar (to find
> the correlation between two raster layers) in a loop. The loop needs to go ro
und
> 72 x 72 times in order to find the correlation between the ratio of each of 7
2
> channels of a multispectral image against another raster layer.
> 
> The programme works fine for the first 25 times that the loop calls r.covar
> (having used 24 raster layers), then (and each subsequent time) when r.covar 
is
> called to correlate two layers I get the error message :
> 
>       WARNING: Too many open raster files
> 
> I've checked the main.c source code for r.covar, and after it's main processi
ng
> it doesn't close the raster files it has opened. Therefore memory isn't freed
> after r.covar has finished processing.
> 
> Does anybody know how I can modify the source code for r.covar so that it clo
ses
> all the raster files it has opened?
> 
>  Also are there other GRASS programmes that don't close files that have been
> opened at the end of processing - because if there are I think these should b
e
> modified, one of the first things I was taught when writing code to handle fi
les
> was to make sure at the end of processing I should close all opened files.
> 
> 
> Thanks,
> 
> Alastair Duncan,
> GIS Data Officer,
> National Centre for Environmental Monitoring and Surveillance,
> The Environment Agency,
> Rivers House,
> Lower Bristol Road,
> Bath, UK.






More information about the grass-user mailing list