[GRASS-SVN] r55850 - in grass-addons/grass6/general: . g.name.sequence

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 17 03:38:46 PDT 2013


Author: hamish
Date: 2013-04-17 03:38:46 -0700 (Wed, 17 Apr 2013)
New Revision: 55850

Added:
   grass-addons/grass6/general/g.name.sequence/
   grass-addons/grass6/general/g.name.sequence/Makefile
   grass-addons/grass6/general/g.name.sequence/description.html
   grass-addons/grass6/general/g.name.sequence/g.name.sequence
Modified:
   grass-addons/grass6/general/Makefile
Log:
helper script to wrap the unix 'seq' tool (wish #1109)

Modified: grass-addons/grass6/general/Makefile
===================================================================
--- grass-addons/grass6/general/Makefile	2013-04-17 09:37:08 UTC (rev 55849)
+++ grass-addons/grass6/general/Makefile	2013-04-17 10:38:46 UTC (rev 55850)
@@ -2,6 +2,7 @@
 
 SUBDIRS = \
 	g.md5sum \
+	g.name.sequence \
 	g.region.grow \
 	g.region.point
 ## already in 6.4+:

Copied: grass-addons/grass6/general/g.name.sequence/Makefile (from rev 55245, grass-addons/grass6/general/g.region.point/Makefile)
===================================================================
--- grass-addons/grass6/general/g.name.sequence/Makefile	                        (rev 0)
+++ grass-addons/grass6/general/g.name.sequence/Makefile	2013-04-17 10:38:46 UTC (rev 55850)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = g.name.sequence
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass6/general/g.name.sequence/description.html
===================================================================
--- grass-addons/grass6/general/g.name.sequence/description.html	                        (rev 0)
+++ grass-addons/grass6/general/g.name.sequence/description.html	2013-04-17 10:38:46 UTC (rev 55850)
@@ -0,0 +1,51 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.name.sequence</em> prints a sequential series of map names to
+<tt>stdout</tt>. It is intended for use with modules like <em>r.series</em>,
+encoding animations, and general scripting purposes.
+
+
+<h2>NOTES</h2>
+
+The sequence must remain postive and only support integers.
+The module will exit with an error if the <b>padding</b> value is not
+ wide enough.
+A padding width of "0" can be used to indicate no padding should be used.
+The <b>skip</b> value can be a negative to decrement instead of increment
+ the series. In this case the <b>min</b> value should be larger than the
+ <b>max</b> value.
+
+
+<h2>EXAMPLE</h2>
+
+Prints <tt>day.001,day.002,...,day.365</tt>:
+<div class="code"><pre>
+g.name.sequence min=1 max=365  base="day." pad=3
+</pre></div>
+
+<p>
+Prints <tt>frame.2000 frame.1980 ... frame.0000</tt>:
+<div class="code"><pre>
+g.name.sequence min=2000 max=0 skip=-20 base="frame." pad=4 sep=space
+</pre></div>
+
+<p>
+Prints <tt>map_9,map_10,...,map_105</tt>:
+<div class="code"><pre>
+g.name.sequence min=9 max=105 base="map_" pad=0
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+<em>
+<a href="g.mlist.html">g.mlist</a>
+</em><br>
+
+
+<h2>AUTHOR</h2>
+
+Hamish Bowman, Dunedin, New Zealand
+<br>
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass-addons/grass6/general/g.name.sequence/description.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass6/general/g.name.sequence/g.name.sequence
===================================================================
--- grass-addons/grass6/general/g.name.sequence/g.name.sequence	                        (rev 0)
+++ grass-addons/grass6/general/g.name.sequence/g.name.sequence	2013-04-17 10:38:46 UTC (rev 55850)
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       g.name.sequence
+# AUTHOR(S):    Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Prints a series of sequential map names
+# COPYRIGHT:    (C) 2013 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.
+#
+############################################################################
+#%Module
+#% description: Prints out a sequential series of user defined map names.
+#% keywords: general, scripting
+#%End
+#%option
+#%  key: minimum
+#%  type: integer
+#%  description: Starting number
+#%  answer: 0
+#%end
+#%option
+#%  key: maximum
+#%  type: integer
+#%  description: Ending number
+#%  required: yes
+#%end
+#%option
+#%  key: skip
+#%  type: integer
+#%  description: Step interval
+#%  answer: 1
+#%end
+#%option
+#%  key: padding
+#%  type: integer
+#%  description: Width of numerical part
+#%  answer: 3
+#%end
+#%option
+#%  key: basename
+#%  type: string
+#%  description: Common base of the map names
+#%  required: yes
+#%end
+#%option
+#%  key: separator
+#%  type: string
+#%  label: Field separator
+#%  description: Character(s), or also accepts "comma,space,tab,newline"
+#%  answer: comma
+#%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 seq
+if [ ! -x "`which seq`" ] ; then
+    g.message -e "seq required, please install it first"
+    exit 1
+fi
+
+#### check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    g.message -e "awk required, please install awk or gawk first"
+    exit 1
+fi
+
+MIN="$GIS_OPT_MINIMUM"
+MAX="$GIS_OPT_MAXIMUM"
+PAD="$GIS_OPT_PADDING"
+SEP="$GIS_OPT_SEPARATOR"
+
+NL=0
+case "$SEP" in
+  comma) SEP=","
+    ;;
+  space) SEP=" "
+    ;;
+  # FIXME: is this portable to BSD/OSX?
+  tab | "\t") SEP=`echo "\t"`
+    ;;
+  newline | "\n") SEP="|"
+    NL=1
+    ;;
+esac
+#g.message -d "SEP=[$SEP]"
+
+# rudimentary check
+if [ "$MIN" -lt 0 ] || [ "$MAX" -lt 0 ] ; then
+   g.message -e "Only positive numbers in map name is supported"
+   exit 1
+fi
+
+if [ "$MAX" -gt "$MIN" ] || [ "$MAX" -eq "$MIN" ]; then
+   # handy tip: awk doesn't support log10(), but ln(x)/ln(10) is the same as log10(x)
+   WIDTH=`echo "$MAX" | awk '{print int(log($1)/log(10)) + 1}'`
+else
+   WIDTH=`echo "$MIN" | awk '{print int(log($1)/log(10)) + 1}'`
+fi
+#g.message -d "width=$WIDTH"
+
+if [ "$WIDTH" -gt "$PAD" ] && [ "$PAD" -ne 0 ] ; then
+   g.message -e "Padding option not large enough to cover range of values given"
+   exit 1
+fi
+
+OPT_STR="${GIS_OPT_BASENAME}%0${PAD}g"
+
+if [ "$NL" -eq 0 ] ; then
+  seq -s"$SEP" -f "$OPT_STR" \
+     "$GIS_OPT_MINIMUM" "$GIS_OPT_SKIP" "$GIS_OPT_MAXIMUM"
+else
+  seq -s"$SEP" -f "$OPT_STR" \
+     "$GIS_OPT_MINIMUM" "$GIS_OPT_SKIP" "$GIS_OPT_MAXIMUM" | tr '|' '\n'
+fi


Property changes on: grass-addons/grass6/general/g.name.sequence/g.name.sequence
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list