[GRASS-dev] MASK_OVERRIDE

Glynn Clements glynn at gclements.plus.com
Tue Feb 19 22:12:03 EST 2008


Ivan Shmakov wrote:

> 	Since it's somewhat cumbersome to work with multiple `MASK's
> 	currently (`r.reclass', `g.copy'?),

Once you have a set of maps suitable for use as masks, switching
between them just requires using g.rename or "g.copy --o". The
r.reclass (or r.mapcalc) step still needs to be done regardless.

> I'd like to introduce
> 	`MASK_OVERRIDE' -- an environment variable analogous to
> 	`WIND_OVERRIDE'.

This would eliminate potential problems with running commands
concurrently. E.g. if you set a mask from the command line, any
display commands used by the GUI will also use the mask.

So, this is really more an issue of flexibility than convenience. It's
probably easier for the user to just use g.rename/g.copy.

> lib/gis/auto_mask.c (G__check_for_auto_masking): Handle `MASK_OVERRIDE';
> allow mask to be in any mapset in the search path.
> lib/gis/mask_info.c (G__mask_info): Likewise.
> 
> diff --git a/lib/gis/auto_mask.c b/lib/gis/auto_mask.c
> index 6828018..0dc218d 100644
> --- a/lib/gis/auto_mask.c
> +++ b/lib/gis/auto_mask.c
> @@ -32,6 +32,7 @@
>  
>  int G__check_for_auto_masking (void)
>  {
> +    char name[GNAME_MAX] = "MASK", mapset[GMAPSET_MAX] = "";
>      struct Cell_head cellhd;
>  
>      /* if mask is switched off (-2) return -2
> @@ -42,14 +43,26 @@ int G__check_for_auto_masking (void)
>  
>      /* if(G__.mask_fd > 0) G_free (G__.mask_buf);*/
>  
> -    /* look for the existence of the MASK file */
> -    G__.auto_mask = (G_find_cell ("MASK", G_mapset()) != 0);
> +    /* check for MASK_OVERRIDE */
> +    {
> +	const char *override = getenv ("MASK_OVERRIDE");
> +	if (override != 0) strncpy (name, override, sizeof (name));

Use "if (override)" rather than an explicit comparison against 0. 
Although C allows comparisons between pointers and literal 0, you may
get a warning, and we have enough of those cluttering up the build
output already. Also, NULL/non-NULL pointers are conventionally as
much of a logic value as zero/non-zero integers. Presumably you
wouldn't write "if ((x == y) != 0)" instead of "if (x == y)"?

> +    }
> +
> +    /* look for the existence of the MASK file; get the mapset name */
> +    {
> +	char *mask_mapset = G_find_cell (name, mapset);
> +
> +	if ((G__.auto_mask = (mask_mapset != 0)) > 0) {
> +	    strncpy (mapset, mask_mapset, sizeof (mapset));
> +	}
> +    }

For this feature to be of real use, you need to allow MASK_OVERRIDE to
be used to disable reading a mask altogether. E.g. if MASK_OVERRIDE is
defined but empty, no mask should be used rather than falling back to
MASK. This would allow the GUI to operate without a mask even when
MASK has been created via the command line.

> diff --git a/lib/gis/mask_info.c b/lib/gis/mask_info.c
> index b82e8ea..dd7f905 100644
> --- a/lib/gis/mask_info.c
> +++ b/lib/gis/mask_info.c
> @@ -58,11 +58,32 @@ int G__mask_info (

>      if(G_is_reclass (name, mapset, rname, rmapset) > 0)
>      {

Personally, I think that returning the base map in the case of a
reclass map is probably bogus. There may be some point to it when the
actual mask will always be MASK@<current mapset>, but if you can
configure it with a variable, the actual mask map will be more useful
than the base map.

I suggest changing G_mask_info() to print the name of the actual mask
map (i.e. either $MASK_OVERRIDE or "MASK at mapset"), as well as the base
map if it's a reclass map.

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


More information about the grass-dev mailing list