C-GRASS combination

Lars Schylberg larss at fmi.kth.se
Tue Nov 17 11:57:32 EST 1992


> Is it possible to call GRASS commands such as r.mapcalc from within a UNIX-C
> program?  Is it possible to use UNIX-C statements withing a shell/macro?
> I have noticed that the parameters of the r.mapcalc command (for example - 
> 'if(soil==2,10,0)' is the same as a C-statement and wondered if there is any
> way to interface.

I wrote such a program a while ago.  What I did was that I wrote it as 
a new grass tool as described in the grass4.0 programming manual.  The
shell variables used in grass are then defined, since your running the
new c-program from Grass.

Here is an example of the use of r.mapcalc:

sprintf( cmd1, "echo \"tmp3 = if ( tmp2 == 0 )\" | r.mapcalc ");
system( cmd1 );

The program that I wrote was an old Bourne-shell script that I
embedded in C code.  I was however disapointed since the new c-program
wasn't so much faster than the old Bourne shell script.  I had a lot
of test statements in the Bourne-shell script that I thought should be
speeded up in the C program, by doing the tests in C.  But I only
saved a couple of percent i processing time.

Well I wondering myself if the system call slowes down the execution. 
Maybe there might be some other way to execute the r.mapcalc statement 
faster.

Lars

Lars Schylberg                    Email: larss at fmi.kth.se  
Department of Photogrammetry 
Royal Institute of Technology     Tel.   +46 8 790 86 33   
S-100 44  STOCKHOLM, SWEDEN       Fax.   +46 8 790 66 10







More information about the grass-user mailing list