[GRASS-dev] g.mlist as C implementation?
Hamish
hamish_nospam at yahoo.com
Mon Sep 10 19:46:01 EDT 2007
Markus Neteler wrote:
> >>> when using g.mlist in mapsets with thousands of maps in
> >>> it (as happens with MODIS time series), it gets extremely
> >>> slow.
Hamish:
> > see attached patch for consideration. Following Glynn's suggestion it
> > gets rid of the loop for each map name,
Markus:
> I have made these tests:
..
> for i in `seq 1 10000` ; do r.mapcalc map$i=1 ;done
> # old g.mlist
> real 0m54.725s
..
> # new g.mlist
> real 0m0.416s
..
> => 0.416/54.725 = 0.0076
..
> Amazing!
well, the time is just proportional to the number of program calls. by
removing that loop that number is now finite, whereas before it depended
on the number of maps. Of course the expanded g.list solution is just 1
program call.
Glynn:
> Here's my proposed alternative. It avoids the use of backticks in
> favour of a pipeline ending in a while loop.
I don't mind which patch gets used; the simpler the better.
I noticed parts of the script may be a bit fragile/inefficient, which is
of concern for a module mainly intended as a scripting tool.
- The script relies on "echo -n"; not portable?
http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html
+ g.list type=$type mapset=$mapset \
+ | grep -v '^-\+$' \
+ | grep -v "files available" \
+ | grep -vi "mapset" \
+ | sed 's/ */\n/g' \
+ | grep -v '^$' \
+ | grep "$search" \
+ | sort \
+ | while read i
- combine the groups of sequential greps into single calls with the \|
"OR" expr.
- The `grep -v "files available"` will fail when translated,
'raster files available in mapset <PERMANENT>:'
I assume the `grep -vi "mapset"` is there as a poor workaround for that.
("mapset" will not be as translated as often as "files available") :-/
Is there a standard C library fn we can call to get regex support?
Direct pattern searching in g.list would be preferable; I agree that
a DIY reimplementation is a lot more trouble than it is worth. (unless
some standard GPL code is copied verbatim into a new G_regex() libgis fn)
?
things like r.out.mpeg have basic map-name matching capabilities already.
Hamish
More information about the grass-dev
mailing list