[GRASS-dev] g.mlist as C implementation?
Glynn Clements
glynn at gclements.plus.com
Mon Sep 10 14:25:10 EDT 2007
Hamish wrote:
> Glynn Clements wrote:
> >
> > 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.
> ..
> Glynn Clements wrote:
> > The main thing which stands out is that it invokes "grep" once for
> > every name returned by g.list:
>
> see attached patch for consideration. Following Glynn's suggestion it
> gets rid of the loop for each map name, making the script ~50% faster
> than before, but still about twice as slow as a single call to g.list.
Here's my proposed alternative. It avoids the use of backticks in
favour of a pipeline ending in a while loop.
--
Glynn Clements <glynn at gclements.plus.com>
-------------- next part --------------
--- scripts/g.mlist/g.mlist~ 2007-04-19 17:45:00.000000000 +0100
+++ scripts/g.mlist/g.mlist 2007-09-10 19:20:51.000000000 +0100
@@ -56,29 +56,25 @@
#%end
do_list() {
- list=""
- for i in `g.list type=$type mapset=$mapset | grep -v '^-\+$' | grep -v "files available" | grep -vi "mapset"`
- do
- if [ ! "$search" ] ; then
- list="$list $i"
- else
- list="$list `echo $i | grep \"$search\"`"
- fi
- done
-
- if [ ! "$list" ] ; then
- return
+ if [ ! "$search" ] ; then
+ search="."
fi
- sorted_list=`echo "$list" | tr ' ' '\n' | sort | tr '\n' ' '`
-
if [ $GIS_FLAG_M -eq 1 ] ; then
MAPSET="@$mapset"
else
MAPSET=""
fi
- i=""
- for i in $sorted_list
+
+ 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
do
if [ "$start" ] ; then
if [ -z "$sep" ] ; then
More information about the grass-dev
mailing list