[GRASS-dev] g.mlist: exclude parameter wish

Hi,

would it be complicated to add an "exclude_pattern" parameter to
g.mlist/g.mremove?

Example: I want to select only the gpcp_1dd_p1d_*_count maps but not the monthly
counts:

g.mlist type=rast patt="gpcp_1dd_p1d_*_count"
gpcp_1dd_p1d_1997_2007_month04_10_count
gpcp_1dd_p1d_1997_count
gpcp_1dd_p1d_1997_month04_10_count
gpcp_1dd_p1d_1998_count
gpcp_1dd_p1d_1998_month04_10_count
gpcp_1dd_p1d_1999_count
gpcp_1dd_p1d_1999_month04_10_count
gpcp_1dd_p1d_2000_count
gpcp_1dd_p1d_2000_month04_10_count
gpcp_1dd_p1d_2001_count
gpcp_1dd_p1d_2001_month04_10_count
gpcp_1dd_p1d_2002_count
gpcp_1dd_p1d_2002_month04_10_count
gpcp_1dd_p1d_2003_count
gpcp_1dd_p1d_2003_month04_10_count
gpcp_1dd_p1d_2004_count
gpcp_1dd_p1d_2004_month04_10_count
gpcp_1dd_p1d_2005_count
gpcp_1dd_p1d_2005_month04_10_count
gpcp_1dd_p1d_2006_count
gpcp_1dd_p1d_2006_month04_10_count
gpcp_1dd_p1d_2007_count
gpcp_1dd_p1d_2007_month04_10_count

Wish (ideal world):

g.mlist type=rast patt="gpcp_1dd_p1d_*_count" exclude="month"
gpcp_1dd_p1d_1997_count
gpcp_1dd_p1d_1998_count
gpcp_1dd_p1d_1999_count
gpcp_1dd_p1d_2000_count
gpcp_1dd_p1d_2001_count
gpcp_1dd_p1d_2002_count
gpcp_1dd_p1d_2003_count
gpcp_1dd_p1d_2004_count
gpcp_1dd_p1d_2005_count
gpcp_1dd_p1d_2006_count
gpcp_1dd_p1d_2007_count

I know that -r and -e are available but I failed to write an exclusion regex.
And often just simple patterns are to be suppressed in the selection.

Markus

Hi Markus

On Wed, 19 Nov 2008, Markus Neteler wrote:

Hi,

would it be complicated to add an "exclude_pattern" parameter to
g.mlist/g.mremove?

Example: I want to select only the gpcp_1dd_p1d_*_count maps but not the monthly
counts:

g.mlist type=rast patt="gpcp_1dd_p1d_*_count"

What about
g.mlist type=rast patt="gpcp_1dd_p1d_???_count"

I think that should work with a shell script version of g.mlist anyway, as ? characters can be used to represent single characters in wildcard patterns passed to the ls command.

Paul

gpcp_1dd_p1d_1997_2007_month04_10_count
gpcp_1dd_p1d_1997_count
gpcp_1dd_p1d_1997_month04_10_count
gpcp_1dd_p1d_1998_count
gpcp_1dd_p1d_1998_month04_10_count
gpcp_1dd_p1d_1999_count

On Wed, Nov 19, 2008 at 10:51 AM, Paul Kelly
<paul-grass@stjohnspoint.co.uk> wrote:

Hi Markus

On Wed, 19 Nov 2008, Markus Neteler wrote:

Hi,

would it be complicated to add an "exclude_pattern" parameter to
g.mlist/g.mremove?

Example: I want to select only the gpcp_1dd_p1d_*_count maps but not the
monthly
counts:

g.mlist type=rast patt="gpcp_1dd_p1d_*_count"

What about
g.mlist type=rast patt="gpcp_1dd_p1d_???_count"

bingo :slight_smile:

I think that should work with a shell script version of g.mlist anyway, as ?
characters can be used to represent single characters in wildcard patterns
passed to the ls command.

This works, resolved for today.

Markus

Markus wrote:

g.mlist type=rast patt="gpcp_1dd_p1d_*_count"
exclude="month"
gpcp_1dd_p1d_1997_count
gpcp_1dd_p1d_1998_count
gpcp_1dd_p1d_1999_count
gpcp_1dd_p1d_2000_count
gpcp_1dd_p1d_2001_count
gpcp_1dd_p1d_2002_count
gpcp_1dd_p1d_2003_count
gpcp_1dd_p1d_2004_count
gpcp_1dd_p1d_2005_count
gpcp_1dd_p1d_2006_count
gpcp_1dd_p1d_2007_count

I know that -r and -e are available but I failed to write
an exclusion regex.
And often just simple patterns are to be suppressed in the
selection.

no idea about the C version, but with the shell script version it would
be roughly like

if [ -n "$GIS_OPT_EXCLUDE" ] ; then
  EXCLD_STR="| grep -v $GIS_OPT_EXCLUDE"
else
  EXCLD_STR=""
fi

g.list * ... | ... $EXCLD_STR

do you now use g.mlist | grep -v 'expr' ?

Hamish

On Wed, Nov 19, 2008 at 11:12 AM, Hamish <hamish_b@yahoo.com> wrote:

Markus wrote:

g.mlist type=rast patt="gpcp_1dd_p1d_*_count"
exclude="month"
gpcp_1dd_p1d_1997_count
gpcp_1dd_p1d_1998_count
gpcp_1dd_p1d_1999_count
gpcp_1dd_p1d_2000_count
gpcp_1dd_p1d_2001_count
gpcp_1dd_p1d_2002_count
gpcp_1dd_p1d_2003_count
gpcp_1dd_p1d_2004_count
gpcp_1dd_p1d_2005_count
gpcp_1dd_p1d_2006_count
gpcp_1dd_p1d_2007_count

I know that -r and -e are available but I failed to write
an exclusion regex.
And often just simple patterns are to be suppressed in the
selection.

no idea about the C version, but with the shell script version it would
be roughly like

if [ -n "$GIS_OPT_EXCLUDE" ] ; then
EXCLD_STR="| grep -v $GIS_OPT_EXCLUDE"
else
EXCLD_STR=""
fi

g.list * ... | ... $EXCLD_STR

Yes - but I dunno how to implement that in C.

do you now use g.mlist | grep -v 'expr' ?

g.mlist type=rast patt="gpcp_1dd_p1d_*_count" | grep -v month | tr
'\n' ',' | sed 's+,$++g

but that's rather funky for daily usage.
[for today, Paul's trick helped but the problem will return]

Markus

Markus,

We could add the exclude option, but I'm not so sure if we really need it.
You can solve your problem by using a more specific wildcard if Paul's
trick doesn't work.

pat="gpcp_1dd_p1d_[0-9][0-9][0-9][0-9]_count"

It's a little lengthy, but it works. Any better examples where we might
want the exclude option?

Huidae

On Wed, Nov 19, 2008 at 12:40:52PM +0100, Markus Neteler wrote:

On Wed, Nov 19, 2008 at 11:12 AM, Hamish <hamish_b@yahoo.com> wrote:
> Markus wrote:
>> g.mlist type=rast patt="gpcp_1dd_p1d_*_count"
>> exclude="month"
>> gpcp_1dd_p1d_1997_count
>> gpcp_1dd_p1d_1998_count
>> gpcp_1dd_p1d_1999_count
>> gpcp_1dd_p1d_2000_count
>> gpcp_1dd_p1d_2001_count
>> gpcp_1dd_p1d_2002_count
>> gpcp_1dd_p1d_2003_count
>> gpcp_1dd_p1d_2004_count
>> gpcp_1dd_p1d_2005_count
>> gpcp_1dd_p1d_2006_count
>> gpcp_1dd_p1d_2007_count
>>
>> I know that -r and -e are available but I failed to write
>> an exclusion regex.
>> And often just simple patterns are to be suppressed in the
>> selection.
>
>
> no idea about the C version, but with the shell script version it would
> be roughly like
>
> if [ -n "$GIS_OPT_EXCLUDE" ] ; then
> EXCLD_STR="| grep -v $GIS_OPT_EXCLUDE"
> else
> EXCLD_STR=""
> fi
>
>
> g.list * ... | ... $EXCLD_STR

Yes - but I dunno how to implement that in C.

> do you now use g.mlist | grep -v 'expr' ?

g.mlist type=rast patt="gpcp_1dd_p1d_*_count" | grep -v month | tr
'\n' ',' | sed 's+,$++g

but that's rather funky for daily usage.
[for today, Paul's trick helped but the problem will return]

Markus
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Huidae Cho wrote:

We could add the exclude option, but I'm not so sure if we really need it.
You can solve your problem by using a more specific wildcard if Paul's
trick doesn't work.

pat="gpcp_1dd_p1d_[0-9][0-9][0-9][0-9]_count"

It's a little lengthy, but it works. Any better examples where we might
want the exclude option?

Also, you can always use 'g.mlist ... | grep -v ...'.

OTOH, adding e.g. G_set_ls_exclude_filter() wouldn't be much work.

Although it's theoretically possible to complement or "subtract"
regular expressions, in practice it's rather ugly, i.e. the result is
often far more complex than the original(s). And it isn't possible to
complement glob patterns.

While we're on the subject, I'm wondering if it would be worthwhile
using glob() where it's available (i.e. everywhere except Windows),
instead constructing an equivalent[1] regexp.

[1] There are a number of differences between g.mlist's glob patterns
and glob(), e.g. it doesn't support complemented ranges, it interprets
metacharacters within ranges, etc.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

> We could add the exclude option, but I'm not so sure if we really need it.
> You can solve your problem by using a more specific wildcard if Paul's
> trick doesn't work.
>
> pat="gpcp_1dd_p1d_[0-9][0-9][0-9][0-9]_count"
>
> It's a little lengthy, but it works. Any better examples where we might
> want the exclude option?

Also, you can always use 'g.mlist ... | grep -v ...'.

OTOH, adding e.g. G_set_ls_exclude_filter() wouldn't be much work.

Although it's theoretically possible to complement or "subtract"
regular expressions, in practice it's rather ugly, i.e. the result is
often far more complex than the original(s). And it isn't possible to
complement glob patterns.

I've now added G_set_ls_exclude_filter() and an exclude= option to
g.list.

--
Glynn Clements <glynn@gclements.plus.com>

On Thu, Nov 20, 2008 at 4:22 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Huidae Cho wrote:

We could add the exclude option, but I'm not so sure if we really need it.
You can solve your problem by using a more specific wildcard if Paul's
trick doesn't work.

pat="gpcp_1dd_p1d_[0-9][0-9][0-9][0-9]_count"

It's a little lengthy, but it works. Any better examples where we might
want the exclude option?

Imagine thousands of similar map names (derivatives of time series
elaborations), then wildcards won't suffice.

Also, you can always use 'g.mlist ... | grep -v ...'.

In a script it needs to be:
LIST=`g.mlist type=rast patt=... | grep -v ... | tr '\n' ',' | sed 's+,$++g`

which is already more complicated (not for me but for xx% of
the users).

OTOH, adding e.g. G_set_ls_exclude_filter() wouldn't be much work.

This would be pretty convenient.

Although it's theoretically possible to complement or "subtract"
regular expressions, in practice it's rather ugly, i.e. the result is
often far more complex than the original(s). And it isn't possible to
complement glob patterns.

While we're on the subject, I'm wondering if it would be worthwhile
using glob() where it's available (i.e. everywhere except Windows),
instead constructing an equivalent[1] regexp.

[1] There are a number of differences between g.mlist's glob patterns
and glob(), e.g. it doesn't support complemented ranges, it interprets
metacharacters within ranges, etc.

I have no idea, sorry... so cannot comment on "glob".

Markus