[GRASS-SVN] r30140 - in grass-addons: . display display/d.frame.split display/d.region.box display/d.shortcuts imagery imagery/i.points.reproj imagery/i.warp misc misc/utm_which_zone raster raster/r.colors.tools raster/r.game_of_life raster/r.out.gmt raster/r.pack raster/r.terraflow.tools vector vector/v.out.ascii.db vector/v.random.cover

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 14 00:45:55 EST 2008


Author: hamish
Date: 2008-02-14 00:45:55 -0500 (Thu, 14 Feb 2008)
New Revision: 30140

Added:
   grass-addons/display/
   grass-addons/display/d.frame.split/
   grass-addons/display/d.frame.split/d.frame.quarter
   grass-addons/display/d.frame.split/d.frame.split
   grass-addons/display/d.region.box/
   grass-addons/display/d.region.box/d.region.box
   grass-addons/display/d.shortcuts/
   grass-addons/display/d.shortcuts/d.mark
   grass-addons/display/d.shortcuts/d.stations
   grass-addons/display/d.shortcuts/d.varea
   grass-addons/imagery/
   grass-addons/imagery/i.points.reproj/
   grass-addons/imagery/i.points.reproj/i.points.reproj
   grass-addons/imagery/i.warp/
   grass-addons/imagery/i.warp/i.warp61
   grass-addons/misc/
   grass-addons/misc/utm_which_zone/
   grass-addons/misc/utm_which_zone/utm_which_zone_Awk.sh
   grass-addons/misc/utm_which_zone/utm_which_zone_Octave.sh
   grass-addons/raster/
   grass-addons/raster/r.colors.tools/
   grass-addons/raster/r.colors.tools/r.colors.stddev
   grass-addons/raster/r.colors.tools/r.cpt2grass
   grass-addons/raster/r.game_of_life/
   grass-addons/raster/r.game_of_life/r.game_of_life
   grass-addons/raster/r.out.gmt/
   grass-addons/raster/r.out.gmt/r.out.gmt
   grass-addons/raster/r.pack/
   grass-addons/raster/r.pack/r.pack
   grass-addons/raster/r.pack/r.unpack
   grass-addons/raster/r.terraflow.tools/
   grass-addons/raster/r.terraflow.tools/calc_terraflow_dir.m
   grass-addons/raster/r.terraflow.tools/dominant_dir.m
   grass-addons/vector/
   grass-addons/vector/v.out.ascii.db/
   grass-addons/vector/v.out.ascii.db/v.out.ascii.db
   grass-addons/vector/v.random.cover/
   grass-addons/vector/v.random.cover/v.random.cover
Log:
create subdirs; add Hamish's addon scripts

Added: grass-addons/display/d.frame.split/d.frame.quarter
===================================================================
--- grass-addons/display/d.frame.split/d.frame.quarter	                        (rev 0)
+++ grass-addons/display/d.frame.split/d.frame.quarter	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,66 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       d.frame.quarter
+# AUTHOR:       M. Hamish Bowman, Dept. Marine Science, Otago Univeristy,
+#                 New Zealand
+# PURPOSE:      split the display into quarter frames
+#
+# COPYRIGHT:    (c) 2007 Hamish Bowman, and the GRASS Development Team
+#               This program is free software released to the public domain
+#
+#############################################################################
+
+#%Module
+#% description: Split the display into quarters.
+#%End
+#%flag
+#% key: 6
+#% description: Split the display into sixths
+#%end
+
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+# skip parser if no args are given
+if [ "$#" -gt 0 ] ; then
+  if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+  fi
+else
+  GIS_FLAG_6=0
+fi
+
+
+if [ `d.mon -p | cut -f1 -d' '` != "Currently" ] ; then
+   echo "No monitor currently selected for output"
+   exit 1
+fi
+
+d.erase -f
+if [ $? -ne 0 ] ; then
+   echo "Error clearing display monitor"
+   exit 1
+fi
+
+if [ "$GIS_FLAG_6" -eq 0 ] ; then
+   d.frame -c frame=uno at=50,100,0,50
+   d.frame -c frame=dos at=50,100,50,100
+   d.frame -c frame=tres at=0,50,0,50
+   d.frame -c frame=cuatro at=0,50,50,100
+else
+   d.frame -c frame=uno at=66.6667,100,0,50
+   d.frame -c frame=dos at=66.6667,100,50,100
+   d.frame -c frame=tres at=33.3333,66.6667,0,50
+   d.frame -c frame=cuatro at=33.3333,66.6667,50,100
+   d.frame -c frame=cinco at=0,33.3333,0,50
+   d.frame -c frame=seis at=0,33.3333,50,100
+fi
+
+d.frame -s uno
+
+exit 0
+

Added: grass-addons/display/d.frame.split/d.frame.split
===================================================================
--- grass-addons/display/d.frame.split/d.frame.split	                        (rev 0)
+++ grass-addons/display/d.frame.split/d.frame.split	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,173 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       d.frame.split
+# AUTHOR:       M. Hamish Bowman, Dept. Marine Science, Otago Univeristy,
+#                 New Zealand
+# PURPOSE:      split the display into quarter frames, etc
+#
+# COPYRIGHT:    (c) 2007 Hamish Bowman, and the GRASS Development Team
+#               This program is free software released to the public domain
+#
+#############################################################################
+
+#%Module
+#% description: Split the display into subframes.
+#%End
+#%option
+#% key: frames
+#% type: integer
+#% description: Number of subframes
+#% options: 2,4,6,8,9,12,16
+#% answer: 4
+#%end
+#%flag
+#% key: h
+#% description: Split horizontally not vertically
+#%end
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+# skip parser if no args are given
+if [ "$#" -gt 0 ] ; then
+  if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+  fi
+else
+  GIS_OPT_FRAMES=4
+  GIS_FLAG_H=0
+fi
+
+
+if [ `d.mon -p | cut -f1 -d' '` != "Currently" ] ; then
+   echo "No monitor currently selected for output"
+   exit 1
+fi
+
+d.erase -f
+if [ $? -ne 0 ] ; then
+   echo "Error clearing display monitor"
+   exit 1
+fi
+
+
+case "$GIS_OPT_FRAMES" in
+   2) if [ $GIS_FLAG_H -eq 0 ] ; then
+	#split vert
+	d.frame -c frame=uno at=50,100,0,100
+	d.frame -c frame=dos at=0,50,0,100
+      else
+	d.frame -c frame=uno at=0,100,0,50
+	d.frame -c frame=dos at=0,100,50,100
+      fi
+     ;;
+   4) d.frame -c frame=uno at=50,100,0,50
+      d.frame -c frame=dos at=50,100,50,100
+      d.frame -c frame=tres at=0,50,0,50
+      d.frame -c frame=cuatro at=0,50,50,100
+     ;;
+   6) if [ $GIS_FLAG_H -eq 0 ] ; then
+	#split vert
+	d.frame -c frame=uno at=66.6667,100,0,50
+	d.frame -c frame=dos at=66.6667,100,50,100
+	d.frame -c frame=tres at=33.3333,66.6667,0,50
+	d.frame -c frame=cuatro at=33.3333,66.6667,50,100
+	d.frame -c frame=cinco at=0,33.3333,0,50
+	d.frame -c frame=seis at=0,33.3333,50,100
+      else
+	d.frame -c frame=uno at=50,100,0,33.3333
+	d.frame -c frame=dos at=50,100,33.3333,66.6667
+	d.frame -c frame=tres at=50,100,66.6667,100
+	d.frame -c frame=cuatro at=0,50,0,33.3333
+	d.frame -c frame=cinco at=0,50,33.3333,66.6667
+	d.frame -c frame=seis at=0,50,66.6667,100
+      fi
+     ;;
+   8) if [ $GIS_FLAG_H -eq 0 ] ; then
+	#split vert
+	d.frame -c frame=uno at=75,100,0,50
+	d.frame -c frame=dos at=75,100,50,100
+	d.frame -c frame=tres at=50,75,0,50
+	d.frame -c frame=cuatro at=50,75,50,100
+	d.frame -c frame=cinco at=25,50,0,50
+	d.frame -c frame=seis at=25,50,50,100
+	d.frame -c frame=siete at=0,25,0,50
+	d.frame -c frame=ocho at=0,25,50,100
+      else
+	d.frame -c frame=uno at=50,100,0,25
+	d.frame -c frame=dos at=50,100,25,50
+	d.frame -c frame=tres at=50,100,50,75
+	d.frame -c frame=cuatro at=50,100,75,100
+	d.frame -c frame=cinco at=0,50,0,25
+	d.frame -c frame=seis at=0,50,25,50
+	d.frame -c frame=siete at=0,50,50,75
+	d.frame -c frame=ocho at=0,50,75,100
+      fi
+     ;;
+   9) d.frame -c frame=uno at=66.6667,100,0,33.3333
+      d.frame -c frame=dos at=66.6667,100,33.3333,66.6667
+      d.frame -c frame=tres at=66.6667,100,66.6667,100
+      d.frame -c frame=cuatro at=33.3333,66.6667,0,33.3333
+      d.frame -c frame=cinco at=33.3333,66.6667,33.3333,66.6667
+      d.frame -c frame=seis at=33.3333,66.6667,66.6667,100
+      d.frame -c frame=siete at=0,33.3333,0,33.3333
+      d.frame -c frame=ocho at=0,33.3333,33.3333,66.6667
+      d.frame -c frame=nueve at=0,33.3333,66.6667,100
+     ;;
+   12) if [ $GIS_FLAG_H -eq 0 ] ; then
+	#split vert
+	d.frame -c frame=uno at=75,100,0,33.3333
+	d.frame -c frame=dos at=75,100,33.3333,66.6667
+	d.frame -c frame=tres at=75,100,66.6667,100
+	d.frame -c frame=cuatro at=50,75,0,33.3333
+	d.frame -c frame=cinco at=50,75,33.3333,66.6667
+	d.frame -c frame=seis at=50,75,66.6667,100
+	d.frame -c frame=siete at=25,50,0,33.3333
+	d.frame -c frame=ocho at=25,50,33.3333,66.6667
+	d.frame -c frame=nueve at=25,50,66.6667,100
+	d.frame -c frame=diez at=0,25,0,33.3333
+	d.frame -c frame=once at=0,25,33.3333,66.6667
+	d.frame -c frame=doce at=0,25,66.6667,100
+      else
+      	d.frame -c frame=uno at=66.6667,100,0,25
+	d.frame -c frame=dos at=66.6667,100,25,50
+	d.frame -c frame=tres at=66.6667,100,50,75
+	d.frame -c frame=cuatro at=66.6667,100,75,100
+	d.frame -c frame=cinco at=33.3333,66.6667,0,25
+	d.frame -c frame=seis at=33.3333,66.6667,25,50
+	d.frame -c frame=siete at=33.3333,66.6667,50,75
+	d.frame -c frame=ocho at=33.3333,66.6667,75,100
+	d.frame -c frame=nueve at=0,33.3333,0,25
+	d.frame -c frame=diez at=0,33.3333,25,50
+	d.frame -c frame=once at=0,33.3333,50,75
+	d.frame -c frame=doce at=0,33.3333,75,100
+      fi
+     ;;
+   16) d.frame -c frame=uno at=75,100,0,25
+       d.frame -c frame=dos at=75,100,25,50
+       d.frame -c frame=tres at=75,100,50,75
+       d.frame -c frame=cuatro at=75,100,75,100
+       d.frame -c frame=cinco at=50,75,0,25
+       d.frame -c frame=seis at=50,75,25,50
+       d.frame -c frame=siete at=50,75,50,75
+       d.frame -c frame=ocho at=50,75,75,100
+       d.frame -c frame=nueve at=25,50,0,25
+       d.frame -c frame=diez at=25,50,25,50
+       d.frame -c frame=once at=25,50,50,75
+       d.frame -c frame=doce at=25,50,75,100
+       d.frame -c frame=trece at=0,25,0,25
+       d.frame -c frame=catorce at=0,25,25,50
+       d.frame -c frame=quince at=0,25,50,75
+       d.frame -c frame=dieciseis at=0,25,75,100
+     ;;
+esac
+
+
+d.frame -s uno
+
+echo "Use 'd.erase -f' to clear frames from display monitor."  1>&2
+
+exit

Added: grass-addons/display/d.region.box/d.region.box
===================================================================
--- grass-addons/display/d.region.box/d.region.box	                        (rev 0)
+++ grass-addons/display/d.region.box/d.region.box	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,65 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       d.region.box
+# AUTHOR:       Hamish Bowman
+# PURPOSE:      draw a box around current region
+# COPYRIGHT:    (c) 2006 Hamish Bowman, and the GRASS Development Team
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%Module
+#% description: Draws a box around the current region in the display frame
+#% keywords: display
+#%end
+
+#% flag
+#% key: f
+#% description: Non-persistant box (doesn't survive redraw or zoom)
+#%end
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+# skip GUI if no args are given
+if [ $# -gt 0 ] ; then
+  if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+  fi
+else
+  GIS_FLAG_F=0
+fi
+
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    echo "ERROR: unable to create temporary files" 1>&2
+    exit 1
+fi
+
+# another method to try: "d.grid -ng 400"
+
+eval `g.region -g`
+
+# create d.graph command file
+cat << EOF > "$TMP"
+color black
+polyline 
+  $e $s
+  $e $n
+  $w $n
+  $w $s
+  $e $s
+EOF
+
+if [ $GIS_FLAG_F -eq 1 ] ; then
+    d.graph -m < "$TMP"
+else
+    d.graph -m input="$TMP"
+fi
+
+exit $?

Added: grass-addons/display/d.shortcuts/d.mark
===================================================================
--- grass-addons/display/d.shortcuts/d.mark	                        (rev 0)
+++ grass-addons/display/d.shortcuts/d.mark	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,77 @@
+#!/bin/sh
+# d.mark - quickly display site data in a nice way
+#
+# COPYRIGHT:	(c) 2007 by Hamish Bowman
+#
+#	This program is free software under the GNU General Public
+#	License (>=v2). Read the file COPYING that comes with GRASS
+#	for details.
+#
+
+
+#%Module
+#% description: Quickly display a marker on the display monitor
+#%End
+#%option
+#% key: at
+#% type: double
+#% key_desc: x,y
+#% description: Placement coordinates (in percentage, 0,0 is lower left)
+#% required : yes
+#%end
+#%option
+#% key: symbol
+#% type: string
+#% key_desc: name
+#% description: Basic symbol to use
+#% answer: triangle
+#% options: arrow1,arrow2,box,circle,cross1,cross2,diamond,marker,octagon,point,pushpin,star,triangle,x
+#% required : no
+#%end
+#%option
+#% key: color
+#% type: string
+#% description: Symbol outline color
+#% gisprompt: color,grass,color
+#% answer: black
+#% required : no
+#%end
+#%option
+#% key: fcolor
+#% type: string
+#% description: Symbol fill color
+#% gisprompt: color,grass,color
+#% answer: yellow
+#% required : no
+#%end
+#%option
+#% key: size
+#% type: integer
+#% description: Symbol size
+#% answer: 12
+#% required : no
+#%end
+#%flag
+#% key: m
+#% description: Coordinates are given in map units
+#%end
+
+if [ -z $GISBASE ] ; then
+        echo "You have to be in GRASS to use this."
+        exit
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+if [ $GIS_FLAG_M -eq 0 ] ; then
+    MAPUN=""
+else
+    MAPUN="-m"
+fi
+
+COORD=`echo "$GIS_OPT_AT" | tr ',' ' '`
+
+echo "symbol basic/$GIS_OPT_SYMBOL $GIS_OPT_SIZE $COORD $GIS_OPT_COLOR $GIS_OPT_FCOLOR" \
+  | d.graph $MAPUN

Added: grass-addons/display/d.shortcuts/d.stations
===================================================================
--- grass-addons/display/d.shortcuts/d.stations	                        (rev 0)
+++ grass-addons/display/d.shortcuts/d.stations	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,55 @@
+#!/bin/sh
+# d.stations - quickly display site data in a nice way
+#
+# COPYRIGHT:	(c) 2004 by Hamish Bowman
+#
+#	This program is free software under the GNU General Public
+#	License (>=v2). Read the file COPYING that comes with GRASS
+#	for details.
+#
+
+if [ -z $GISBASE ] ; then
+        echo "You have to be in GRASS to use this."
+        exit
+fi
+
+if [ -z "$1" ] ; then
+	echo "USAGE: d.stations sitefile [color]"
+	echo "       make pretty diamond markers for a sites file"
+	exit
+fi
+
+if [ -z $2 ] ; then
+	COLOR=red
+else
+	COLOR=$2
+fi
+
+
+GRASS_VERSION=`g.version | cut -f2 -d' '`
+GRASS_MAJOR_VERSION=`echo $GRASS_VERSION | cut -f1 -d.`
+GRASS_MINOR_VERSION=`echo $GRASS_VERSION | cut -f2 -d.`
+
+if [ $GRASS_MAJOR_VERSION -eq 5  -a $GRASS_MINOR_VERSION -lt 7 ] ; then
+    GRASS_VER=old
+else
+    GRASS_VER=new
+fi
+
+if [ $GRASS_VER = "old" ] ; then
+#	d.sites $1 color=white type=diamond size=6
+#	d.sites $1 color=$COLOR type=diamond size=5
+#        d.sites $1 color=$COLOR type=diamond size=4
+        d.sites $1 color=$COLOR type=diamond size=3
+        d.sites $1 color=$COLOR type=diamond size=2
+        d.sites $1 color=$COLOR type=x size=2
+#        d.sites $1 color=$COLOR type=diamond size=1
+#        d.sites $1 color=$COLOR type=diamond size=0
+#	d.site.labels $1 attr=double xref=right size=7  # color=yellow
+
+else
+    d.vect $1 color=$COLOR fcolor=$COLOR size=6 icon=basic/circle
+#    COLNAME=depth
+#    d.vect $1 display=attr attrcol=$COLNAME lcolor=lcolor=blue xref=center yref=top lsize=9
+fi
+

Added: grass-addons/display/d.shortcuts/d.varea
===================================================================
--- grass-addons/display/d.shortcuts/d.varea	                        (rev 0)
+++ grass-addons/display/d.shortcuts/d.varea	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,40 @@
+#!/bin/sh
+# d.varea - quickly display vector area data in a nice way
+#
+# COPYRIGHT:	(c) 2004 by Hamish Bowman
+#
+#	This program is free software under the GNU General Public
+#	License (>=v2). Read the file COPYING that comes with GRASS
+#	for details.
+#
+
+if [ -z $GISBASE ] ; then
+        echo "You have to be in GRASS to use this."
+        exit
+fi
+
+if [ -z "$1" ] ; then
+	echo "USAGE: d.vearea vectorfile [color]"
+	exit
+fi
+
+if [ -z $2 ] ; then
+	COLOR=225:225:225
+else
+	COLOR=$2
+fi
+
+
+GRASS_VERSION=`g.version | cut -f2 -d' '`
+GRASS_MAJOR_VERSION=`echo $GRASS_VERSION | cut -f1 -d.`
+GRASS_MINOR_VERSION=`echo $GRASS_VERSION | cut -f2 -d.`
+
+if [ $GRASS_MAJOR_VERSION -eq 5  -a $GRASS_MINOR_VERSION -lt 7 ] ; then
+    GRASS_VER=old
+    echo "This needs GRASS 5.7 or newer."
+    exit 1
+else
+    GRASS_VER=new
+fi
+
+d.vect $1 type=area fcolor=$COLOR

Added: grass-addons/imagery/i.points.reproj/i.points.reproj
===================================================================
--- grass-addons/imagery/i.points.reproj/i.points.reproj	                        (rev 0)
+++ grass-addons/imagery/i.points.reproj/i.points.reproj	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,116 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       i.points.reproj
+#
+# AUTHOR:       Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE:      Reproject the target points in an imagery POINTS file
+#               to save a r.proj generation loss later.
+#
+# COPYRIGHT:    (c) 2007 Hamish Bowman, and The GRASS Development Team
+#
+#############################################################################
+#
+# REQUIREMENTS:
+#      -  awk, cs2cs from GDAL/OGR tools
+#
+# run from simple_xy (source) location
+#
+
+#%Module
+#% description: Reproject the target points in an imagery POINTS file.
+#% keywords: imagery, projection, rectification
+#%End
+#%option
+#% key: group
+#% type: string
+#% gisprompt: old,group,group
+#% description: Name of existing imagery group
+#% required: yes
+#%end
+#%option
+#% key: in_proj
+#% type: string
+#% description: Input projection parameters (PROJ.4 style)
+#% required: yes
+### wgs84/ll
+#% answer: +init=epsg:4326
+#%end
+#%option
+#% key: out_proj
+#% type: string
+#% description: Output projection parameters (PROJ.4 style)
+#% required: yes
+### NZTM
+#% answer: +init=epsg:2193
+#%end
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." >&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+fi
+
+#### check for cs2cs
+if [ ! -x "`which cs2cs`" ] ; then
+    echo "ERROR: cs2cs program not found, install it first\
+      http://proj.maptools.org" 1>&2
+    exit 1
+fi
+
+#### check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    echo "ERROR: awk required, please install awk or gawk first" 1>&2
+    exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+
+GROUP=$GIS_OPT_GROUP
+IN_PROJ=$GIS_OPT_IN_PROJ
+OUT_PROJ=$GIS_OPT_OUT_PROJ
+
+eval `g.findfile elem=group/$GROUP file=POINTS | grep '^file='`
+if [ -z "$file" ] ; then
+    echo "ERROR: The group's POINTS file not found, run i.points first" 1>&2
+    exit 1
+fi
+
+POINTSFILE="$file"
+
+#### setup temporary file
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    g.message -e "Unable to create temporary files" 1>&2
+    exit 1
+fi
+
+grep -v '^#\|0$' $POINTSFILE | awk '{print($1 " " $2)}' > "$TMP.xy"
+grep -v '^#\|0$' $POINTSFILE | awk '{print($3 " " $4)}' > "$TMP.ll"
+
+#IN_PROJ="+proj=longlat +towgs84=0.000,0.000,0.000"
+#OUT_PROJ="`g.proj -jf`"
+cs2cs -f %.7f $IN_PROJ +to $OUT_PROJ < "$TMP.ll" | cut -f1 -d' '> "$TMP.nztm"
+
+cat $POINTSFILE | head -n 3 > "$TMP.new_POINTS"
+
+paste -d' ' "$TMP.xy" "$TMP.nztm" | \
+  awk '{printf("%17s %15s %15s %15s    1\n", $1, $2, $3, $4)}' \
+  >> "$TMP.new_POINTS"
+
+NEW_POINTSFILE="$POINTSFILE.`echo "$OUT_PROJ" | cut -f2 -d=`"
+cp "$TMP.new_POINTS" "$NEW_POINTSFILE"
+
+\rm "$TMP"*
+
+echo "New POINTS file saved to <`basename $NEW_POINTSFILE`>." 1>&2
+echo "Remember to rerun i.target and rename POINTS files before running i.rectify." 1>&2
+

Added: grass-addons/imagery/i.warp/i.warp61
===================================================================
--- grass-addons/imagery/i.warp/i.warp61	                        (rev 0)
+++ grass-addons/imagery/i.warp/i.warp61	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,130 @@
+#!/bin/sh
+#
+############################################################################
+#
+# MODULE:       i.warp
+#
+# AUTHOR(S):    Hamish Bowman
+#               Department of Marine Science
+#               Otago University, New Zealand
+#               3 June 2005
+#
+# PURPOSE:      Use GCPs from i.points to run gdalwarp using splines
+#
+# COPYRIGHT:    (c) Hamish Bowman
+#
+#############################################################################
+#
+# REQUIREMENTS:
+#       gdalwarp from the GDAL package.   http://www.gdal.org
+#     xx  GRASS 6.1-cvs newer than 1 June 2005
+#
+
+#%Module
+#%  description: Georectify an image using thin plate splines
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old_file,file,input
+#% description: Name of input image (JPEG, TIFF, etc.)
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new_file,file,output
+#% description: Name for georeferenced and warped GeoTIFF
+#% required : yes
+#%end
+#%option
+#% key: group
+#% type: string
+#% gisprompt: old,group,group
+#% description: Name of imagery group containing GCPs
+#% required : yes
+#%end
+
+if [ -z "$GISBASE" ] ; then
+   echo "You must be in GRASS GIS to run this program." >&2
+   exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+   exec g.parser "$0" "$@"
+fi
+
+#### check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    echo "$PROG: awk required, please install awk or gawk first" 1>&2
+    exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+
+INFILE="$GIS_OPT_input"
+OUTFILE="`basename $GIS_OPT_output .tif`.tif"
+GROUP="$GIS_OPT_group"
+
+if [ ! -e "$INFILE" ] ; then
+    echo "ERROR: unable to read input file." 1>&2
+    exit 1
+fi
+if [ -e "$OUTFILE" ] ; then
+    echo "ERROR: output file already exists." 1>&2
+    exit 1
+fi
+
+
+eval `g.filename elem=group file=${GROUP}/POINTS`
+POINTS_FILE="$file"
+
+if [ ! -e "$POINTS_FILE" ] ; then
+    echo "ERROR: unable to read POINTS file. Run i.points first." 1>&2
+    exit 1
+fi
+
+#### setup temporary file
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    echo "ERROR: unable to create temporary files" 1>&2
+    exit 1
+fi
+
+DIMS="`gdalinfo "$INFILE" | grep '^Lower Right' | cut -f2 -d'(' | \
+    cut -f1 -d')' |  tr ',' ' '`"
+WIDTH="`echo $DIMS | cut -f1 -d' '`"
+HEIGHT="`echo $DIMS | cut -f2 -d' '`"
+
+## BUG: GCPs need to be sorted top to bottom!!  (??????)
+GDAL_GCP="`cat "$POINTS_FILE" | grep -v '^#'| grep -v '0$' | sort -n -r --key=2 | \
+    awk -v hgt=$HEIGHT -v wth=$WIDTH \
+      '{printf("-gcp %.3f %.3f %f %f ", $1, hgt - $2, $3, $4)}'`"
+
+
+echo $GDAL_GCP | sed -e 's/-gcp/\ngcp/g' -e 's/ /\t/g'
+echo
+
+echo "Adding GCPs ..."
+gdal_translate $GDAL_GCP "$INFILE" "$TMP".tif
+
+sleep 1
+echo "Rectifying ..."
+## BUG: outfile name needs to be at least 20 chars long!!
+gdalwarp -tps -rcs -co compress=lzw "$TMP".tif "$OUTFILE"_warp_warp_warp_warp
+#gdalwarp -tps -rcs -co compress=lzw -srcnodata 255 -dstnodata 255 "$TMP".tif "$OUTFILE"_warp_warp_warp_warp
+
+
+sleep 1
+mv "$OUTFILE"_warp_warp_warp_warp "$OUTFILE"
+
+rm -f "$TMP".tif "$TMP"
+
+echo "Done!"
+
+echo ""
+echo "In target location:  r.in.gdal -o input=$OUTFILE output=`basename $OUTFILE .tif`"

Added: grass-addons/misc/utm_which_zone/utm_which_zone_Awk.sh
===================================================================
--- grass-addons/misc/utm_which_zone/utm_which_zone_Awk.sh	                        (rev 0)
+++ grass-addons/misc/utm_which_zone/utm_which_zone_Awk.sh	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# MN
+# calculate UTM zone from LatLong
+# DCA
+# replace octave with awk. 200511
+
+if [ $# -lt 2 ] || [ -z `which awk` ] ; then
+   echo "Requires 'awk' to be installed."
+   echo ""
+   echo "Usage:  (LONG: x LAT: y)"
+   echo "      utm_which_zone.sh LONG LAT"
+   exit 1
+fi
+
+LONG=$1
+LAT=$2
+
+#Original doc from octave version:
+# utm_zone.m   Matlab (or gpl'd Octave)
+# Calc UTM zone from Lat/Lon position.
+#
+#  (c) Hamish Bowman, Otago University, New Zealand  (mid 2002 sometime)
+#  This program is free software under the GPL (>=v2)
+#   for license deails, see  http://www.gnu.org/copyleft/gpl.html
+#
+# UTM is based on a Transverse Mercator (conformal, cylindrical) projection.
+# 60 zones. Width 6deg lon, numbered 1 to 60, starting at 180deg lon (west).
+#  8deg lat strips, C to X northwards, omitting I and O, beginning at 80deg
+#  south.
+
+awk -v lat=$LAT -v long=$LONG '
+BEGIN{
+  strips="CDEFGHJKLMNPQRSTUVWX";
+  zone = ceil( (long+180)/6.0 );
+  strip = substr( strips, ceil((lat+80)/8.0), 1 );
+  print "LatLon = " lat " " long;
+  print "Zone = " zone;
+  print "Strip = " strip;
+}
+function ceil(x){
+  if ( x <= 0 ){
+    return int(x);
+  }else{
+    if ( x == int(x) ){
+      return x;
+    }else{
+      return int(x)+1;
+    }
+  }
+}
+'
+

Added: grass-addons/misc/utm_which_zone/utm_which_zone_Octave.sh
===================================================================
--- grass-addons/misc/utm_which_zone/utm_which_zone_Octave.sh	                        (rev 0)
+++ grass-addons/misc/utm_which_zone/utm_which_zone_Octave.sh	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# MN
+#calculate UTM zone from LatLong
+
+if [ $# -lt 2 ] || [ -z `which octave` ] ; then
+   echo "Requires 'octave' to be installed."
+   echo ""
+   echo "Usage:  (LONG: x LAT: y)"
+   echo "      utm_which_zone.sh LONG LAT"
+   exit 1
+fi
+
+LONG=$1
+LAT=$2
+
+echo "
+% utm_zone.m   Matlab (or gpl'd Octave)
+% Calc UTM zone from Lat/Lon position.
+%
+%  (c) Hamish Bowman, Otago University, New Zealand  (mid 2002 sometime)
+%  This program is free software under the GPL (>=v2)
+%   for license deails, see  http://www.gnu.org/copyleft/gpl.html
+%
+% UTM is based on a Transverse Mercator (conformal, cylindrical) projection.
+% 60 zones. Width 6deg lon, numbered 1 to 60, starting at 180deg lon (west).
+%  8deg lat strips, C to X northwards, omitting I and O, beginning at 80deg
+%  south.
+%
+% West is negative, south is negative
+
+if (exist('LatLon') ~= 1)
+        LatLon = [ $LAT $LONG ]
+end
+
+Strips = [ 'C' 'D' 'E' 'F' 'G' 'H' 'J' 'K' 'L' 'M' ...
+           'N' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X'];
+
+Zone = ceil((LatLon(2)+180)/6)
+Strip = Strips(ceil((LatLon(1)+80)/8))
+" | octave -q
+

Added: grass-addons/raster/r.colors.tools/r.colors.stddev
===================================================================
--- grass-addons/raster/r.colors.tools/r.colors.stddev	                        (rev 0)
+++ grass-addons/raster/r.colors.tools/r.colors.stddev	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,145 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       r.colors.stddev
+# AUTHOR:       M. Hamish Bowman, Dept. Marine Science, Otago Univeristy,
+#                 New Zealand
+# PURPOSE:      
+#
+# COPYRIGHT:    (c) 2007 Hamish Bowman, and the GRASS Development Team
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%Module
+#% description: Set color rules based on stddev from a map's mean value.
+#% keywords: raster
+#%End
+#% option
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of input raster map 
+#% required: yes
+#%end
+#%flag
+#% key: b
+#% description: Color using standard deviation bands
+#%end
+#%flag
+#% key: z
+#% description: Force center at zero
+#%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
+
+
+eval `r.univar -g "$GIS_OPT_INPUT"`
+# $? is result of the eval not r.univar (???)
+#if [ $? -ne 0 ] ; then
+#   echo "ERROR: Problem running r.univar" 1>&2
+#   exit 1
+#fi
+
+
+if [ $GIS_FLAG_Z -eq 0 ] ; then
+
+   MEAN_MINUS_2STDEV=`echo "$mean $stddev" | awk '{print $1 - 2*$2}'`
+   MEAN_PLUS_2STDEV=`echo "$mean $stddev" | awk '{print $1 + 2*$2}'`
+
+   if [ $GIS_FLAG_B -eq 0 ] ; then
+     # smooth free floating blue/white/red
+     r.colors "$GIS_OPT_INPUT" color=rules << EOF
+       0% blue
+       $MEAN_MINUS_2STDEV blue
+       $mean white
+       $MEAN_PLUS_2STDEV red
+       100% red
+EOF
+   else
+     # banded free floating  black/red/yellow/green/yellow/red/black
+     MEAN_MINUS_1STDEV=`echo "$mean $stddev" | awk '{print $1 - $2}'`
+     MEAN_MINUS_3STDEV=`echo "$mean $stddev" | awk '{print $1 - 3*$2}'`
+     MEAN_PLUS_1STDEV=`echo "$mean $stddev" | awk '{print $1 + $2}'`
+     MEAN_PLUS_3STDEV=`echo "$mean $stddev" | awk '{print $1 + 3*$2}'`
+
+     # reclass with labels only works for category (integer) based maps
+     #r.reclass input="$GIS_OPT_INPUT" output="${GIS_OPT_INPUT}.stdevs" << EOF
+
+     # >3 S.D. outliers colored black so they show up in d.histogram w/ white background
+     r.colors "$GIS_OPT_INPUT" color=rules << EOF
+       0% black
+       $MEAN_MINUS_3STDEV black
+       $MEAN_MINUS_3STDEV red
+       $MEAN_MINUS_2STDEV red
+       $MEAN_MINUS_2STDEV yellow
+       $MEAN_MINUS_1STDEV yellow
+       $MEAN_MINUS_1STDEV green
+       $MEAN_PLUS_1STDEV green
+       $MEAN_PLUS_1STDEV yellow
+       $MEAN_PLUS_2STDEV yellow
+       $MEAN_PLUS_2STDEV red
+       $MEAN_PLUS_3STDEV red
+       $MEAN_PLUS_3STDEV black
+       100% black
+EOF
+   fi
+
+
+else 
+   # data centered on 0  (e.g. map of deviations)
+   r.mapcalc "r_col_stdev_abs_$$ = abs($GIS_OPT_INPUT)"
+   eval `r.info -r "r_col_stdev_abs_$$"`
+
+   # current r.univar truncates percentage to the base integer
+   STDDEV2=`r.univar -eg "r_col_stdev_abs_$$" perc=95.4500 | grep ^percentile | cut -f2 -d=`
+
+   if [ $GIS_FLAG_B -eq 0 ] ; then
+     # zero centered smooth blue/white/red
+     r.colors "$GIS_OPT_INPUT" color=rules << EOF
+       -$max blue
+       -$STDDEV2 blue
+       0 white
+       $STDDEV2 red
+       $max red
+EOF
+   else
+     # zero centered banded  black/red/yellow/green/yellow/red/black
+
+     # current r.univar truncates percentage to the base integer
+     STDDEV1=`r.univar -eg "r_col_stdev_abs_$$" perc=68.2689 | grep ^percentile | cut -f2 -d=`
+     STDDEV3=`r.univar -eg "r_col_stdev_abs_$$" perc=99.7300 | grep ^percentile | cut -f2 -d=`
+
+     # >3 S.D. outliers colored black so they show up in d.histogram w/ white background
+     r.colors "$GIS_OPT_INPUT" color=rules << EOF
+       -$max black
+       -$STDDEV3 black
+       -$STDDEV3 red
+       -$STDDEV2 red
+       -$STDDEV2 yellow
+       -$STDDEV1 yellow
+       -$STDDEV1 green
+       $STDDEV1 green
+       $STDDEV1 yellow
+       $STDDEV2 yellow
+       $STDDEV2 red
+       $STDDEV3 red
+       $STDDEV3 black
+       $max black
+EOF
+   fi
+
+   g.remove rast="r_col_stdev_abs_$$" --quiet
+fi
+

Added: grass-addons/raster/r.colors.tools/r.cpt2grass
===================================================================
--- grass-addons/raster/r.colors.tools/r.cpt2grass	                        (rev 0)
+++ grass-addons/raster/r.colors.tools/r.cpt2grass	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,176 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       r.cpt2grass
+# AUTHOR(S):    M. Hamish Bowman, Otago University, New Zealand
+# PURPOSE:      Convert a GMT color table into a GRASS color rules file
+# COPYRIGHT:    (c) 2007 by Hamish Bowman, and the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+# SEE ALSO:     GMT: The Generic Mapping Tools 
+#                 http://gmt.soest.hawaii.edu
+#		  http://gmt.soest.hawaii.edu/gmt/doc/html/GMT_Docs/node58.html
+#
+# REQUIRES:	awk
+#############################################################################
+
+#%Module
+#% description: Convert or apply a GMT color table to a GRASS raster map
+#%End
+#%option
+#% key: input
+#% gisprompt: old_file,file,file
+#% type: string
+#% description: Name of input GMT color table (.cpt file)
+#% required : yes
+#%END
+#%option
+#% key: map
+#% gisprompt: old,cell,raster
+#% type: string
+#% description: Raster map to apply it to
+#% required : no
+#%END
+#%option
+#% key: output
+#% gisprompt: new_file,file,file
+#% type: string
+#% description: Name for new rules file, or "-" for stdout
+#% required : no
+#%END
+#%flag
+#% key: s
+#% description: Stretch color scale to match map data extent
+#%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
+
+if [ -z "$GIS_OPT_MAP" ] && [ -z "$GIS_OPT_OUTPUT" ] ; then
+    echo "ERROR: Nothing to do, please select either the map or output option" 1>&2
+    exit 1
+fi
+
+if [ ! -e "$GIS_OPT_INPUT" ] ; then
+    echo "ERROR: Input file [$GIS_OPT_INPUT] not found." 1>&2
+    exit 1
+fi
+
+if [ `grep '^# COLOR_MODEL' "$GIS_OPT_INPUT" | cut -f2 -d= | grep -c 'HSV\|CMYK'` -gt 0 ] ; then
+    echo "ERROR: Only the RGB color model is supported" 1>&2
+    exit 1
+fi
+
+
+# check if we have awk
+AWK=`which awk`
+if [ "$AWK" = "" ] ; then
+    echo "ERROR: awk required, please install awk/gawk first" 1>&2
+    exit 1
+fi
+
+# setting environment, so that awk works properly in all languages
+unset LC_ALL
+export LC_NUMERIC=C
+
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "${TMP}" ] ; then
+    echo "ERROR: Unable to create temporary files" 1>&2
+    exit 1
+fi
+
+
+
+# B background is for values less than the first color rule, F foreground is for greater.
+#  in GRASS we just consider that to be null, although we could define a color rule
+#  max<->near infinity to be solidly that color. ??
+# skip labels for now
+
+echo "# GMT color map created with r.cpt2grass" > "$TMP"
+echo "#  from [$GIS_OPT_INPUT] by $USER at `date`" >> "$TMP"
+grep '^#' "$GIS_OPT_INPUT" >> "$TMP"
+
+# null value color
+grep '^N' "$GIS_OPT_INPUT" | \
+  awk '{printf("nv %d:%d:%d\n", $2, $3, $4)}' >> "$TMP"
+
+
+# do it in an awk script:
+#if ^#, print
+#if 8 nums
+#if N nv
+
+if [ $GIS_FLAG_S -eq 0 ] ; then
+  # the data
+  grep '^[0-9.-]' "$GIS_OPT_INPUT" | \
+    awk '{printf("%s %d:%d:%d\n%s %d:%d:%d\n", $1, $2, $3, $4, $5, $6, $7, $8)}' >> "$TMP"
+else
+  # strech to fit data
+
+  CPT_MIN=`grep -v '^[#FBN]' "$GIS_OPT_INPUT" | awk '{print $1}' | sort -n | head -n 1`
+  CPT_MAX=`grep -v '^[#FBN]' "$GIS_OPT_INPUT" | awk '{print $5}' | sort -n | tail -n 1`
+
+#  N_RULE_ROWS=`grep -cv '^[#FBN]' "$GIS_OPT_INPUT"`
+#  N_RULES=`echo "$N_RULE_ROWS" | awk '{print $1 + 1}'`
+
+  RANGE=`echo "$CPT_MIN $CPT_MAX" | awk '{print $2 - $1}'`  
+
+# DEBUG:
+#echo "RANGE=$RANGE   Cmin=$CPT_MIN  Cmax=$CPT_MAX"
+
+  while read LINE ; do
+     unset LINE_MIN LINE_MAX PERCENT_MIN PERCENT_MAX
+     if [ `echo "$LINE" | grep -c '^[#FBN]'` -ne 0 ] ; then
+       continue
+     fi
+
+     LINE_MIN=`echo "$LINE" | awk '{print $1}'`
+     LINE_MAX=`echo "$LINE" | awk '{print $5}'`
+
+     PERCENT_MIN=`echo "$LINE_MIN" | awk -v RANGE="$RANGE" -v CMAX="$CPT_MAX" \
+        '{print 100 * (RANGE - (CMAX - $1)) / RANGE }'`
+     PERCENT_MAX=`echo "$LINE_MAX" | awk -v RANGE="$RANGE" -v CMAX="$CPT_MAX" \
+        '{print 100 * (RANGE - (CMAX - $1)) / RANGE }'`
+
+     echo "$LINE" | awk -v PMIN="$PERCENT_MIN" -v PMAX="$PERCENT_MAX" \
+        '{printf("%s%% %d:%d:%d\n%s%% %d:%d:%d\n", PMIN, $2, $3, $4, PMAX, $6, $7, $8)}' >> "$TMP"
+
+# DEBUG:
+#echo "LINE: [$LINE]"
+#echo "  lmin=$LINE_MIN  lmax=$LINE_MAX  pmin=$PERCENT_MIN  pmax=$PERCENT_MAX "
+
+  done < "$GIS_OPT_INPUT"
+fi
+
+uniq "$TMP" "${TMP}.u"
+
+if [ -n "$GIS_OPT_MAP" ] ; then
+   if [ `echo "$GRASS_VERSION" | cut -f1,2 -d.` = "6.2" ] ; then
+     # 6.2's rules= doesn't take a filename
+     r.colors map="$GIS_OPT_MAP" color=rules < "${TMP}.u"
+   else
+     # assume 6.3 or newer
+     r.colors map="$GIS_OPT_MAP" rules="${TMP}.u"
+   fi
+fi
+
+if [ -n "$GIS_OPT_OUTPUT" ] ; then
+   if [ "$GIS_OPT_OUTPUT" = "-" ] ; then
+      cat "${TMP}.u"
+   else
+      cp "${TMP}.u" "$GIS_OPT_OUTPUT"
+   fi
+fi
+
+\rm "$TMP" "${TMP}.u"

Added: grass-addons/raster/r.game_of_life/r.game_of_life
===================================================================
--- grass-addons/raster/r.game_of_life/r.game_of_life	                        (rev 0)
+++ grass-addons/raster/r.game_of_life/r.game_of_life	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,220 @@
+#!/bin/bash
+############################################################################
+#
+# MODULE:      r.game_of_life
+#
+# AUTHOR(S):   Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE:     Raster demo: Conway's game of life in 2D or 3D raster with options
+#		to try Thompson's HighLife version and a couple GRASS exclusive
+#		flavours. (aka interesting mistakes)
+#
+# COPYRIGHT:   Script (c) 2007 Hamish Bowman, and the GRASS Development Team
+#	       This program is free software under the GNU General Public
+#	       License (>=v2). Read the file COPYING that comes with GRASS
+#	       for details.
+#
+#############################################################################
+#
+#rules for classic Conway's version:  (taken from Wikipedia entry)
+# 1. Any live cell with fewer than two live neighbours dies, as if by loneliness.
+# 2. Any live cell with more than three live neighbours dies, as if by overcrowding.
+# 3. Any live cell with two or three live neighbours lives, unchanged, to the next generation.
+# 4. Any dead cell with exactly three live neighbours comes to life.
+#
+# The rules for Thompson's HighLife version are the same, but six
+#  live neighbors around a dead cell and the cell comes to life
+#
+# mod 4 is live hard, die hard
+# mod 6 is gregarious lifestyle
+#
+# 3D runs "gregarious lifestyle", displays an xganim movie; creates an
+#    MPEG-1 animation; and finally constructs a 3D raster block, then
+#    loads that block in NVIZ. It's up to the user to create NVIZ isosurfaces
+#    and cutting planes (at eg 0.9) -- I can't script that.
+#
+
+#%Module
+#% description: Conway's game of life in 2D or 3D raster
+#% keywords: cellular automata, game of life, demo
+#%end
+#%option
+#% key: type
+#% type: string
+#% description: Kind of life you want to live
+#% options: 2d_life,2d_highlife,2d_life_mod4,2d_life_mod6,3d_life
+#% answer: 2d_life
+#% required : yes
+#%end
+#%option
+#% key: size
+#% type: integer
+#% description: Size of computational box
+#% answer: 256
+#% required : no
+#%end
+
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." >&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+cleanup()
+{
+   g.remove rast=count.$PREV_IT
+   echo "User break!" 1>&2
+   exit 1
+}
+
+#### trap ctrl-c so that we can clean up tmp
+trap 'cleanup' 2 3 15
+
+
+BOXSIZE="$GIS_OPT_SIZE"
+
+GRASS_WIDTH=$((BOXSIZE * 2))
+GRASS_HEIGHT=$((BOXSIZE * 2))
+export GRASS_WIDTH GRASS_HEIGHT
+
+
+case "$GIS_OPT_TYPE" in
+    2d_life)
+        # Conway's original version
+       RULES="if( count.\$PREV_IT < 2, 0, \
+	 if( count.\$PREV_IT > 3, 0, \
+	 if( count.\$PREV_IT == 2, life.\$PREV_IT, \
+	 if( count.\$PREV_IT == 3, 1, -99 ) ) ) )"
+       ;;
+    2d_highlife)
+        # Thompson's HighLife version
+       RULES="if( count.\$PREV_IT < 2, 0, \
+	 if( count.\$PREV_IT > 3 && life.\$PREV_IT != 0, 0, \
+	 if( count.\$PREV_IT == 2, life.\$PREV_IT, \
+	 if( count.\$PREV_IT == 3 || count.\$PREV_IT == 6, 1, 0 ) ) ) )"
+       ;;
+    2d_life_mod4)
+       # Life Mod 4: Live hard, Die hard
+       RULES="if( count.\$PREV_IT < 3, 0, \
+         if( count.\$PREV_IT > 4, 0, \
+         if( count.\$PREV_IT == 4, life.\$PREV_IT, \
+         if( count.\$PREV_IT == 3, 1, -99 ) ) ) )"
+       ;;
+    2d_life_mod6 | 3d_life)
+       # Life Mod 6: Gregarious lifestyle
+       RULES="if( count.\$PREV_IT < 2, 0, \
+	 if( count.\$PREV_IT > 3 && count.\$PREV_IT != 6, 0, \
+	 if( count.\$PREV_IT == 2, life.\$PREV_IT, \
+	 if( count.\$PREV_IT == 3 || count.\$PREV_IT == 6, 1, \
+	 -99 ) ) ) )"
+       ;;
+esac
+
+
+########## do it ###########
+
+d.mon x0
+d.font FreeSans
+
+g.region n=$BOXSIZE s=0 w=0 e=$BOXSIZE res=1
+
+
+if [ `g.mlist -r patt="life\.\|count\." | grep -vc '^$'` -gt 0 ] ; then
+   echo "ERROR: Please remove the old raster maps from a past life first:" 1>&2
+   g.mlist -r rast patt='life\.\|count\.'
+   exit 1
+fi
+
+GRASS_VERBOSE=0
+export GRASS_VERBOSE
+REMOVE=1
+
+if [ $GIS_OPT_TYPE = "3d_life" ] ; then
+   g.findfile elem=grid3 file=3d_life > /dev/null
+   if [ $? -eq 0 ] ; then
+      echo "ERROR: please remove the old 3D raster maps from a past life first:" 1>&2
+      g.mlist rast3d patt=3d_life
+      exit 1
+   fi
+
+   # hardcoded to 256 iterations currently, 
+   #g.region t=$BOXSIZE b=0 res3=1
+   g.region t=256 b=0 res3=1
+
+   # keep the 2d slices
+   REMOVE=0
+fi
+
+
+# Create random surface for seed
+#
+## -i flag is new for grass 6.3-cvs
+##r.surf.random -i out=life.000 min=0 max=2  # creates 0/1 map not 0-2!
+#
+# rand(int,int) has a problem being non-random for powers of 2
+#r.mapcalc "life.000 = rand(0,2)"   #creates a 0/1 map
+r.mapcalc "life.000 = int(rand(0.0,1.0)+0.5)"
+
+PREV_IT=000
+
+
+#for i in `seq 1 $((BOXSIZE -1))` ; do
+for i in `seq 1 255` ; do
+   CURR_IT=`echo $i | awk '{printf("%.3d", $1)}'`
+
+   r.neighbors method=sum size=3 in="life.$PREV_IT" out="count.$PREV_IT"
+
+   eval "r.mapcalc \"life.$CURR_IT = $RULES\""
+
+   d.rast "life.$CURR_IT"
+   echo $CURR_IT | d.text color=black
+
+   if [ $REMOVE -eq 1 ] ; then
+      g.remove rast="count.$PREV_IT,life.$PREV_IT"
+   fi
+
+   PREV_IT=$CURR_IT
+   i=`expr $i + 1`
+
+done
+
+
+#### 3d family tree and visualization demos ####
+# Consider time to be the third dimension if you like
+if [ $GIS_OPT_TYPE = "3d_life" ] ; then
+   # last count
+   r.neighbors method=sum in="life.$PREV_IT" out="count.$PREV_IT"
+
+   # construct 3D block
+   LIFE_MAPS=`g.mlist rast pat=life.* sep=,`
+   COUNT_MAPS=`g.mlist rast pat=count.* sep=,`
+   echo "Constructing 3D raster block ..." 1>&2
+   r.to.rast3 in="$LIFE_MAPS" out=3d_life
+
+   # movies
+   echo 1>&2
+   echo "Running 'xganim' map animator ..." 1>&2
+   xganim view1="$LIFE_MAPS" view2="$COUNT_MAPS"
+
+   echo "Constructing MPEG-1 movie ..." 1>&2
+   r.out.mpeg -qc view1="$LIFE_MAPS" view2="$COUNT_MAPS" out=life.mpg qual=5
+   if [ $? -eq 0 ] ; then
+      echo "  'life.mpg' created." 1>&2
+   fi
+
+   g.mremove -f -r rast="life\.*\|count\.*"
+
+   # view in NVIZ
+   echo 1>&2
+   echo "Opening 3D raster block with NVIZ ..." 1>&2
+   echo "  (set viewing height to $((BOXSIZE * 2)) then add isosurfaces" 1>&2
+   echo "   and cutting planes from the Volumes panel)" 1>&2
+   nviz volume=3d_life
+fi
+
+
+exit

Added: grass-addons/raster/r.out.gmt/r.out.gmt
===================================================================
--- grass-addons/raster/r.out.gmt/r.out.gmt	                        (rev 0)
+++ grass-addons/raster/r.out.gmt/r.out.gmt	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,261 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       r.out.gmt
+#
+# AUTHOR(S):    M. Hamish Bowman, Otago University, New Zealand
+#                heavily based on tutorial by Dylan Beaudette, UC Davis
+#
+# PURPOSE:      Output a GRASS raster to a GMT gridfile and color table 
+#
+# COPYRIGHT:    (c) 2005 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
+#               for details.
+#
+# REQUIRES:     GMT: The Generic Mapping Tools 
+#                 http://gmt.soest.hawaii.edu
+#               awk
+#
+#############################################################################
+#
+# TODO: use GMT's xyz2grd to make grid files? see raster/r.out.bin/README
+#       then you can do DCELL output.
+#
+#   xyz2grd -ZTLi  for CELL
+#   xyz2grd -ZTLf  for FCELL
+#   xyz2grd -ZTLd  for DCELL
+#
+#  and the -F may be quite important: it forces pixel registration 
+#  (the default is grid registration). I am always confused by this, 
+#  maybe grid registration is correct?
+#  
+# Dylan's tutorial: http://169.237.35.250/~dylan/grass_user_group/map1.html
+#
+
+
+#%Module
+#% description: Exports a GRASS raster map into a GMT grid file and color table
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Name of input raster map
+#% required : yes
+#%END
+#%option
+#% key: output
+#% type: string
+#% description: Base name of output files (taken from input map if not given)
+#% required : no
+#%END
+#%flag
+#% key: p
+#% description: Display suggested GMT PostScript creation commands
+#%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
+AWK=`which awk`
+if [ "$AWK" = "" ] ; then
+    echo "$PROG: awk required, please install awk/gawk first" 1>&2
+    exit 1
+fi
+
+# setting environment, so that awk works properly in all languages
+unset LC_ALL
+export LC_NUMERIC=C
+
+
+MAP_NAME="$GIS_OPT_input"
+
+if [ -z "$GIS_OPT_output" ] ; then
+    OUT_BASE="$GIS_OPT_input"
+else
+    OUT_BASE="$GIS_OPT_output"
+fi
+
+OUTPUT_GRD="${OUT_BASE}.grd"
+OUTPUT_CPT="${OUT_BASE}.cpt"
+OUTPUT_PS="${OUT_BASE}.ps"
+
+# what to do in case of user break:
+exitprocedure()
+{
+    echo "User break!" 1>&2
+    cleanup
+    exit 1
+}
+# shell check for user break (signal list: trap -l)
+trap "exitprocedure" 2 3 15
+
+cleanup()
+{
+    if [ "$MAP_TYPE" = "DCELL" ] ; then
+	g.remove tmp_gmt_$$ > /dev/null
+    fi
+}
+
+MAP_TYPE=`r.info -t "$MAP_NAME" | cut -f2 -d'='`
+
+case "$MAP_TYPE" in
+    CELL)
+	MAP_TAG="=2" ;;
+    FCELL)
+	MAP_TAG="=1" ;;
+    DCELL)
+	MAP_TAG="=1"
+	echo "WARNING: Converting from double precision to floating point map" 1>&2
+	r.mapcalc "tmp_gmt_$$=float($MAP_NAME)"
+	MAP_NAME=tmp_gmt_$$
+	;;
+esac
+
+r.out.bin -h input="$MAP_NAME" output="$OUTPUT_GRD" 
+if [ $? -ne 0 ] ; then
+  echo "ERROR: creating binary grid file" 1>&2
+  cleanup
+  exit 1
+fi
+
+# get our geographic extents
+eval `g.region -g`
+ns_extent=`g.region -e | grep south | cut -f2 -d: | sed -e 's=^ =='`
+ew_extent=`g.region -e | grep west | cut -f2 -d: | sed -e 's=^ =='`
+
+# preserve aspect ratio from UTM E,N coordinates:
+aspect_ratio=`echo $ns_extent $ew_extent | awk '{printf("%f", $1 / $2)}'`
+
+# setup the map width in inches
+# this is going to affect how much information can be placed in the margins of the paper.
+# commonly a printer will enforce a .25" margin...
+map_width=7
+
+# calculate the map length based on the original aspect ratio
+map_length=`echo $map_width $aspect_ratio | awk '{printf("%f", $1 * $2)}'`
+
+# calculate the y location (in paper units) for the field sheet title
+field_sheet_title_y=`echo $map_length | awk '{printf("%f", $1 + 0.33)}'`
+
+# compile the projection string, with width/length variables
+#   linear projection, width inches / length inches
+projection_string="X${map_width}i/${map_length}i"
+
+# setup the X,Y offset from the bottom left corner, in inches
+# might need to play around with these so that none of the image is cropped by the printer
+#  x_offset=".25i"    
+x_offset="c"	#have GMT horizontally center the map
+y_offset="0.7i"
+
+# compute the scale in meters
+# 39.369 inch/meter
+#  (round to a whole number of some sort?)
+scale=`echo $ew_extent $map_width | awk '{printf("%d", ($1 * 39.369) / $2)}'`
+
+
+# compute default grid ticks
+# default units are meters
+if [ `echo $aspect_ratio | cut -f1 -d'.'` -ge 1 ] ; then
+    MAX_EXTENT=$ns_extent
+else
+    MAX_EXTENT=$ew_extent
+fi
+# try to figure out something useful  (how to get awk to do log10()??)
+tic_interval=`echo $MAX_EXTENT | awk '{printf("%d", int(($1/60)/100)*100 )}'`
+annotated_tic_interval=`expr $tic_interval '*' 10`
+
+# setup the comment at the bottom of the map
+map_comment="1:$scale"
+
+
+
+# create cpt color table from raster's colr file
+eval `g.findfile elem=colr file="$MAP_NAME" | grep "^file="`
+COLR_FILE="$file"
+
+echo "#" > "$OUTPUT_CPT"
+echo "# GMT colormap created by the `g.version` r.out.gmt script" >> "$OUTPUT_CPT"
+echo "# from base map [$MAP_NAME]" >> "$OUTPUT_CPT"
+echo "# created by ${USER}@${HOSTNAME} at `date`" >> "$OUTPUT_CPT"
+echo "#" >> "$OUTPUT_CPT"
+echo "# COLOR_MODEL = RGB" >> "$OUTPUT_CPT"
+
+for line in `cat "$COLR_FILE" | tail -n+2 | grep -v "^nv" | tr ' ' '|'` ; do
+    C_BEGIN="`echo "$line" | cut -f1 -d'|'`"
+    C_END="`echo "$line" | cut -f2 -d'|'`"
+
+    C_BEGIN="`echo "$line" | cut -f1 -d'|'`"
+    C_END="`echo "$line" | cut -f2 -d'|'`"
+
+    # translate 1 color value into 3
+    if [ "`echo "$C_BEGIN" | tr ':' '\n' | wc -l`" -eq 2 ] ; then
+	RULE_CAT="`echo "$C_BEGIN" | cut -f1 -d:`"
+	RULE_COLOR="`echo "$C_BEGIN" | cut -f2 -d:`"
+	C_BEGIN="${RULE_CAT}:${RULE_COLOR}:${RULE_COLOR}:${RULE_COLOR}"
+    fi
+    if [ "`echo "$C_END" | tr ':' '\n' | wc -l`" -eq 2 ] ; then
+	RULE_CAT="`echo "$C_END" | cut -f1 -d:`"
+	RULE_COLOR="`echo "$C_END" | cut -f2 -d:`"
+	C_END="${RULE_CAT}:${RULE_COLOR}:${RULE_COLOR}:${RULE_COLOR}"
+    fi     
+
+    C_STRING="${C_BEGIN}:${C_END}"
+    echo "$C_STRING" | tr ':' '\t' >> "$OUTPUT_CPT"
+done
+# copy color of null value, if any
+C_NULL="`grep "^nv" "$COLR_FILE" | cut -f2 -d':'`"
+if [ -n "$C_NULL" ] ; then
+    if [ "`echo "$C_NULL" | tr ':' '\n' | wc -l`" -eq 1 ] ; then
+	C_STRING="N:${C_NULL}:${C_NULL}:${C_NULL}"
+    else
+	C_STRING="N:${C_NULL}"
+    fi
+    
+    echo "$C_STRING" | tr ':' '\t' >> "$OUTPUT_CPT"
+fi
+
+
+# show suggested PostScript creation commands
+if [ $GIS_FLAG_p -eq 1 ] ; then
+    echo "Suggested GMT PostScript creation commands follow:" 1>&2
+    echo "==================================================" 1>&2
+    echo 1>&2
+    # setup basemap
+    echo "psbasemap -J$projection_string -R${w}/${e}/${s}/${n} \\
+   -Bpf${tic_interval}a${annotated_tic_interval}:\"Easting (m)\":/f${tic_interval}a${annotated_tic_interval}:\"Northing (m)\"::.\"$OUT_BASE\":WeSn \\
+   -X$x_offset -Y$y_offset -U\"scale $map_comment\" -P -K -V > $OUTPUT_PS"
+
+    echo 1>&2
+    # render the grid with the translated color palette
+    # note that we append a =2 after the grd filename- this instructs GMT to read it as an INT GRD
+    # -J inherit the projection information from previous declaration
+       # ?? "-J" on its own doesn't work ?? GMT Debian/Sarge Version: 3.4.4-1
+    # -R inherit the region information from previous declaration (important when regions of grd files do not match!!)
+    # -K allows for further PS additions later
+    # -O uses preset plotting grid
+    echo grdimage "${OUTPUT_GRD}${MAP_TAG} -C${OUTPUT_CPT} -J$projection_string \\
+   -R -K -O -V >> $OUTPUT_PS"
+
+    echo 1>&2
+    echo "==================================================" 1>&2
+fi
+
+
+cleanup
+
+echo "`basename $0` complete." 1>&2
+
+exit 0

Added: grass-addons/raster/r.pack/r.pack
===================================================================
--- grass-addons/raster/r.pack/r.pack	                        (rev 0)
+++ grass-addons/raster/r.pack/r.pack	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,88 @@
+#!/bin/sh
+#  r.pack   --  pack up a raster map:
+#     r.out.mat file + support files => gzip
+#
+#   (c) 2004 GRASS Development Team
+#   AUTHOR: Hamish Bowman, Otago University, New Zealand
+#
+#   This program is free software under the GNU General Public
+#   License (>=v2). Read the file COPYING that comes with GRASS
+#   for details.
+#
+
+#%Module
+#%  description: Packs up a raster map and support files for copying
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Name of an existing raster map
+#% required : yes
+#%end
+
+if [ -z "$GISBASE" ] ; then
+   echo "You must be in GRASS GIS to run this program." >&2
+   exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+fi
+
+# check for tar  (is there a better way?)
+if [ -z "`which tar`" ] ; then
+   echo "ERROR: tar must be installed to use this program."
+   exit 1
+fi
+# check for gzip
+if [ -z "`which gzip`" ] ; then
+   echo "ERROR: gzip must be installed to use this program."
+   exit 1
+fi
+
+
+# create temporary directory to hold bits
+TMP_DIR="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP_DIR" ] ; then
+   echo "ERROR: unable to create temporary files" 1>&2
+   exit 1
+fi
+rm -f "$TMP_DIR"
+mkdir "$TMP_DIR"
+if [ ! -d "$TMP_DIR" ] ; then
+   echo "ERROR: unable to create temporary directory" 1>&2
+   exit 1
+fi
+
+# output map
+r.out.mat input="$GIS_OPT_input" output="$TMP_DIR"/map.mat
+
+
+# copy support files
+for SUPPORT in colr hist cats ; do 
+    eval `g.findfile element=$SUPPORT file="$GIS_OPT_input"`
+    if [ ! -z "$file" ] ; then
+        cp "$file" "$TMP_DIR"/$SUPPORT
+    fi
+done
+
+
+# copy projection info
+#   (would prefer to use g.proj*, but this way is 5.3 and 5.7 compat)
+eval `g.gisenv`
+cp "$GISDBASE"/"$LOCATION_NAME"/PERMANENT/PROJ_INFO "$TMP_DIR"/proj_info
+
+
+# pack it all up
+OLD_DIR="`pwd`"
+cd "$TMP_DIR"/
+tar czf "$OLD_DIR"/"$GIS_OPT_input".pack *
+
+
+# clean up
+cd "$OLD_DIR"
+rm -rf "$TMP_DIR"
+
+echo Finished.
+exit 0

Added: grass-addons/raster/r.pack/r.unpack
===================================================================
--- grass-addons/raster/r.pack/r.unpack	                        (rev 0)
+++ grass-addons/raster/r.pack/r.unpack	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,116 @@
+#!/bin/sh
+#  r.unpack   --  unpack up a raster map packed with r.pack:
+#     tar+gzip => r.in.mat + support files
+#
+#   (c) 2004 GRASS Development Team
+#   AUTHOR: Hamish Bowman, Otago University, New Zealand
+#
+#   This program is free software under the GNU General Public
+#   License (>=v2). Read the file COPYING that comes with GRASS
+#   for details.
+#
+
+#%Module
+#%  description: UnPacks a raster map packed with r.pack
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: file,file,file
+#% description: Name of an existing pack file
+#% required : yes
+#%end
+#%flag
+#%  key: o
+#%  description: Override projection (use location's projection)
+#%end
+
+
+if [ -z "$GISBASE" ] ; then
+   echo "You must be in GRASS GIS to run this program." >&2
+   exit 1
+fi   
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+   exec g.parser "$0" "$@"
+fi
+
+# check for tar  (is there a better way?)
+if [ -z "`which tar`" ] ; then
+   echo "ERROR: tar must be installed to use this program."
+   exit 1
+fi
+# check for gzip
+if [ -z "`which gzip`" ] ; then
+   echo "ERROR: gzip must be installed to use this program."
+   exit 1
+fi
+
+
+eval `g.gisenv`
+MSET_DIR="$GISDBASE/$LOCATION_NAME/$MAPSET"
+
+
+if [ ! -e "$GIS_OPT_input" ] ; then
+   echo "ERROR: file not found [$GIS_OPT_input]"
+   exit 1
+fi
+
+# remove .pack and path from $GIS_OPT_input
+MAP_NAME="`basename "$GIS_OPT_input" | sed -e 's/\.pack$//'`"
+echo "The imported map will be named [$MAP_NAME]."
+
+eval `g.findfile element=cell file="$MAP_NAME"`
+if [ ! -z "$file" ] ; then
+   echo "ERROR: '$MAP_NAME' already exists."
+   exit 1
+fi
+
+
+# create temporary directory to hold bits
+TMP_DIR="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP_DIR" ] ; then
+   echo "ERROR: unable to create temporary files" 1>&2
+   exit 1
+fi
+rm -f "$TMP_DIR"
+mkdir "$TMP_DIR"
+if [ ! -d "$TMP_DIR" ] ; then
+   echo "ERROR: unable to create temporary directory" 1>&2
+   exit 1
+fi
+
+
+cp "$GIS_OPT_input" "$TMP_DIR"/
+cd "$TMP_DIR"/
+tar xzf "`basename $GIS_OPT_input`"
+
+
+# check projection compatibility in a rather crappy way
+if [ ! -z "`diff proj_info "$MSET_DIR"/../PERMANENT/PROJ_INFO`" ] ; then
+    if [ $GIS_FLAG_o -eq 1 ] ; then
+        echo "WARNING: Projection information does not match. Proceeding.."
+    else
+        echo "ERROR: Projection information does not match. Aborting."
+        # clean up
+        cd "$MSET_DIR"
+        rm -rf "$TMP_DIR"
+        exit 1
+    fi
+fi
+
+
+r.in.mat input=map.mat output="$MAP_NAME"
+
+for SUPPORT in colr hist cats ; do 
+    if [ -e $SUPPORT ] ; then
+        cp $SUPPORT "$MSET_DIR"/$SUPPORT/"$MAP_NAME"
+    fi
+done
+
+
+# clean up
+cd "$MSET_DIR"
+rm -rf "$TMP_DIR"
+
+echo Finished.
+exit 0

Added: grass-addons/raster/r.terraflow.tools/calc_terraflow_dir.m
===================================================================
--- grass-addons/raster/r.terraflow.tools/calc_terraflow_dir.m	                        (rev 0)
+++ grass-addons/raster/r.terraflow.tools/calc_terraflow_dir.m	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,58 @@
+% calc_terraflow_dir.m
+%   extract dominant flow from r.terraflow direction map and convert to GRASS aspect map
+%   by Hamish Bowman 18 April 2005
+%
+% GRASS aspect format is in degrees CCW from east.
+%
+% (c) 2005 The GRASS GIS Development Team
+% This program is free software under the GNU General Public
+%   License (>=v2). Read the file COPYING that comes with GRASS
+%   for details.
+%
+% terraflow directions:
+%   32 64 128
+%   16 *   1
+%   8  4   2
+
+% !r.out.mat in=terraflow.dir out=tf.mat
+% load tf.mat
+
+if ( exist('map_data') ~= 1)
+    disp('you have to import map from GRASS first. r.out.mat->load file.mat')
+end
+
+dim = size(map_data);
+dom_map = zeros(dim);
+asp_map = zeros(dim);
+
+for i = 1:dim(1)
+    for j = 1:dim(2)
+        dom_map(i,j) = dominant_dir(map_data(i,j));
+    end
+end
+
+%imagesc(dom_map), axis equal, axis tight, colorbar
+
+oct_mtx = [0 1 2 4 8 16 32 64 128 -1];
+asp_mtx = [0 360:-45:45 -1];
+
+for i = 1:length(oct_mtx)
+   asp_map(find(dom_map == oct_mtx(i))) = asp_mtx(i);
+end
+
+%clf
+%imagesc(asp_map), axis equal, axis tight, colorbar
+
+% save results
+map_data = asp_map;
+map_name = 'terraflow_aspect';
+map_title= 'TerraFlow direction from GRASS aspect format from calc_terraflow_dir.m';
+save terraflow_aspect.mat map_* -v4
+
+if(0)
+% GRASS commands to load back in
+!r.in.mat in=terraflow_aspect.mat -v
+!r.null map=terraflow_aspect setnull=0
+!r.colors terraflow_aspect col=aspect
+!d.rast.arrow terraflow_aspect
+end

Added: grass-addons/raster/r.terraflow.tools/dominant_dir.m
===================================================================
--- grass-addons/raster/r.terraflow.tools/dominant_dir.m	                        (rev 0)
+++ grass-addons/raster/r.terraflow.tools/dominant_dir.m	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,74 @@
+function dominant_dir = dominant_dir(dir)
+% dominant_dir.m
+%   extract dominant flow from r.terraflow direction map.
+%   by Hamish Bowman 18 April 2005
+% based upon the rules in r.terraflow's findDominant() funtion in direction.cc
+%
+% directions:
+%   32 64 128
+%   16 *   1
+%   8  4   2
+
+switch(dir)
+  case {1,2,4,8,16,32,64,128}
+    dominant_dir=dir;
+
+  case {1+2, 128+1}
+    dominant_dir=1;
+  case {2+4, 4+8}
+    dominant_dir=4;
+  case {8+16, 16+32}
+    dominant_dir=16;
+  case {32+64, 64+128}
+    dominant_dir=64;
+
+  case {1+2+4}
+    dominant_dir=2;
+  case {2+4+8}
+    dominant_dir=4;
+  case {4+8+16}
+    dominant_dir=8;
+  case {8+16+32}
+    dominant_dir=16;
+  case {16+32+64}
+    dominant_dir=32;
+  case {32+64+128}
+    dominant_dir=64;
+  case {64+128+1}
+    dominant_dir=128;
+  case {128+1+2}
+    dominant_dir=1;
+
+  case {128+1+2+4, 64+128+1+2}
+    dominant_dir=1;
+  case {1+2+4+8, 2+4+8+16}
+    dominant_dir=4;
+  case {8+16+32+64, 4+8+16+32}
+    dominant_dir=16;
+  case {32+64+128+1, 16+32+64+128}
+    dominant_dir=64;
+
+  case {64+128+1+2+4}
+    dominant_dir=1;
+  case {128+1+2+4+8}
+    dominant_dir=2;
+  case {1+2+4+8+16}
+    dominant_dir=4;
+  case {2+4+8+16+32}
+    dominant_dir=8;
+  case {4+8+16+32+64}
+    dominant_dir=16;
+  case {8+16+32+64+128}
+    dominant_dir=32;
+  case {16+32+64+128+1}
+    dominant_dir=64;
+  case {32+64+128+1+2}
+    dominant_dir=128;
+
+  case 0
+    dominant_dir=dir;
+
+  otherwise
+    disp(['Ambiguous direction: [' num2str(dir) ']'])
+    dominant_dir=-1;
+end

Added: grass-addons/vector/v.out.ascii.db/v.out.ascii.db
===================================================================
--- grass-addons/vector/v.out.ascii.db/v.out.ascii.db	                        (rev 0)
+++ grass-addons/vector/v.out.ascii.db/v.out.ascii.db	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,131 @@
+#!/bin/sh
+#
+############################################################################
+#
+# MODULE:       v.out.ascii.db
+#
+# AUTHOR(S):    Hamish Bowman, University of Otago, New Zealand
+#
+# PURPOSE:      output point coordinates with optional columns from database
+#
+# COPYRIGHT:    (c) 2005-2006 Hamish Bowman and the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+# updates:
+#   30 March 2006 (HB): Added support for 'where='
+#
+#############################################################################
+
+#%Module
+#% description: Export vector point data with selected attributes
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,vector,vector
+#% description: name of existing vector file
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new_file,file,file
+#% description: name for output ASCII file (omit for display to stdout)
+#% required : no
+#%end
+#%option
+#% key: columns
+#% type: string
+#% description: attribute columns to export ("cat" is always included)
+#% required : yes
+#% multiple: yes
+#%end
+#%option
+#% key: where
+#% type: string
+#% description: WHERE conditions of SQL statement without 'where' keyword
+#% required : no
+#% multiple: yes
+#%end
+
+## temp disabled:
+##%option
+##% key: fs
+##% type: string
+##% description: output field separator
+##% required : no
+##% answer: |
+##%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
+  # echo "g.parser \"$0\" \"$@\""
+   exec g.parser "$0" "$@"
+fi
+
+# set up tempfiles
+COOR_TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$COOR_TMP" ] ; then
+    echo "ERROR: unable to create temporary files" 1>&2
+    exit 1
+fi
+ATTR_TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$ATTR_TMP" ] ; then
+    echo "ERROR: unable to create temporary files" 1>&2
+    exit 1
+fi
+
+# restrict fs to one char
+#FS=`echo "$GIS_OPT_fs" | awk '{printf("%c", $1)}'`
+
+INPUT="$GIS_OPT_input"
+if [ -n "$GIS_OPT_where" ] ; then
+   v.extract in="$GIS_OPT_input" out=tmp_voutascdb_$$ where="$GIS_OPT_where" 1>&2
+   INPUT=tmp_voutascdb_$$
+fi
+
+# extract
+v.out.ascii "$INPUT" > "$COOR_TMP"
+
+#assume layer =1
+TABLE="`v.db.connect -g "$INPUT" | head -1 | cut -f2 -d' '`"
+DATABASE="`v.db.connect -g "$INPUT" | head -1 | cut -f4 -d' '`"
+DRIVER="`v.db.connect -g "$INPUT" | head -1 | cut -f5 -d' '`"
+
+INNAME=`echo "$INPUT" | cut -f1 -d'@'`
+if [ "$TABLE" != "$INNAME" ] ; then
+   echo "Multiple tables: using first one [$TABLE]" 1>&2
+fi
+
+db.select -c table="$TABLE" database="$DATABASE" driver="$DRIVER" \
+   sql="select cat,$GIS_OPT_columns from $TABLE" > "$ATTR_TMP"
+
+# number of cat column from coor export
+N="`head -1 "$COOR_TMP" | tr '|' '\n' | wc -l | awk '{print $1}'`"
+if [ $N -lt 1 ] ; then
+   echo "No point coordinates found in vector map (use v.type or v.to.points)" 1>&2
+   exit 1
+fi
+
+# sort both by cat
+sort -n --field-separator='|' --key=$N "$COOR_TMP" > "$COOR_TMP".s
+sort -n --field-separator='|' "$ATTR_TMP" > "$ATTR_TMP".s
+
+if [ -n "$GIS_OPT_output" ] ; then
+    join -t '|' -1 $N -2 1 "$COOR_TMP".s "$ATTR_TMP".s > "$GIS_OPT_output"
+    echo "`basename $0` done." 1>&2
+else  # to stdout
+    join -t '|' -1 $N -2 1 "$COOR_TMP".s "$ATTR_TMP".s
+fi
+
+#cleanup
+rm -f "$COOR_TMP" "$ATTR_TMP" "$COOR_TMP".s "$ATTR_TMP".s
+if [ -n "$GIS_OPT_where" ] ; then
+   g.remove vect=tmp_voutascdb_$$ 1>&2
+fi

Added: grass-addons/vector/v.random.cover/v.random.cover
===================================================================
--- grass-addons/vector/v.random.cover/v.random.cover	                        (rev 0)
+++ grass-addons/vector/v.random.cover/v.random.cover	2008-02-14 05:45:55 UTC (rev 30140)
@@ -0,0 +1,197 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       v.random.cover
+# AUTHOR:       M. Hamish Bowman, Dept. Marine Science, Otago Univeristy,
+#                 New Zealand
+# PURPOSE:      Randomly generate a 2D points map constrained to an area
+#		See also 'r.random cover= vector_output='
+#
+# COPYRIGHT:    (c) 2008 Hamish Bowman, and the GRASS Development Team
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%Module
+#% description: Randomly generate a 2D points map constrained to a specified area.
+#% keywords: vector, statistics
+#%End
+#%option
+#% key: cover
+#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc: name
+#% description: Name of vector map containing cover area
+##   "containment area"? "specified area"?
+#%required: yes
+#%end
+#%option
+#% key: cat
+#% type: integer
+#% label: Category number(s) of cover area
+#% description: Example: 1,3,7-9,13
+#% required: yes
+#%end 
+#%option
+#% key: layer
+#% type: integer
+#% description: Layer number of cover area
+#% answer: 1
+#% required: no
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new,vector,vector
+#% key_desc: name
+#% description: Name for output vector map
+#% required: yes
+#%end
+#%option
+#% key: n
+#% type: integer
+#% description: Number of points to be created
+#% required: yes
+#%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
+
+# --quiet causes an error with GRASS <= 6.2.2  (6.2.3 is ok)
+GRASS_VERBOSE=0
+export GRASS_VERBOSE
+
+
+#### check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    echo "ERROR: awk required, please install awk or gawk first" 1>&2
+    exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+
+cleanup()
+{
+   g.mremove -f vect="vranda_*_$$"
+   g.remove region="vrandarea.$$"
+}
+
+# what to do in case of user break:
+exitprocedure()
+{
+ echo 'User break!' 1>&2
+ cleanup
+ exit 1
+}
+# shell check for user break (signal list: trap -l)
+trap "exitprocedure" 2 3 15
+
+
+if [ "$GIS_OPT_N" -lt 1 ] ; then
+    echo "ERROR: Need at least one point" 1>&2
+    exit 1
+fi
+
+# extract the area of interest
+v.extract in="$GIS_OPT_COVER" out="vranda_cover_$$" \
+   layer="$GIS_OPT_LAYER" list="$GIS_OPT_CAT"
+
+#preset to 0 as a failsafe
+areas=0
+eval `v.info -t map="vranda_cover_$$" | grep areas`
+
+if [ "$areas" -lt 1 ] ; then
+    echo "ERROR: No bounding area" 1>&2
+    cleanup
+    exit 1
+fi
+
+# clone current region
+g.region save="vrandarea.$$"
+WIND_OVERRIDE="vrandarea.$$"
+export WIND_OVERRIDE
+
+# set the resolution
+g.region vect="vranda_cover_$$"
+
+
+# proportion of in-area to region area
+NS_EXT=`g.region -em | grep north | cut -f2 -d':' | awk '{print $1}'`
+EW_EXT=`g.region -em | grep east | cut -f2 -d':' | awk '{print $1}'`
+REGION_AREA=`echo $NS_EXT $EW_EXT | awk '{print $1 * $2}'`
+BOUND_AREA=`v.report map="vranda_cover_$$" option=area units=meters 2>/dev/null \
+   | cut -f3 -d'|' | grep -v '^area$' | tr '\n' ' '`
+
+# for use with multiple cats
+BOUND_AREA_TOT=0
+for i in $BOUND_AREA ; do
+   BOUND_AREA_TOT=`echo "$BOUND_AREA_TOT" "$i" | awk '{print $1 + $2}'`
+done
+#debug: echo "[$BOUND_AREA] -> {$BOUND_AREA_TOT}"
+
+
+# plus 20%
+N_MULT=`echo "$REGION_AREA" "$BOUND_AREA_TOT" | awk '{print 1.2 * ($1 / $2)}'`
+N_ESTIMATE=`echo "$GIS_OPT_N" "$N_MULT" | awk '{printf("%.0f", $1 * $2)}'`
+
+# calc what 20% of n is in case we need more
+N_20=`echo "$GIS_OPT_N" | awk '{printf("%.0f", $1 * 0.2)}'`
+if [ "$N_20" -lt 1 ] ; then
+   N_20="1"
+fi
+
+#debug: echo "N_ESTIMATE = [$N_ESTIMATE]"
+v.random out="vranda_pass1_$$" n="$N_ESTIMATE"
+
+# select just points in area
+v.select ainput="vranda_pass1_$$" atype=point binput="vranda_cover_$$" \
+   btype=area operator=overlap output="vranda_pts1_$$"
+
+# do we have enough?
+eval `v.info -t "vranda_pts1_$$" | grep points`
+
+while [ "$points" -lt "$GIS_OPT_N" ] ; do
+  echo "Not enough points, additional pass required ..." 1>&2
+   # too few: add 20% more
+   v.random out="vranda_pass2_$$" n="$N_20" --overwrite
+   v.select ainput="vranda_pass2_$$" atype=point binput="vranda_cover_$$" \
+      btype=area operator=overlap output="vranda_pts2_$$" --overwrite
+
+   # if no new points to add, skip patching to save a little wear&tear
+   eval `v.info -t "vranda_pts2_$$" | grep points`
+   if [ "$points" -eq 0 ] ; then
+      continue
+   fi
+
+   v.patch -a in="vranda_pts2_$$" out="vranda_pts1_$$" --o
+   eval `v.info -t "vranda_pts1_$$" | grep points`
+done
+
+v.category option=del in="vranda_pts1_$$" out="vranda_nocat_$$"
+v.category option=add in="vranda_nocat_$$"  out="vranda_cat_$$" cat=1 step=1
+
+# too many: extract only what we need
+if [ "$points" -gt "$GIS_OPT_N" ] ; then
+   v.extract in="vranda_cat_$$" out="$GIS_OPT_OUTPUT" list="1-${GIS_OPT_N}"
+else
+   g.rename vect="vranda_cat_$$,$GIS_OPT_OUTPUT"
+fi
+
+cleanup
+
+eval `v.info -t "$GIS_OPT_OUTPUT" | grep points`
+
+echo "Created <$GIS_OPT_OUTPUT> with $points random points" 1>&2



More information about the grass-commit mailing list