[GRASSLIST:1162] Re: Advise for first program in c -

Conn Copas conn.copas at dsto.defence.gov.au
Mon Nov 20 21:44:20 EST 2000

David Finlayson <david_finlayson at yahoo.com> writes:

> I am interested in trying to build a C program that
> accesses GRASS and have a few questions (I'm not a
> programmer).
> I am interesting in writing a routine that traces the
> profile of a river and builds an ascii table of x,y
> coordinate pairs and columns of values associated with
> user-supplied list of rasters.  The idea is to trace a
> river profile and dump out the associated variables
> for each pixel on the river, say manning's n,
> elevation, width, slope etc... Really though, it is
> just a simple program to try in C.
> First, do I need to have a full copy of the source
> code for GRASS or can I work with a binary only
> version and just link against the libraries I need
> mentioned in the programmers manual?  (I've never used
> make before either so I don't understand that yet
> either)

If you are not a programmer and have never used "make" before then you are 
biting off quite a lot, IMHO.

When you build Grass, you wind up with a number of things:

1. A whole bunch of Grass commands, which are really just Unix binaries the same 
as "ls", etc. These can be called from the command line, from within a shell 
script, or from within a C program. 

2. A bunch of Grass libraries, which contain general-purpose, low-level 
functions. Most Grass commands are linked to one or more of those libraries 
because they call some of those functions. In addition, there are functions 
specific to each command.
In general, you should not need the source code unless:

. The supplied commands and/or libraries do not quite do what you want, and you 
wish to make extensions, or

. You decide that you do not wish to invoke external binaries from a C program  
and would rather have a single executable. This could typically be because of 
the performance overheads associated with multiple binaries, or because of the 
inconvenience of parsing the textual output of many Grass commands. In such 
cases, you need at the least to merge your C program and the code for the Grass 
command(s) so that there is only one "main" function.

Off the top of my head, tracing linear features represented as rasters is 
non-trivial in Grass, and will indeed require some src code hackery.

More information about the grass-user mailing list