[GRASS-SVN] r46734 - in grass-addons/raster: . r.pack r.pack/experiment r.unpack r.unpack/experiment

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 18 02:47:12 EDT 2011


Author: hamish
Date: 2011-06-17 23:47:12 -0700 (Fri, 17 Jun 2011)
New Revision: 46734

Added:
   grass-addons/raster/r.pack/experiment/
   grass-addons/raster/r.pack/experiment/r.pack.mat
   grass-addons/raster/r.unpack/experiment/
   grass-addons/raster/r.unpack/experiment/r.unpack.mat
Removed:
   grass-addons/raster/r.pack.mat/
   grass-addons/raster/r.unpack.mat/
Log:
r.[un]pack.mat were first generation experiments, they are retained to demonstrate an alternative method but are no longer suggested for general use

Copied: grass-addons/raster/r.pack/experiment/r.pack.mat (from rev 46712, grass-addons/raster/r.pack.mat/r.pack.mat)
===================================================================
--- grass-addons/raster/r.pack/experiment/r.pack.mat	                        (rev 0)
+++ grass-addons/raster/r.pack/experiment/r.pack.mat	2011-06-18 06:47:12 UTC (rev 46734)
@@ -0,0 +1,88 @@
+#!/bin/sh
+#  r.pack   --  pack up a raster map as binary MAT-File:
+#     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 as binary MAT-File 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

Copied: grass-addons/raster/r.unpack/experiment/r.unpack.mat (from rev 46712, grass-addons/raster/r.unpack.mat/r.unpack.mat)
===================================================================
--- grass-addons/raster/r.unpack/experiment/r.unpack.mat	                        (rev 0)
+++ grass-addons/raster/r.unpack/experiment/r.unpack.mat	2011-06-18 06:47:12 UTC (rev 46734)
@@ -0,0 +1,116 @@
+#!/bin/sh
+#  r.unpack.mat   --  unpack up a binary MAT-File(v4) map packed with r.pack.mat:
+#     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 binary MAT-File map packed with r.pack.mat
+#%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



More information about the grass-commit mailing list