[GRASS-dev] MASK_OVERRIDE

Ivan Shmakov ivan at theory.asu.ru
Tue Feb 19 11:36:13 EST 2008


	Since it's somewhat cumbersome to work with multiple `MASK's
	currently (`r.reclass', `g.copy'?), I'd like to introduce
	`MASK_OVERRIDE' -- an environment variable analogous to
	`WIND_OVERRIDE'.

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));
+    }
+
+    /* 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));
+	}
+    }
 
     if (G__.auto_mask <= 0)
         return 0;
 
     /* check MASK projection/zone against current region */
-    if (G_get_cellhd ("MASK", G_mapset(), &cellhd) >= 0)
+    if (G_get_cellhd (name, mapset, &cellhd) >= 0)
     {
 	if (cellhd.zone != G_zone() || cellhd.proj != G_projection())
 	{
@@ -59,11 +72,12 @@ int G__check_for_auto_masking (void)
     }
 
     G_unopen_cell(G__.mask_fd );
-    G__.mask_fd = G__open_cell_old ("MASK", G_mapset());
+    G__.mask_fd = G__open_cell_old (name, mapset);
     if (G__.mask_fd < 0)
     {
         G__.auto_mask = 0;
-        G_warning (_("Unable to open automatic MASK file"));
+        G_warning (_("Unable to open automatic MASK (<%s@%s>) file"),
+		   name, mapset);
         return 0;
     }
 
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 (
 {
     char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
 
-    strcpy (name, "MASK");
-    strcpy (mapset, G_mapset());
+    /* NB: the following is painfully close to G__check_for_auto_masking
+     *     (); consider a separate function here
+     */
 
-    if(!G_find_cell (name, mapset))
-	return -1;
+    /* check for MASK_OVERRIDE */
+    {
+	const char *override = getenv ("MASK_OVERRIDE");
+	if (override != 0) {
+	    strncpy (name, override, sizeof (name));
+	} else {
+	    strcpy  (name, "MASK");
+	}
+    }
+
+    /* look for the existence of the MASK file; get the mapset name */
+    {
+	char *mask_mapset = G_find_cell (name, "");
+
+	if (mask_mapset == 0) {
+	    /* NB: `mapset' won't be initialized */
+	    /* . */
+	    return -1;
+	}
+
+	strncpy (mapset, mask_mapset, sizeof (mapset));
+    }
 
     if(G_is_reclass (name, mapset, rname, rmapset) > 0)
     {



More information about the grass-dev mailing list