[GRASS-SVN] r59322 - grass-addons/grass6/raster/r.surf.nnbathy

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 25 01:19:25 PDT 2014


Author: hamish
Date: 2014-03-25 01:19:25 -0700 (Tue, 25 Mar 2014)
New Revision: 59322

Modified:
   grass-addons/grass6/raster/r.surf.nnbathy/r.surf.nnbathy
Log:
cleanup

Modified: grass-addons/grass6/raster/r.surf.nnbathy/r.surf.nnbathy
===================================================================
--- grass-addons/grass6/raster/r.surf.nnbathy/r.surf.nnbathy	2014-03-24 22:47:37 UTC (rev 59321)
+++ grass-addons/grass6/raster/r.surf.nnbathy/r.surf.nnbathy	2014-03-25 08:19:25 UTC (rev 59322)
@@ -6,10 +6,10 @@
 #
 # AUTHOR(S):  Maciej Sieczka
 #
-# PURPOSE:	  Interpolate raster surface using the "nnbathy" natural
+# PURPOSE:    Interpolate raster surface using the "nnbathy" natural
 #             neighbor interpolation program.
 #
-# VERSION:	  1.95, developed over GRASS 6.3 CVS
+# VERSION:	1.95, developed over GRASS 6.3 CVS
 #
 # COPYRIGHT:  (c) Maciej Sieczka
 #
@@ -59,41 +59,38 @@
 # - cosmetics
 # - manual cleaned up
 
-#%Module
-#%  description: Interpolate raster using the nnbathy natural neighbor interpolation program.
-#%END
 
+#%Module
+#% description: Interpolates a raster map using the nnbathy natural neighbor interpolation program.
+#%End
 #%option
 #% key: input
 #% type: string
 #% gisprompt: old,cell,raster
-#% description: The raster map to interpolate on
+#% description: Name of input raster map
 #% required : yes
-#%END
-
+#%End
 #%option
 #% key: output
 #% gisprompt: new,cell,raster
 #% type: string
-#% description: Name of the output raster map
+#% description: Name for output raster map
 #% required : yes
-#%END
-
+#%End
 #%option
 #% key: alg
 #% type: string
 #% options: l,nn,ns
 #% answer: nn
-#% description: Interpolation algorithm for nnbathy to use
+#% descriptions: l;Linear;nn;Sibson natural neighbor;ns;Non-Sibsonian natural neighbor
+#% description: Interpolation algorithm
 #% required : yes
-#%END
+#%End
 
 
 # called from GRASS?
 if [ -z "$GISBASE" ]; then
-  echo
   echo "ERROR: You must be in GRASS GIS to run this program." 1>&2
-  echo
   exit 1
 fi
 
@@ -101,17 +98,16 @@
   exec g.parser "$0" "$@"
 fi
 
+
 # check if we have awk
 if [ ! -x "`which awk`" ]; then
-  g.message -e '"awk" executable required but not found.' 1>&2
+  g.message -e '"awk" executable required but not found.'
   exit 1
 fi
 
 # check if we have nnbathy
 if [ ! -x "`which nnbathy`" ]; then
-  echo
-  g.message -e '"nnbathy" executable required but not found. Follow the instructions in r.surf.nnbathy manual to install it.' 1>&2
-  echo
+  g.message -e '"nnbathy" executable required but not found. Follow the instructions in r.surf.nnbathy manual to install.'
   exit 1
 fi
 
@@ -127,9 +123,7 @@
 # set up temporary files
 TMP="`g.tempfile pid=$$`"
 if [ $? -ne 0 ] || [ -z "$TMP" ]; then
-  echo
   g.message -e 'Unable to create temporary files.' 1>&2
-  echo
   exit 1
 fi
 
@@ -145,22 +139,18 @@
   # Reset traps before normal script termination to avoid bogus ERROR message, as
   # we put a trap on signal 0.
   trap - 0 2 3 15 
-  rm -f "$TMP" "$TMP.${PROG}.input_xyz" "$TMP.${PROG}.output_xyz" "$TMP.${PROG}.output_grd"
+  rm -f "$TMP" "$TMP.$PROG.input_xyz" "$TMP.$PROG.output_xyz" "$TMP.$PROG.output_grd"
 }
 
 # define run-time error handling procedure
 proc_runtime_error() {
-  echo
-  g.message -e "There was an error at the script's run time. Please try to debug the problem if you can and let me know by email." 1>&2
-  echo
+  g.message -e "There was an error at the script's run time. Please try to debug the problem if you can and let me know by email."
   exit 1
 }
 
 # define user-break procedure
 proc_user_break() {
-  echo
-  g.message -w "User break!"
-  echo
+  g.message -e "User break!"
   proc_cleanup
   exit 1
 }
@@ -171,13 +161,13 @@
 # trap user break
 trap "proc_user_break" 2 3 15
 
+
 # assign main variables from user's input
 INPUT="$GIS_OPT_INPUT"
 OUTPUT="$GIS_OPT_OUTPUT"
-ALG=$GIS_OPT_ALG
+ALG="$GIS_OPT_ALG"
 
 
-
 ### DO IT ###
 
 # Make script terminate (ie. emit signal 0) if any statement returns a
@@ -188,34 +178,41 @@
 set -e
 
 # grab the current region settings
-eval `g.region -gp`
+eval `g.region -g`
 
 # spit out non-null (-n) raster coords + values to be interpolated
-r.stats --q -1gn input="${INPUT}" > "$TMP.${PROG}.input_xyz"
+r.stats -1gn input="$INPUT" --quiet > "$TMP.$PROG.input_xyz"
 
 # set the working region for nnbathy (it's cell-center oriented)
-nn_n=`echo $n | awk -v res="$nsres" '{printf "%.8f",$1-res/2.0}'`
-nn_s=`echo $s | awk -v res="$nsres" '{printf "%.8f",$1+res/2.0}'`
-nn_w=`echo $w | awk -v res="$ewres" '{printf "%.8f",$1+res/2.0}'`
-nn_e=`echo $e | awk -v res="$ewres" '{printf "%.8f",$1-res/2.0}'`
+nn_n=`echo $n | awk -v res="$nsres" '{printf "%.8f", $1 - res/2.0}'`
+nn_s=`echo $s | awk -v res="$nsres" '{printf "%.8f", $1 + res/2.0}'`
+nn_w=`echo $w | awk -v res="$ewres" '{printf "%.8f", $1 + res/2.0}'`
+nn_e=`echo $e | awk -v res="$ewres" '{printf "%.8f", $1 - res/2.0}'`
 
-null=NaN
-type=double
+null="NaN"
+type="double"
 
-# interpolate
-echo
-g.message -w '"nnbathy" is performing the interpolation now. This may take some time.' 1>&2
-echo
-g.message -w "Once it completes 'All done.' message will be printed." 1>&2
-echo
 
-nnbathy -W 0 -P alg=$ALG -n ${cols}x${rows} -x $nn_w $nn_e -y $nn_n $nn_s -i "$TMP.${PROG}.input_xyz" > "$TMP.${PROG}.output_xyz"
-# Y in "r.stats -1gn" output is in descending order, thus -y must be in MAX MIN order, not MIN MAX, for nnbathy not to produce a grid upside-down
+#### interpolate
+g.message ""
+g.message '"nnbathy" is performing the interpolation now. This may take some time.'
+g.message "Once it completes an 'All done.' message will be printed."
+g.message ""
 
+
+nnbathy -W 0 -P alg="$ALG" -n "${cols}x${rows}" \
+	-x "$nn_w" "$nn_e" -y "$nn_n" "$nn_s" \
+	-i "$TMP.$PROG.input_xyz" \
+       > "$TMP.$PROG.output_xyz"
+
+
+# Y in "r.stats -1gn" output is in descending order, thus -y must be in
+# MAX MIN order, not MIN MAX, for nnbathy not to produce a grid upside-down
+
 # convert the X,Y,Z nnbathy output into a GRASS ASCII grid, then import with r.in.ascii:
 
 # 1 create header
-cat << EOF > "$TMP.${PROG}.output_grd"
+cat << EOF > "$TMP.$PROG.output_grd"
 north: $n
 south: $s
 east: $e
@@ -227,8 +224,8 @@
 EOF
 
 # 2 do the conversion
-echo "Converting nnbathy output to GRASS raster." 1>&2
-echo
+g.message "Converting nnbathy output to GRASS raster ..."
+g.message ""
 
 awk -v cols="$cols" '
 BEGIN {col_cur=1; ORS=" "}
@@ -236,30 +233,29 @@
  if (col_cur==cols) {ORS="\n"; col_cur=0; print $3; ORS=" "}
 		    else {print $3}
  col_cur++
-}' "$TMP.${PROG}.output_xyz" >> "$TMP.${PROG}.output_grd"
+}' "$TMP.$PROG.output_xyz" >> "$TMP.$PROG.output_grd"
 
 # 3 import
-r.in.ascii input="$TMP.${PROG}.output_grd" output="${OUTPUT}" > /dev/null
+r.in.ascii input="$TMP.$PROG.output_grd" output="$OUTPUT" --quiet
 
 # store comand history in raster's metadata
 
-r.support map=${OUTPUT} history=""
-r.support map=${OUTPUT} history="script run syntax:"
-r.support map=${OUTPUT} history=""
-r.support map=${OUTPUT} history="r.surf.nnbathy alg=$ALG input=${INPUT} output=${OUTPUT}"
-r.support map=${OUTPUT} history=""
-r.support map=${OUTPUT} history="nnbathy run syntax:"
-r.support map=${OUTPUT} history=""
-r.support map=${OUTPUT} history="nnbathy -W 0 -P alg=$ALG -n ${cols}x${rows} "
-r.support map=${OUTPUT} history="-x $nn_w $nn_e "
-r.support map=${OUTPUT} history="-y $nn_n $nn_s "
-r.support map=${OUTPUT} history="-i tmp_in > tmp_out"
-r.support map=${OUTPUT} history=""
+r.support map="$OUTPUT" history=""
+r.support map="$OUTPUT" history="script run syntax:"
+r.support map="$OUTPUT" history=""
+r.support map="$OUTPUT" history="r.surf.nnbathy alg=$ALG input=$INPUT output=$OUTPUT"
+r.support map="$OUTPUT" history=""
+r.support map="$OUTPUT" history="nnbathy run syntax:"
+r.support map="$OUTPUT" history=""
+r.support map="$OUTPUT" history="nnbathy -W 0 -P alg=$ALG -n ${cols}x$rows "
+r.support map="$OUTPUT" history="-x $nn_w $nn_e "
+r.support map="$OUTPUT" history="-y $nn_n $nn_s "
+r.support map="$OUTPUT" history="-i tmp_in > tmp_out"
+r.support map="$OUTPUT" history=""
 
 ### ALL DONE ###
 
 proc_cleanup
 
-echo
-echo "All done." 1>&2
-echo
+g.message "All done."
+



More information about the grass-commit mailing list