[GRASS-SVN] r60081 - grass-addons/grass6/postscript/ps.atlas
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 4 16:05:06 PDT 2014
Author: hamish
Date: 2014-05-04 16:05:06 -0700 (Sun, 04 May 2014)
New Revision: 60081
Modified:
grass-addons/grass6/postscript/ps.atlas/ps.atlas
Log:
quoting is required for filename variables, misc cleanup, don't alter WIND file (#2230)
Modified: grass-addons/grass6/postscript/ps.atlas/ps.atlas
===================================================================
--- grass-addons/grass6/postscript/ps.atlas/ps.atlas 2014-05-04 22:46:16 UTC (rev 60080)
+++ grass-addons/grass6/postscript/ps.atlas/ps.atlas 2014-05-04 23:05:06 UTC (rev 60081)
@@ -16,8 +16,8 @@
#############################################################################
if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
+ echo "You must be in GRASS GIS to run this program." >&2
+ exit 1
fi
#%Module
@@ -91,33 +91,18 @@
exec g.parser "$0" "$@"
fi
-# sed
-if [ -z "`which sed`" ] ; then
- echo "ERROR: Script needs sed."
- exit 1
-fi
-# grep
-if [ -z "`which grep`" ] ; then
- echo "ERROR: Script needs grep."
- exit 1
-fi
+PGMS="sed grep awk bc"
+for PGM in $PGMS ; do
+ if [ -z "`which $PGM`" ] ; then
+ g.message -e "Script needs $PGM."
+ exit 1
+ fi
+done
-# awk
-if [ -z "`which awk`" ] ; then
- echo "ERROR: Script needs awk."
- exit 1
-fi
-
-# bc
-if [ -z "`which bc`" ] ; then
- echo "ERROR: Script needs bc."
- exit 1
-fi
-
# ps2pdfwr
if [ -z "`which ps2pdfwr`" ] && [ $GIS_FLAG_p -eq 1 ]; then
- echo "ERROR: Script needs ps2pdfwr."
+ g.message -e "Script needs ps2pdfwr."
exit 1
fi
@@ -136,12 +121,12 @@
fi
# redirecting messages to stdout or /dev/null
-if [ "$GIS_FLAG_D" -eq "1" ]; then
+if [ "$GIS_FLAG_D" -eq 1 ] ; then
OUT="/dev/stdout"
else
OUT="/dev/null"
fi
-
+
## vars
eval `g.gisenv`
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
@@ -154,11 +139,11 @@
oldregion="region_$$"
newvector=$out"_atlas"
TMP1="`g.tempfile pid=$$`"
-rows_x_cols=`echo $rows $cols|awk '{print $1*$2}'`;
+rows_x_cols=`echo $rows $cols | awk '{print $1*$2}'`
# removing vector, if exists
# create vector && overwrite old && vector exists
-if [ "$GIS_FLAG_V" -eq "1" ] && [ "$GIS_FLAG_O" -eq "1" ] && [ -n "`g.mlist type=vect mapset=$MAPSET pattern=$newvector`" ]; then
+if [ "$GIS_FLAG_V" -eq 1 ] && [ "$GIS_FLAG_O" -eq 1 ] && [ -n "`g.mlist type=vect mapset=$MAPSET pattern=$newvector`" ] ; then
echo "Vector exists, removing..."
g.remove vect=$newvector 1>$OUT
else
@@ -171,28 +156,28 @@
fi
# rotate flag
-if [ $GIS_FLAG_R -eq 1 ]; then
- rotate="-r";
+if [ $GIS_FLAG_R -eq 1 ] ; then
+ rotate="-r"
fi
# informing
echo "Running: ps.map -e $rotate in=$input out=$out.eps"
# use only hlaf of overlaping
-overlap=`echo "$overlap"|awk '{printf("%f", $1/2);}'`;
+overlap=`echo "$overlap" | awk '{printf("%f", $1/2)}'`
#######################################################################
cleanup()
{
- g.region $oldregion
- rm -f $GISDBASE/$LOCATION_NAME/$MAPSET/windows/$oldregion
- rm -f $TMP1
+ g.region "$oldregion"
+ g.remove region="$oldregion"
+ rm -f "$TMP1"
}
# what to do in case of user break:
exitprocedure()
{
echo "User break!"
- echo "drop table $newvector"|db.execute
+ echo "drop table $newvector" | db.execute
cleanup
exit 1
}
@@ -202,13 +187,14 @@
#######################################################################
-g.region save=$oldregion
+g.region save="$oldregion"
# must be because of awk and non-english locale
-export LANG=C
+LANG=C
+export LANG
# setign maxe, maxn, maxw and maxs variables with help of g.region
-eval `g.region -g| sed -e s/^/max/`;
+eval `g.region -gu | sed -e s/^/max/`
# be simple ps.map
if [ -z "$cols" ]; then
@@ -225,114 +211,115 @@
# size of steps
-estep=`echo $maxe $maxw $cols | awk '{printf("%f",($1-$2)/$3);}'`;
-nstep=`echo $maxn $maxs $rows | awk '{printf("%f",($1-$2)/$3);}'`;
+estep=`echo $maxe $maxw $cols | awk '{printf("%f",($1-$2)/$3);}'`
+nstep=`echo $maxn $maxs $rows | awk '{printf("%f",($1-$2)/$3);}'`
# setting first region
-south=`echo $north $nstep | awk '{printf("%f",$1-$2)}'`;
-east=`echo $west $estep | awk '{printf("%f",$1+$2)}'`;
+south=`echo $north $nstep | awk '{printf("%f",$1-$2)}'`
+east=`echo $west $estep | awk '{printf("%f",$1+$2)}'`
# number of region
-no_of_region=0;
+no_of_region=0
### ascii file and db. table
if [ $GIS_FLAG_V -eq 1 ]; then
echo "Creating ascii file + vector table"
### creating database
- echo "CREATE TABLE $newvector (cat int, region int, label varchar(10), row int, col varchar(5), east double, north double, west double, south double);"| db.execute
+ echo "CREATE TABLE $newvector (cat int, region int, label varchar(10), row int, col varchar(5), east double, north double, west double, south double);" | db.execute
fi
# inicialization
currow=0;
### rows N-S
-while [ "`echo $overlap $south $maxs |awk '{printf("%d", $2+$1 >= $3);}'`" -eq "1" ];
+while [ "`echo $overlap $south $maxs | awk '{printf("%d", $2+$1 >= $3)}'`" -eq 1 ];
do
- echo "north->south" 1>$OUT # test
+ echo "north->south" 1> "$OUT" # test
# number of current row
- currow=`expr $currow + 1`;
+ currow=`expr $currow + 1`
# inicialization
curcol=0;
# columns W-E
- while [ "`echo $east $maxe |awk '{printf("%d", $1 <= $2);}'`" -eq "1" ];
+ while [ "`echo $east $maxe | awk '{printf("%d", $1 <= $2)}'`" -eq 1 ];
do
- echo "west->east" 1>$OUT # test
+ echo "west->east" 1> "$OUT" # test
# number of current column
- curcol=`expr $curcol + 1`;
+ curcol=`expr $curcol + 1`
# charakter of current column
- if [ "$curcol" -gt "26" ]; then
- pre_alpha=`echo $curcol/26| bc`;
- curcol_alpha=`echo $pre_alpha $curcol|awk '{printf("%c%c",$1+64, $2-26+64);}'`;
+ if [ "$curcol" -gt 26 ] ; then
+ pre_alpha=`echo $curcol/26 | bc`
+ curcol_alpha=`echo $pre_alpha $curcol | awk '{printf("%c%c",$1+64, $2-26+64)}'`
else
- curcol_alpha=`echo $curcol|awk '{printf("%c",$1+64);}'`;
+ curcol_alpha=`echo $curcol | awk '{printf("%c",$1+64)}'`
fi
# overlapping 10% = 5% on both sides
- over_north=`echo $north $overlap|awk '{printf("%f", $1+$2);}'`;
- over_west=`echo $west $overlap|awk '{printf("%f", $1-$2);}'`;
- over_east=`echo $east $overlap|awk '{printf("%f", $1+$2);}'`;
- over_south=`echo $south $overlap|awk '{printf("%f", $1-$2);}'`;
- east_center=`echo "$over_east+(($over_west)-($over_east))/2" |bc `
- north_center=`echo "$over_south+(($over_north)-($over_south))/2" |bc `
+ over_north=`echo $north $overlap | awk '{printf("%f", $1+$2);}'`
+ over_west=`echo $west $overlap | awk '{printf("%f", $1-$2);}'`
+ over_east=`echo $east $overlap | awk '{printf("%f", $1+$2);}'`
+ over_south=`echo $south $overlap | awk '{printf("%f", $1-$2);}'`
+ east_center=`echo "$over_east+(($over_west)-($over_east))/2" | bc`
+ north_center=`echo "$over_south+(($over_north)-($over_south))/2" | bc`
- g.region n=$over_north s=$over_south w=$over_west e=$over_east;
+ g.region n=$over_north s=$over_south w=$over_west e=$over_east
west=$east
- east=`echo "$west $estep" | awk '{print $1 + $2}'`;
+ east=`echo "$west $estep" | awk '{print $1 + $2}'`
- no_of_region=`expr $no_of_region + 1`;
- echo "-------------- REGION NUMBER $no_of_region OF $rows_x_cols ---------------" 1>$OUT
+ no_of_region=`expr $no_of_region + 1`
+ echo "-------------- REGION NUMBER $no_of_region OF $rows_x_cols ---------------" 1> "$OUT"
# storing coordinaes to ascii file
- if [ $GIS_FLAG_v -eq 1 ]; then
- echo "B 5" >> $TMP1
- echo "$over_east $over_north" >> $TMP1
- echo "$over_east $over_south" >> $TMP1
- echo "$over_west $over_south" >> $TMP1
- echo "$over_west $over_north" >> $TMP1
- echo "$over_east $over_north" >> $TMP1
- echo -e "C 1 1\n$east_center $north_center\n1 $no_of_region" >> $TMP1
- echo "INSERT INTO $newvector (cat, region, col, row, label, north, east, south, west) VALUES ($no_of_region,$no_of_region, '$curcol_alpha', $currow, '$curcol_alpha$currow', $over_north, $over_east, $over_south, $over_west);"|db.execute
+ if [ $GIS_FLAG_V -eq 1 ] ; then
+ echo "B 5" >> "$TMP1"
+ echo "$over_east $over_north" >> "$TMP1"
+ echo "$over_east $over_south" >> "$TMP1"
+ echo "$over_west $over_south" >> "$TMP1"
+ echo "$over_west $over_north" >> "$TMP1"
+ echo "$over_east $over_north" >> "$TMP1"
+ echo -e "C 1 1\n$east_center $north_center\n1 $no_of_region" >> "$TMP1"
+ echo "INSERT INTO $newvector (cat, region, col, row, label, north, east, south, west) VALUES ($no_of_region,$no_of_region, '$curcol_alpha', $currow, '$curcol_alpha$currow', $over_north, $over_east, $over_south, $over_west);" | db.execute
fi
#################################################################
# create ps & pdf
#################################################################
- ps.map -e $rotate in=$input out=$out$no_of_region.eps 1>$OUT
- if [ "$GIS_FLAG_p" = "1" ]; then
- ps2pdfwr -sPAPERSIZE=$GIS_OPT_FORMAT $out$no_of_region.eps
+ ps.map -e $rotate in=$input out=$out$no_of_region.eps 1> "$OUT"
+ if [ "$GIS_FLAG_p" -eq 1 ] ; then
+ ps2pdfwr -sPAPERSIZE=$GIS_OPT_FORMAT "$out$no_of_region.eps"
fi
#################################################################
#
#################################################################
# print progres
- echo "$no_of_region $rows_x_cols" | awk '{printf("\r%d%%",$1/$2*100);}' 1>&1
+ echo "$no_of_region $rows_x_cols" | awk '{printf("\r%d%%",$1/$2*100)}' 1>&1
done
north=$south
- south=`echo "$north $nstep" |awk '{print $1 - $2}'`;
+ south=`echo "$north $nstep" | awk '{print $1 - $2}'`
# go back to west!
west=$maxw
- east=`echo "$west $estep" | awk '{print $1 + $2}'`;
+ east=`echo "$west $estep" | awk '{print $1 + $2}'`
done;
-if [ $GIS_FLAG_v -eq 1 ]; then
+if [ $GIS_FLAG_V -eq 1 ] ; then
# import the vector of regions
outtmp="$newvector"_tmp
- v.in.ascii -n in=$TMP1 out=$outtmp format=standard 1>$OUT 2>&1
- v.clean tool=break,rmdupl in=$outtmp out=$newvector 1>$OUT 2>&1
- g.remove vect=$outtmp 1>$OUT 2>&1
- v.db.connect map=$newvector table=$newvector 1>$OUT 2>&1
+ v.in.ascii -n in=$TMP1 out=$outtmp format=standard 1> "$OUT" 2>&1
+ v.clean tool=break,rmdupl in=$outtmp out=$newvector 1> "$OUT" 2>&1
+ g.remove vect=$outtmp 1> "$OUT" 2>&1
+ v.db.connect map=$newvector table=$newvector 1> "$OUT" 2>&1
fi
### cleaning
cleanup
+
More information about the grass-commit
mailing list