[GRASS-SVN] r56123 - grass/branches/develbranch_6/scripts/r.mask

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 4 20:50:33 PDT 2013


Author: hamish
Date: 2013-05-04 20:50:33 -0700 (Sat, 04 May 2013)
New Revision: 56123

Modified:
   grass/branches/develbranch_6/scripts/r.mask/description.html
   grass/branches/develbranch_6/scripts/r.mask/r.mask
Log:
fix #1525 & cleanup

Modified: grass/branches/develbranch_6/scripts/r.mask/description.html
===================================================================
--- grass/branches/develbranch_6/scripts/r.mask/description.html	2013-05-04 18:43:37 UTC (rev 56122)
+++ grass/branches/develbranch_6/scripts/r.mask/description.html	2013-05-05 03:50:33 UTC (rev 56123)
@@ -39,14 +39,14 @@
 is removed.
 <p>
 
-The mask is read as an integer map. If MASK is actually a
+The MASK is read as an integer map. If MASK is actually a
 floating-point map, the values will be converted to integers using the
 map's quantisation rules (this defaults to round-to-nearest, but can
 be changed with r.quant).
 <p>
 
 <em>r.mask</em> uses <em>r.reclass</em> to create a reclassification of an
-existing raster map and name it MASK. A reclass map takes up less space, but
+existing raster map and name it <tt>MASK</tt>. A reclass map takes up less space, but
 is affected by any changes to the underlying map from which it was created.
 The user can select category values from the input raster to use in the MASK
 with the <em>maskcats</em> parameter; if <em>r.mask</em> is run from the
@@ -58,6 +58,7 @@
 <em>r.mask</em> can be done using <em>r.mapcalc</em>, 
 <em>g.region</em>, and other commands.
 
+
 <h2>EXAMPLES</h2>
 
 Creating a raster MASK, for showing only elevations of lakes:
@@ -84,6 +85,7 @@
 d.rast geology_30m
 </pre></div>
 
+
 <h2>SEE ALSO</h2>
 <em>
 <a href="g.region.html">g.region</a>,
@@ -93,6 +95,7 @@
 <a href="g.rename.html">g.rename</a>
 </em>
 
+
 <h2>AUTHOR</h2>
 
 Michael Barton, Arizona State University

Modified: grass/branches/develbranch_6/scripts/r.mask/r.mask
===================================================================
--- grass/branches/develbranch_6/scripts/r.mask/r.mask	2013-05-04 18:43:37 UTC (rev 56122)
+++ grass/branches/develbranch_6/scripts/r.mask/r.mask	2013-05-05 03:50:33 UTC (rev 56123)
@@ -6,7 +6,7 @@
 # AUTHOR(S):	Michael Barton, Arizona State University
 #               Markus Neteler
 # PURPOSE:	    Facilitates creation of raster MASK using r.reclass
-# COPYRIGHT:	(C) 2005, 2007-2009 by the GRASS Development Team
+# COPYRIGHT:	(C) 2005-2013 by the GRASS Development Team
 #
 #		This program is free software under the GNU General Public
 #		License (>=v2). Read the file COPYING that comes with GRASS
@@ -29,7 +29,8 @@
 #%option
 #% key: maskcats
 #% type: string
-#% description: Category values to use for MASK (format: 1 2 3 thru 7 *)
+#% label: Category values to use for MASK
+#% description: format: 1 2 3 thru 7 *
 #% answer: *
 #% guisection: Create
 #%end
@@ -49,12 +50,12 @@
 #%end
 
 if  [ -z "$GISBASE" ] ; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
+   echo "You must be in GRASS GIS to run this program." >&2
+   exit 1
 fi
 
 if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
+   exec g.parser "$0" "$@"
 fi
 
 if [ -n "$GRASS_OVERWRITE" ] && [ "$GRASS_OVERWRITE" -eq 1 ] ; then
@@ -62,32 +63,32 @@
 fi
 
 if [ -z "$GRASS_VERBOSE" ] || [ "$GRASS_VERBOSE" -le 2 ] ; then
-  BEQUIET="--quiet"
+   BEQUIET="--quiet"
 else
-  BEQUIET=""
+   BEQUIET=""
 fi
 
 # temp file
-TEMPRAST="r_mask_$$"
+TEMPRAST="tmp_r_mask_$$"
 
 cleanup()
 {
- g.remove --q rast="$TEMPRAST"
+   g.remove --quiet rast="$TEMPRAST"
 }
 
 # what to do in case of user break:
 exitprocedure()
 {
- g.message -e 'User break!'
- cleanup
- exit 1
+   g.message -e 'User break!'
+   cleanup
+   exit 1
 }
 
 # shell check for user break (signal list: trap -l)
 trap "exitprocedure" 2 3 15
 
-# if map is given check if existing
-if [ -n "$GIS_OPT_INPUT" ]; then
+# if input map is given, check if it exists
+if [ -n "$GIS_OPT_INPUT" ] ; then
    eval `g.findfile element=cell file="$GIS_OPT_INPUT"`
    filename="$fullname"
    if [ -z "$filename" ] ; then
@@ -96,50 +97,57 @@
    fi
 fi
 
-if [ -n "$GIS_OPT_MASKCATS" -a "$GIS_FLAG_R" -eq 0 ]; then
-   eval `r.info -t $GIS_OPT_INPUT`
+if [ "$GIS_FLAG_R" -eq 1 ] ; then
+   # remove existing MASK from current mapset
+   if test -f "`g.gisenv GISDBASE`/`g.gisenv LOCATION_NAME`/`g.gisenv MAPSET`/cell/MASK" ; then
+      g.remove rast=MASK
+      g.message $BEQUIET "Raster MASK removed"
+   else
+      g.message $BEQUIET -w "No existing MASK to remove"
+   fi
+   exit 0
+fi
+
+
+# create new MASK
+if [ -n "$GIS_OPT_MASKCATS" -a "$GIS_OPT_MASKCATS" != '*' ] ; then
+   # test for compatibility
+   eval `r.info -t "$GIS_OPT_INPUT"`
    if [ "$datatype" != "CELL" ] ; then
-      g.message -e "Raster map <$GIS_OPT_INPUT> must be integer for maskcats parameter"
+      g.message -e "The raster map <$GIS_OPT_INPUT> must be integer (CELL type) \
+		    in order to use the 'maskcats' parameter"
       exit 1
    fi
 fi
 
-if [ "$GIS_FLAG_R" -eq 1 ]; then
-	if test -f "`g.gisenv GISDBASE`/`g.gisenv LOCATION_NAME`/`g.gisenv MAPSET`/cell/MASK" ; then
- 		g.remove rast=MASK
- 		g.message $BEQUIET "Raster MASK removed"
- 	else
- 		g.message $BEQUIET -w "No existing MASK to remove"
-	fi
-else
-	if [ -z "$GIS_OPT_INPUT" ]; then
-		g.message $BEQUIET -w "No raster map for MASK provided"
-		exit 1;
-	fi
-	if [ "$GIS_FLAG_O" -eq 1 ]; then
-		echo "$GIS_OPT_MASKCATS = 1" | r.reclass input="$GIS_OPT_INPUT" output=MASK --o
-	else 
-		# does map exist in CURRENT mapset?
-		eval `g.findfile element=cell file=MASK mapset="$MAPSET"`
-		if [ -n "$file" ] ; then
-		   g.message -e "MASK already found in current mapset. Delete first or overwrite"
-		   exit 1
-		fi
+if [ -z "$GIS_OPT_INPUT" ] ; then
+   g.message $BEQUIET -w "No raster map for MASK provided"
+   exit 1
+fi
 
-		echo "$GIS_OPT_MASKCATS = 1" | r.reclass input="$GIS_OPT_INPUT" output=MASK
-	fi
+if [ "$GIS_FLAG_O" -eq 1 ] ; then
+   echo "$GIS_OPT_MASKCATS = 1" | r.reclass input="$GIS_OPT_INPUT" output=MASK --o
+else 
+   # does map exist in CURRENT mapset?
+   eval `g.findfile element=cell file=MASK mapset="$MAPSET"`
+   if [ -n "$file" ] ; then
+      g.message -e "MASK already found in current mapset. Delete first or overwrite"
+      exit 1
+   fi
 
-        if [ "$GIS_FLAG_I" -eq 1 ]; then
-		g.rename --q rast=MASK,"$TEMPRAST"
-		r.mapcalc "MASK = if(isnull($TEMPRAST),1,null())"
-		g.remove --q rast="$TEMPRAST"
-		g.message $BEQUIET "Inverted MASK created. All subsequent raster operations"
-	else
-	  g.message $BEQUIET "MASK created. All subsequent raster operations"
-	fi
-        g.message $BEQUIET "will be limited to MASK area"
-        g.message $BEQUIET "Removing or renaming raster file named MASK will"
-        g.message $BEQUIET "restore raster operations to normal"
+   echo "$GIS_OPT_MASKCATS = 1" | r.reclass input="$GIS_OPT_INPUT" output=MASK
 fi
 
+if [ "$GIS_FLAG_I" -eq 1 ] ; then
+   g.rename --quiet rast=MASK,"$TEMPRAST"
+   r.mapcalc "MASK = if(isnull($TEMPRAST),1,null())"
+   g.remove --quiet rast="$TEMPRAST"
+   g.message $BEQUIET "Inverted MASK created. All subsequent raster operations"
+else
+   g.message $BEQUIET "MASK created. All subsequent raster operations"
+fi
+g.message $BEQUIET "will be limited to the MASK area."
+g.message $BEQUIET "Removing or renaming the raster map named 'MASK' will \
+                    restore raster operations to normal."
+
 exit 0



More information about the grass-commit mailing list