From Leonard Coop: Re: Forestry and Grass + scripts for models (fwd)

Agustin Lobo alobo at ija.csic.es
Wed Oct 27 06:24:33 EDT 1999


I forward this message to the
list as it seems that Leonard has problems to
post messages:

Agus
---------- Forwarded message ----------
Date: Tue, 26 Oct 1999 11:26:08 -0700
From: Leonard Coop <coopl at ava.bcc.orst.edu>
To: grass at cecer.army.mil, alobo at ija.csic.es
Subject: Re: Forestry and Grass + scripts for models

Agustin,
(note I cant post to grass list - It always seems to bounce, so you may
want
to forward this to the list)

Here is a snippet from a perl script (I didnt write it but I use it)
running GRASS showing how you can use perl files as standard i/o to 
write to GRASS functions, in this case r.mapcalc:

    open RMAPCALC, "|r.mapcalc" or die "Can't launch r.mapcalc";
    # STEP 5: ADD CORRECTIONS
    print RMAPCALC "$corrname = ($basename * $rationame)/1000\n";
    # STEPS 6: FORCE NEGATIVES TO ZERO
    print RMAPCALC "$outname = max($corrname,0)\n";
    close RMAPCALC;

Thus once you know perl it is pretty obvious how to use grass like any
other
UNIX commands. I am still learning perl myself. We pass these scripts
into GRASS
with a "DOGRASS" script that sets up a GRASS shell environment and all
(similar to
GRASSLINKS, which is now done in perl I believe).
Len

Agustin Lobo wrote:
> 
> Well, I would not say that is "ideal", it is possible.
> Actually, writing (i.e. population or metapopulation) models
> in C (or C++) is far from ideal, as writing the code tends to
> imply too much time devoted to "low level" (not a fair term, but an
> usual one) programming and the resulting code uses to be
> too obscure for others to read (often it's easier to
> write your own program in C than reading it afterwards).
> 
> A closer-to-ideal situation would be having an script language, from
> which you can call grass programs. I wrote a model
> for gap dynamics in a neotropical forest using the c-shell
> and calling grass functions. It was better (easier and faster) than
> using C, but the code was almost as cryptic. Another problem
> was the very limited power of the c-shell to manage
> arrays (only 1-D) and to make computations (only integers), which
> had to solve by using awk sometimes.
> 
> Now there are other script languages than could be better, i.e.,
> like perl, does anybody have experience at integrating grass
> commands within a perl script?
> 
> Finally, I explored the possibility of using Splus (R is now a
> free alternative and mostly compatible) programs, as Splus (or R)
> can issue OS commands. Therefore, it is possible, from within an
> Splus program, run i.e. r.stats and read in the result into
> an S array and make computations. But the communication is
> through files.
> 
> In any case, I think that the (near) future of Grass should contemplate
> the use of an scripting language for modeling. Is anybody at Baylor
> working in this direction?
> 
> Agus
> 
> Dr. Agustin Lobo
> Instituto de Ciencias de la Tierra (CSIC)
> Lluis Sole Sabaris s/n
> 08028 Barcelona SPAIN
> tel 34 93409 5410
> fax 34 93411 0012
> alobo at ija.csic.es
> http://pangea.ija.csic.es/alobo
> 
> On Tue, 26 Oct 1999, Roy Sanderson wrote:
> 
> > Hello
> >
> > Colleagues of mine have been using GRASS for several years to model red and
> > grey squirrel populations under different forest management regimes, and
> > various control measures for grey squirrels.  Grass is ideal for this type
> > of work, especially since you can integrate your own process-based
> > population models (we write ours in C) into the Grass environment.
> >
> > Roy
> >
> > At 04:32 pm 26/10/99 +0200, you wrote:
> > >Hello (again)
> > >
> > >I'm wondering if anybody of the grass-community has used Grass combined
> > >with forestry --> modelling and planning etc.
> > >
> > >
> > >
> > >sincerely Kjell-Olav
> > >
> > >
> > >
> >
> > ----------------------------------------------------------------------------
> > Roy Sanderson
> > Centre for Land Use and Water Resources Research
> > Porter Building
> > University of Newcastle
> > Newcastle upon Tyne
> > NE1 7RU
> > United Kingdom
> >
> > Tel: +44 191 222 7789
> > Fax: +44 191 222 6563
> > r.a.sanderson at newcastle.ac.uk
> > URL: http://www.cluwrr.ncl.ac.uk
> > ----------------------------------------------------------------------------
> >

-- 
Leonard Coop
Research Associate
Entomology Dept & Integrated Plant Protection Center
2046 Cordley
Oregon State University
Corvallis OR 97331-2907



More information about the grass-user mailing list