[GRASS-SVN] r46743 - in grass-addons/raster: . r.flip

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 19 23:20:08 EDT 2011


Author: hamish
Date: 2011-06-19 20:20:08 -0700 (Sun, 19 Jun 2011)
New Revision: 46743

Added:
   grass-addons/raster/r.flip/
   grass-addons/raster/r.flip/Makefile
   grass-addons/raster/r.flip/r.flip
Log:
+ r.flip scripts: beware: slighly lossy. Better to wait for Yann's port of the grass5 C version

Added: grass-addons/raster/r.flip/Makefile
===================================================================
--- grass-addons/raster/r.flip/Makefile	                        (rev 0)
+++ grass-addons/raster/r.flip/Makefile	2011-06-20 03:20:08 UTC (rev 46743)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.flip
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/raster/r.flip/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/raster/r.flip/r.flip
===================================================================
--- grass-addons/raster/r.flip/r.flip	                        (rev 0)
+++ grass-addons/raster/r.flip/r.flip	2011-06-20 03:20:08 UTC (rev 46743)
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       r.flip
+# AUTHOR(S):    M. Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      
+# COPYRIGHT:    (C) 2011 Hamish Bowman, and the GRASS Development Team
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+############################################################################
+#
+#  TODO: Yann suggested to port the grass5 C version, it would be good
+#    to replace this with that.  a r.rotate (90deg) would be useful too.
+#  WARNING: this script is a little lossy in precision.
+#
+
+#%Module
+#% description: Flip a raster array's rows.
+#% keywords: raster
+#%End
+#%Option
+#% key: input
+#% type: string
+#% required: yes
+#% key_desc: name
+#% description: Name of input raster map
+#% gisprompt: old,cell,raster
+#%End
+#%Option
+#% key: output
+#% type: string
+#% required: yes
+#% multiple: yes
+#% key_desc: name
+#% description: Name for output raster map
+#% gisprompt: new,cell,raster
+#%End
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+# check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    g.message "awk required, please install awk or gawk first" 
+    exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+#### check if we have tac
+# perhaps try `type -t` instead of `which`, as it is more POSIXy
+if [ -x "`which tac`" ] ; then
+   TAC=tac
+else
+   TAC=awk_tac
+fi
+
+awk_tac()
+{
+   awk '1 { last = NR; line[last] = $0; }
+          END { for (i = last; i > 0; i--) { print line[i]; } }'
+}
+
+# setup temporary file
+TMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMPFILE" ] ; then
+    g.message -e "unable to create temporary files"
+    exit 1
+fi
+# trap ctrl-c so that we can clean up tmp
+cleanup()
+{
+   rm -f "$TMPFILE" "$TMPFILE.body" "$TMPFILE.header"
+}
+trap "cleanup" 2 3 15
+
+eval `r.info -t "$GIS_OPT_INPUT"`
+## mmph this is %f not %g, so not exactly right, but in the neighborhood
+case $datatype in
+   CELL)
+     DP=0
+     TYPE="-i"
+     ;;
+   FCELL)
+     DP=7
+     TYPE="-f"
+     ;;
+   DCELL)
+     DP=15
+     TYPE="-d"
+     ;;
+esac
+
+r.out.ascii in="$GIS_OPT_INPUT" --quiet | head -n 6 > "$TMPFILE.header"
+r.out.ascii in="$GIS_OPT_INPUT" dp="$DP" | tail -n +7 | $TAC > "$TMPFILE.body"
+
+cat "$TMPFILE.header" "$TMPFILE.body" | \
+  r.in.ascii "$TYPE" out="$GIS_OPT_OUTPUT"
+
+cleanup
+
+g.message "Done."
+exit


Property changes on: grass-addons/raster/r.flip/r.flip
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list