[GRASS-SVN] r40690 - in grass/branches/develbranch_6/scripts:
v.in.garmin v.in.gpsbabel v.in.lines v.in.wfs v.out.gpsbabel
v.rast.stats v.univar.sh
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 27 00:12:21 EST 2010
Author: hamish
Date: 2010-01-27 00:12:20 -0500 (Wed, 27 Jan 2010)
New Revision: 40690
Modified:
grass/branches/develbranch_6/scripts/v.in.garmin/v.in.garmin
grass/branches/develbranch_6/scripts/v.in.gpsbabel/v.in.gpsbabel
grass/branches/develbranch_6/scripts/v.in.lines/v.in.lines
grass/branches/develbranch_6/scripts/v.in.wfs/v.in.wfs
grass/branches/develbranch_6/scripts/v.out.gpsbabel/v.out.gpsbabel
grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats
grass/branches/develbranch_6/scripts/v.univar.sh/v.univar.sh
Log:
rename TMP variable to avoid namespace collision on MS Windows (trac #890)
Modified: grass/branches/develbranch_6/scripts/v.in.garmin/v.in.garmin
===================================================================
--- grass/branches/develbranch_6/scripts/v.in.garmin/v.in.garmin 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.in.garmin/v.in.garmin 2010-01-27 05:12:20 UTC (rev 40690)
@@ -142,14 +142,14 @@
#### setup temporary file
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
#### trap ctrl-c so that we can clean up tmp
-trap 'rm -f "${TMP}"*' 2 3 15
+trap 'rm -f "${TEMPFILE}"*' 2 3 15
#### process command line arguments
@@ -180,7 +180,7 @@
if [ "`expr $GIS_FLAG_W + $GIS_FLAG_R + $GIS_FLAG_T`" -gt 1 ] ; then
g.message -e "One feature at a time please. Use v.patch if you need to combine them."
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
@@ -207,13 +207,13 @@
if [ "`expr $WPT + $TRK + $RTE`" -eq 0 ] ; then
g.message -e "Must request either waypoints, route, or track."
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
if [ $GIS_FLAG_Z -eq 1 ] && [ $TRK -ne 1 ] ; then
g.message -e "3D import is only supported for tracks so far"
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
@@ -224,7 +224,7 @@
gpstrans "$GPSPORT" -i 1> /dev/null
if [ $? -ne 0 ] ; then
g.message -e message="Receiver on $GIS_OPT_PORT not responding, exiting"
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
elif [ $VERBOSE -eq 1 ] ; then
@@ -233,7 +233,7 @@
gardump -u -p "$GIS_OPT_PORT" 1>&2
if [ $? -ne 0 ] ; then
g.message -e message="Receiver on $GIS_OPT_PORT not responding, exiting"
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
g.message "GPS connection ok"
@@ -245,7 +245,7 @@
PROJ_TYPE=`g.region -p | grep 'projection' | cut -f2 -d" "`
if [ $PROJ_TYPE -eq 0 ] && [ $KEEP_WGS84 -ne 1 ] ; then
g.message -e "Cannot project to a XY location."
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
@@ -254,57 +254,57 @@
if [ $WPT -eq 1 ] ; then
g.message "Receiving Waypoints..."
if [ $GIS_FLAG_U -eq 0 ] ; then
- gpstrans "$GPSPORT" -dw > "$TMP".gpst 2>/dev/null
+ gpstrans "$GPSPORT" -dw > "$TEMPFILE".gpst 2>/dev/null
EXITCODE=$?
else
- gardump -w -p "$GIS_OPT_PORT" > "$TMP".gard
+ gardump -w -p "$GIS_OPT_PORT" > "$TEMPFILE".gard
EXITCODE=$?
fi
fi
if [ $RTE -eq 1 ] ; then
g.message "Receiving Routes..."
if [ $GIS_FLAG_U -eq 0 ] ; then
- gpstrans "$GPSPORT" -dr > "$TMP".gpst 2>/dev/null
+ gpstrans "$GPSPORT" -dr > "$TEMPFILE".gpst 2>/dev/null
EXITCODE=$?
else
- gardump -r -p "$GIS_OPT_PORT" > "$TMP".gard
+ gardump -r -p "$GIS_OPT_PORT" > "$TEMPFILE".gard
EXITCODE=$?
fi
fi
if [ $TRK -eq 1 ] ; then
g.message "Receiving Tracks..."
if [ $GIS_FLAG_U -eq 0 ] ; then
- gpstrans "$GPSPORT" -dt > "$TMP".gpst 2>/dev/null
+ gpstrans "$GPSPORT" -dt > "$TEMPFILE".gpst 2>/dev/null
EXITCODE=$?
else
- gardump -t -p "$GIS_OPT_PORT" > "$TMP".gard
+ gardump -t -p "$GIS_OPT_PORT" > "$TEMPFILE".gard
EXITCODE=$?
fi
fi
#### check success/failure
if [ "$EXITCODE" -ne 0 ] ; then
g.message -e "Retrieving data."
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
if [ $GIS_FLAG_U -eq 0 ] ; then
- if [ ! -e "${TMP}.gpst" ] || [ `wc -l < "${TMP}.gpst"` -le 1 ] ; then
+ if [ ! -e "${TEMPFILE}.gpst" ] || [ `wc -l < "${TEMPFILE}.gpst"` -le 1 ] ; then
g.message -w 'No Data! Exiting.'
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 0
fi
else
- if [ "`cat "${TMP}.gard" | grep -v '^\[' | grep -v '^#' -c`" -eq 0 ] ; then
+ if [ "`cat "${TEMPFILE}.gard" | grep -v '^\[' | grep -v '^#' -c`" -eq 0 ] ; then
g.message -w 'No Data! Exiting.'
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 0
fi
fi
if [ $GIS_FLAG_U -eq 0 ] ; then
#### check which projection we are working with
- PROJ="`head -n 1 "${TMP}.gpst" | sed -e 's/Format: //' | sed -e 's/ UTC.*//'`"
+ PROJ="`head -n 1 "${TEMPFILE}.gpst" | sed -e 's/Format: //' | sed -e 's/ UTC.*//'`"
if [ $VERBOSE -eq 1 ] ; then
g.message message="Coordinate format: ${PROJ}"
fi
@@ -313,10 +313,10 @@
# or DM.MM formatted input and I'm not going to start doing that sort
# of math in a shell script.
g.message -e message="Only DDD coordinates currently supported. [$PROJ]"
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
- IS_WGS84="`head -n 1 "$TMP".gpst | grep 'WGS 84'`"
+ IS_WGS84="`head -n 1 "$TEMPFILE".gpst | grep 'WGS 84'`"
else
# gardump
IS_WGS84=TRUE
@@ -331,19 +331,19 @@
if [ $GIS_FLAG_U -eq 0 ] ; then
# gpstrans
if [ $WPT -eq 1 ] ; then
- cat "${TMP}.gpst" | sed -e '1d' | awk -F '\t' '{print $6 " " $5}' > "$TMP".base
- cat "${TMP}.gpst" | sed -e '1d' | cut -f1,2,3 | tr '\t' '|' > "$TMP".attributes
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | awk -F '\t' '{print $6 " " $5}' > "$TEMPFILE".base
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | cut -f1,2,3 | tr '\t' '|' > "$TEMPFILE".attributes
ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, type VARCHAR(1), name VARCHAR(10), comments VARCHAR(40)'
fi
if [ $RTE -eq 1 ] ; then
- cat "${TMP}.gpst" | sed -e '1d' | grep '^W' | awk -F '\t' '{print $6 " " $5}' > "$TMP".base
- cat "${TMP}.gpst" | sed -e '1d' | grep '^W' | cut -f1,2,3 | tr '\t' '|' > "$TMP".attributes
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | grep '^W' | awk -F '\t' '{print $6 " " $5}' > "$TEMPFILE".base
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | grep '^W' | cut -f1,2,3 | tr '\t' '|' > "$TEMPFILE".attributes
ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, type VARCHAR(1), name varchar(10), comments VARCHAR(40)'
fi
if [ $TRK -eq 1 ] ; then
# we use uniq here as gpstrans can dupe up track points !?
- uniq "${TMP}.gpst" | sed -e '1d' | grep '^T' | awk -F '\t' '{print $4 " " $3}' > "$TMP".base
- uniq "${TMP}.gpst" | sed -e '1d' | grep '^T' | cut -f1,2 | tr '\t' '|' > "$TMP".attributes
+ uniq "${TEMPFILE}.gpst" | sed -e '1d' | grep '^T' | awk -F '\t' '{print $4 " " $3}' > "$TEMPFILE".base
+ uniq "${TEMPFILE}.gpst" | sed -e '1d' | grep '^T' | cut -f1,2 | tr '\t' '|' > "$TEMPFILE".attributes
ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, type VARCHAR(1), localtime VARCHAR(40)'
HAVE_ALT=FALSE
fi
@@ -352,7 +352,7 @@
if [ $WPT -eq 1 ] || [ $RTE -eq 1 ] ; then
# **n [route name]
# lat long [A:alt] [S:sym] [D:display] [I:id] [C:cmnt] [W:wpt info] [L:link]
- grep -E -v '^\[|^#|^\*\*' "${TMP}.gard" | awk '{print $2 " " $1}' > "$TMP".base
+ grep -E -v '^\[|^#|^\*\*' "${TEMPFILE}.gard" | awk '{print $2 " " $1}' > "$TEMPFILE".base
ROUTE_NUM=""
ROUTE_NAME=""
@@ -381,11 +381,11 @@
fi
if [ $WPT -eq 1 ] ; then
- echo "$A_VAL|$S_VAL|$D_VAL|$I_VAL|$C_VAL|$W_VAL|$L_VAL" >> "$TMP".attributes
+ echo "$A_VAL|$S_VAL|$D_VAL|$I_VAL|$C_VAL|$W_VAL|$L_VAL" >> "$TEMPFILE".attributes
elif [ $RTE -eq 1 ] ; then
- echo "$ROUTE_NUM|$ROUTE_NAME|$A_VAL|$S_VAL|$D_VAL|$I_VAL|$C_VAL|$W_VAL|$L_VAL" >> "$TMP".attributes
+ echo "$ROUTE_NUM|$ROUTE_NAME|$A_VAL|$S_VAL|$D_VAL|$I_VAL|$C_VAL|$W_VAL|$L_VAL" >> "$TEMPFILE".attributes
fi
- done < "${TMP}.gard"
+ done < "${TEMPFILE}.gard"
if [ $WPT -eq 1 ] ; then
ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, altitude DOUBLE PRECISION, symbol INTEGER, smbl_flag INTEGER, name VARCHAR(15), comments VARCHAR(50), poi_code VARCHAR(40), poi_link VARCHAR(4)'
@@ -398,24 +398,24 @@
# [yyyy-mm-dd hh:mm:ss] lat long [alt] [start]
unset HAVE_ALT
# some tracks don't have time/date, so we have to decide on the fly
- grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | \
+ grep -v '^\[\|^#\|^Track:' "${TEMPFILE}.gard" | \
awk '{ if ( $0 ~ /..:..:../) {
print $4 " " $3
} else {
print $2 " " $1
}
- }' > "$TMP".base
+ }' > "$TEMPFILE".base
- grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | \
+ grep -v '^\[\|^#\|^Track:' "${TEMPFILE}.gard" | \
awk '{ if ( $0 ~ /..:..:../) {
print $1 "|" $2 "|" $5 "|" $6
} else {
print "||" $3 "|" $4
}
- }' > "$TMP.attr"
+ }' > "$TEMPFILE.attr"
# check if there is any altitude data
- if [ `cut -f3 -d'|' "$TMP.attr" | grep -c 'start'` -ge 1 ] ; then
+ if [ `cut -f3 -d'|' "$TEMPFILE.attr" | grep -c 'start'` -ge 1 ] ; then
HAVE_ALT=FALSE
ATTR_COLS='x DOUBLE PRECISION, y DOUBLE PRECISION, gmt_date VARCHAR(10), gmt_time VARCHAR(8), new_track VARCHAR(5)'
if [ $GIS_FLAG_Z -eq 1 ] ; then
@@ -427,17 +427,17 @@
fi
# check if there is any track name data
- if [ `grep -c '^Track:' "${TMP}.gard"` -ge 1 ] ; then
+ if [ `grep -c '^Track:' "${TEMPFILE}.gard"` -ge 1 ] ; then
ATTR_COLS="$ATTR_COLS, track_name VARCHAR(15)"
# create data for track name column
# need extra if(TRK) else NULL stuff for v.in.ascii empty last column bug
- grep -v '^\[\|^#' "${TMP}.gard" | awk \
+ grep -v '^\[\|^#' "${TEMPFILE}.gard" | awk \
'/^Track:/ {TRK=$0; sub(/^Track: /, "", TRK)} ;
- /^[-0-9]/ {if(TRK) {print TRK} else {print "NULL"}}' > "$TMP.trackname"
- paste -d'|' "$TMP.attr" "$TMP.trackname" > "$TMP.attributes"
+ /^[-0-9]/ {if(TRK) {print TRK} else {print "NULL"}}' > "$TEMPFILE.trackname"
+ paste -d'|' "$TEMPFILE.attr" "$TEMPFILE.trackname" > "$TEMPFILE.attributes"
else
- cp "$TMP.attr" "$TMP.attributes"
+ cp "$TEMPFILE.attr" "$TEMPFILE.attributes"
fi
fi
fi
@@ -445,13 +445,13 @@
#### reproject if needed (only consider 2D)
if [ -z "$IS_WGS84" ] || [ $KEEP_WGS84 -eq 1 ] ; then
g.message "No projection transformation performed"
- cp "${TMP}.base" "${TMP}.P_base"
+ cp "${TEMPFILE}.base" "${TEMPFILE}.P_base"
else
g.message "Attempting waypoint projection transform with cs2cs..."
- cs2cs -f %.7f $IN_PROJ +to $OUT_PROJ < "${TMP}.base" > "${TMP}.P_base"
+ cs2cs -f %.7f $IN_PROJ +to $OUT_PROJ < "${TEMPFILE}.base" > "${TEMPFILE}.P_base"
EXITCODE=$?
# check if transform REALLY worked (e.g. grid file not found)
- BAD_PTS="`grep -c "^\*" "${TMP}.P_base"`"
+ BAD_PTS="`grep -c "^\*" "${TEMPFILE}.P_base"`"
if [ "$BAD_PTS" -gt 0 ] ; then
g.message message=""
g.message -w "$BAD_PTS point(s) failed reprojection."
@@ -460,46 +460,46 @@
if [ $EXITCODE -ne 0 ] ; then
g.message -w "Projection transform failed, retaining WGS84"
g.message message=""
- cp -f "${TMP}.base" "${TMP}.P_base"
+ cp -f "${TEMPFILE}.base" "${TEMPFILE}.P_base"
fi
fi
- cat "${TMP}.P_base" | awk '{print $1 "|" $2}' > "${TMP}.vertices"
+ cat "${TEMPFILE}.P_base" | awk '{print $1 "|" $2}' > "${TEMPFILE}.vertices"
#### and put back together
# wpt list: x|y| W MOB 04-OCT-03 08:07
- paste -d"|" "$TMP".vertices "$TMP".attributes > "$TMP".asc
+ paste -d"|" "$TEMPFILE".vertices "$TEMPFILE".attributes > "$TEMPFILE".asc
if [ -z "$NAME" ] ; then
g.message "ASCII file redirected to stdout"
- cat "${TMP}.asc" 2> /dev/null
+ cat "${TEMPFILE}.asc" 2> /dev/null
else
#### import into new ascii points file
if [ $WPT -eq 1 ] ; then
g.message "Importing Waypoints..."
- v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS" --quiet
+ v.in.ascii input="${TEMPFILE}.asc" output="$NAME" cat=0 columns="$ATTR_COLS" --quiet
EXITCODE=$?
fi
if [ $RTE -eq 1 ] ; then
g.message "Importing Routes as points..."
- v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS"
+ v.in.ascii input="${TEMPFILE}.asc" output="$NAME" cat=0 columns="$ATTR_COLS"
EXITCODE=$?
fi
if [ $TRK -eq 1 ] ; then
if [ $GIS_FLAG_Z -eq 1 ] && [ "$HAVE_ALT" = "TRUE" ] ; then
g.message "Importing Track as 3D points..."
- v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS" -z z=5
+ v.in.ascii input="${TEMPFILE}.asc" output="$NAME" cat=0 columns="$ATTR_COLS" -z z=5
EXITCODE=$?
else
g.message "Importing Track as points..."
- v.in.ascii input="${TMP}.asc" output="$NAME" cat=0 columns="$ATTR_COLS"
+ v.in.ascii input="${TEMPFILE}.asc" output="$NAME" cat=0 columns="$ATTR_COLS"
EXITCODE=$?
fi
fi
if [ $EXITCODE -ne 0 ] ; then
g.message -e "While importing data with v.in.ascii"
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
@@ -515,32 +515,32 @@
#### prepare line components
if [ $RTE -eq 1 ] ; then
# add vertex counts
- cat "${TMP}.gpst" | sed -e '1d' | tac | awk 'BEGIN { FS="\t" ; R=0 } \
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | tac | awk 'BEGIN { FS="\t" ; R=0 } \
$1=="W" { printf(" %.7f %.7f\n", $6, $5) ; ++R } ; \
- $1=="R" { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TMP}.base"
+ $1=="R" { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TEMPFILE}.base"
# create attr table: cat(int), id number(int 0-19), name varchar(16+), starting_wpt(varchar 10)
- cat "${TMP}.gpst" | grep '^R' | cut -f2,3 | grep -n '^' | \
- sed -e 's/:/\t/' > "${TMP}.route_ids"
- cat "${TMP}.gpst" | sed -e '1d' | grep '^R' -A 1 | grep '^W' | cut -f2 > "${TMP}.route_start"
- paste "${TMP}.route_ids" "${TMP}.route_start" > "${TMP}.route_atts"
- ATTR_FILE="${TMP}.route_atts"
+ cat "${TEMPFILE}.gpst" | grep '^R' | cut -f2,3 | grep -n '^' | \
+ sed -e 's/:/\t/' > "${TEMPFILE}.route_ids"
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | grep '^R' -A 1 | grep '^W' | cut -f2 > "${TEMPFILE}.route_start"
+ paste "${TEMPFILE}.route_ids" "${TEMPFILE}.route_start" > "${TEMPFILE}.route_atts"
+ ATTR_FILE="${TEMPFILE}.route_atts"
ATTR_COLS='cat INT, route_id INT, name VARCHAR(20), start_wpt VARCHAR(10)'
elif [ $TRK -eq 1 ] ; then
# add vertex counts
- cat "${TMP}.gpst" | sed -e '1d' | tac | awk 'BEGIN { FS="\t" ; R=0 } \
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | tac | awk 'BEGIN { FS="\t" ; R=0 } \
$1=="T" { printf(" %.7f %.7f\n", $4, $3) ; ++R } ; \
- $1=="" { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TMP}.base"
+ $1=="" { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TEMPFILE}.base"
# create attr table: cat(int), start_time varchar(40), start_lat(double precision), start_lon(double precision), \
# end_time varchar(40), end_lat(double precision), end_lon(double precision)
- cat "${TMP}.gpst" | sed -e '1d' | grep '^$' -B 1 | grep '^T' | cut -f2,3,4 > "${TMP}.end_time"
- cat "${TMP}.gpst" | grep '^T' | tail -n 1 | cut -f2,3,4 >> "${TMP}.end_time"
- cat "${TMP}.gpst" | sed -e '1d' | grep '^$' -A 1 | grep '^T' | cut -f2,3,4 | \
- grep -n '^' | sed -e 's/:/\t/' > "${TMP}.start_time"
- paste "${TMP}.start_time" "${TMP}.end_time" > "${TMP}.track_atts"
- ATTR_FILE="${TMP}.track_atts"
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | grep '^$' -B 1 | grep '^T' | cut -f2,3,4 > "${TEMPFILE}.end_time"
+ cat "${TEMPFILE}.gpst" | grep '^T' | tail -n 1 | cut -f2,3,4 >> "${TEMPFILE}.end_time"
+ cat "${TEMPFILE}.gpst" | sed -e '1d' | grep '^$' -A 1 | grep '^T' | cut -f2,3,4 | \
+ grep -n '^' | sed -e 's/:/\t/' > "${TEMPFILE}.start_time"
+ paste "${TEMPFILE}.start_time" "${TEMPFILE}.end_time" > "${TEMPFILE}.track_atts"
+ ATTR_FILE="${TEMPFILE}.track_atts"
ATTR_COLS='cat INT, start_time VARCHAR(40), start_lat DOUBLE PRECISION, start_lon DOUBLE PRECISION, end_time VARCHAR(40), end_lat DOUBLE PRECISION, end_lon DOUBLE PRECISION'
fi
@@ -548,27 +548,27 @@
# gardump
if [ $RTE -eq 1 ] ; then
# add vertex counts
- grep -v '^\[\|^#' "${TMP}.gard" | tac | awk 'BEGIN { R=0 } \
+ grep -v '^\[\|^#' "${TEMPFILE}.gard" | tac | awk 'BEGIN { R=0 } \
/^[-0-9]/ { printf(" %.7f %.7f\n", $2, $1) ; ++R } ; \
- /^\*\*/ { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TMP}.base"
+ /^\*\*/ { printf("L %d 1\n", R) ; R=0 } END {;}' | tac > "${TEMPFILE}.base"
# create attr table: cat(int), id number(int 0-19), name varchar(40), starting_wpt(varchar 15)
# grep -n is to insert cat number, starting from 1. (route numbers start from 0)
- grep '^\*\*' "${TMP}.gard" | sed -e 's/^\*\*//' -e 's/ /|/' \
- | grep -n '^' | sed -e 's/:/|/' > "${TMP}.route_ids"
+ grep '^\*\*' "${TEMPFILE}.gard" | sed -e 's/^\*\*//' -e 's/ /|/' \
+ | grep -n '^' | sed -e 's/:/|/' > "${TEMPFILE}.route_ids"
- grep -A 1 '^\*\*' "${TMP}.gard" | grep -E -v '^\*\*|^--' | \
- sed -e 's/.* I://' | awk '{print $1}' > "${TMP}.route_start"
+ grep -A 1 '^\*\*' "${TEMPFILE}.gard" | grep -E -v '^\*\*|^--' | \
+ sed -e 's/.* I://' | awk '{print $1}' > "${TEMPFILE}.route_start"
- paste -d'|' "${TMP}.route_ids" "${TMP}.route_start" > "${TMP}.route_atts"
+ paste -d'|' "${TEMPFILE}.route_ids" "${TEMPFILE}.route_start" > "${TEMPFILE}.route_atts"
- ATTR_FILE="${TMP}.route_atts"
+ ATTR_FILE="${TEMPFILE}.route_atts"
ATTR_COLS='cat int, route_id INT, name VARCHAR(40), start_wpt VARCHAR(15)'
elif [ $TRK -eq 1 ] ; then
# add vertex counts
# some tracks don't have time/date, so we have to decide on the fly
- grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | tac | awk 'BEGIN { R=0 } \
+ grep -v '^\[\|^#\|^Track:' "${TEMPFILE}.gard" | tac | awk 'BEGIN { R=0 } \
! /start/ {
if($0 ~ /..:..:../ ) { printf(" %.7f %.7f\n", $4, $3) }
else { printf(" %.7f %.7f\n", $2, $1) }
@@ -580,7 +580,7 @@
else { printf(" %.7f %.7f\nL %d 1\n", $2, $1, R+1) }
R=0
}
- END {;}' | tac > "${TMP}.base"
+ END {;}' | tac > "${TEMPFILE}.base"
# create attr table: cat(int), \
# start_time varchar(40), start_lat(double precision), start_lon(double precision), \
@@ -592,16 +592,16 @@
# - use grep -n to add "line number: string" for cat as track nums start as 0
# crop out start times
- grep 'start$' "${TMP}.gard" | \
+ grep 'start$' "${TEMPFILE}.gard" | \
awk '{ if ( $0 ~ /..:..:../ ) {
print $1 "T" $2 "Z|" $3 "|" $4
} else {
print "|" $1 "|" $2
}
- }' | grep -n '^' | sed -e 's/:/|/' > "${TMP}.start_time"
+ }' | grep -n '^' | sed -e 's/:/|/' > "${TEMPFILE}.start_time"
# find and crop out end times. if only 1 pt in trk, use start as end time
- grep -v '^#\|^\[\|^Track:' "${TMP}.gard" | grep -B 1 'start$' | \
+ grep -v '^#\|^\[\|^Track:' "${TEMPFILE}.gard" | grep -B 1 'start$' | \
grep -v '^--' | awk 'BEGIN { FIRST=1 } \
/start/ {
if (FIRST != 1) { print TIME "|" LAT "|" LON } else { FIRST=0 } ;
@@ -617,49 +617,49 @@
} else {
TIME=""; LAT=$1; LON=$2
}
- }' > "${TMP}.end_time"
+ }' > "${TEMPFILE}.end_time"
# get time & coord of final point
- grep -B 1 'end transfer' "${TMP}.gard" | grep '^[0-9]' | awk \
+ grep -B 1 'end transfer' "${TEMPFILE}.gard" | grep '^[0-9]' | awk \
'{ if ( $0 ~ /..:..:../ ) {
print $1 "T" $2 "Z|" $3 "|" $4
} else {
print "|" $1 "|" $2
}
- }' >> "${TMP}.end_time"
+ }' >> "${TEMPFILE}.end_time"
ATTR_COLS='cat INT, start_time VARCHAR(40), start_lat DOUBLE PRECISION, start_lon DOUBLE PRECISION, end_time VARCHAR(40), end_lat DOUBLE PRECISION, end_lon DOUBLE PRECISION'
# check if there is any track name data
unset HAVE_TRACK_NAME
- if [ `grep -c '^Track:' "${TMP}.gard"` -ge 1 ] ; then
+ if [ `grep -c '^Track:' "${TEMPFILE}.gard"` -ge 1 ] ; then
HAVE_TRACK_NAME=TRUE
ATTR_COLS="$ATTR_COLS, track_name VARCHAR(15)"
# extract data for track name column
- grep -v '^\[\|^#' "${TMP}.gard" | grep '^Track:\|start' | awk \
+ grep -v '^\[\|^#' "${TEMPFILE}.gard" | grep '^Track:\|start' | awk \
'/^Track:/ {TRK=$0; sub(/^Track: /, "", TRK)} ;
- /^[-0-9]/ {print TRK}' > "$TMP.trackname"
- paste -d'|' "${TMP}.start_time" "${TMP}.end_time" "$TMP.trackname" > "${TMP}.track_atts"
+ /^[-0-9]/ {print TRK}' > "$TEMPFILE.trackname"
+ paste -d'|' "${TEMPFILE}.start_time" "${TEMPFILE}.end_time" "$TEMPFILE.trackname" > "${TEMPFILE}.track_atts"
else
HAVE_TRACK_NAME=FALSE
- paste -d'|' "${TMP}.start_time" "${TMP}.end_time" > "${TMP}.track_atts"
+ paste -d'|' "${TEMPFILE}.start_time" "${TEMPFILE}.end_time" > "${TEMPFILE}.track_atts"
fi
- ATTR_FILE="${TMP}.track_atts"
+ ATTR_FILE="${TEMPFILE}.track_atts"
fi
fi
#### reproject if needed
if [ -z "$IS_WGS84" ] || [ $KEEP_WGS84 -eq 1 ] ; then
g.message "No projection transformation performed"
- cat "${TMP}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
- $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TMP}.P_base"
+ cat "${TEMPFILE}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
+ $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TEMPFILE}.P_base"
else
g.message "Attempting waypoint projection transform with cs2cs..."
- cs2cs -tL -f %.7f $IN_PROJ +to $OUT_PROJ < "${TMP}.base" > "${TMP}.P_mid"
+ cs2cs -tL -f %.7f $IN_PROJ +to $OUT_PROJ < "${TEMPFILE}.base" > "${TEMPFILE}.P_mid"
EXITCODE=$?
# check if transform REALLY worked (e.g. grid file not found)
- BAD_PTS="`grep -c "^\*" "${TMP}.P_mid"`"
+ BAD_PTS="`grep -c "^\*" "${TEMPFILE}.P_mid"`"
if [ "$BAD_PTS" -gt 0 ] ; then
g.message message=""
g.message -w "$BAD_PTS vertices failed reprojection."
@@ -668,24 +668,24 @@
if [ $EXITCODE -ne 0 ] ; then
g.message -w "Projection transform failed, retaining WGS84"
g.message message=""
- cat "${TMP}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
- $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TMP}.P_base"
+ cat "${TEMPFILE}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
+ $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TEMPFILE}.P_base"
else
- cat "${TMP}.P_mid" | awk 'BEGIN {;} $1=="L" { print } ; \
- $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TMP}.P_base"
+ cat "${TEMPFILE}.P_mid" | awk 'BEGIN {;} $1=="L" { print } ; \
+ $1!="L" { printf(" %.7f %.7f\n", $1, $2) } END {;}' > "${TEMPFILE}.P_base"
fi
fi
# add category numbers
- cat "${TMP}.P_base" | awk 'BEGIN { FS=" " ; R=0 } \
+ cat "${TEMPFILE}.P_base" | awk 'BEGIN { FS=" " ; R=0 } \
$1=="L" { printf(" 1 %d\nL %d 1\n", R, $2) ; ++R } ; \
- $1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' > "${TMP}.P_baseC"
+ $1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' > "${TEMPFILE}.P_baseC"
# add z for 3D maps
unset HAVE_ALT
if [ $GIS_FLAG_Z -eq 1 ] ; then
# check if there is any altitude data
- if [ `grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | tr -s ' ' '|' | cut -f6 -d'|' | grep -c start` -ge 1 ] ; then
+ if [ `grep -v '^\[\|^#\|^Track:' "${TEMPFILE}.gard" | tr -s ' ' '|' | cut -f6 -d'|' | grep -c start` -ge 1 ] ; then
HAVE_ALT=TRUE
else
HAVE_ALT=FALSE
@@ -699,28 +699,28 @@
if [ "$HAVE_ALT" = "TRUE" ] ; then
# cut out altitude data and add blank lines between track lines
- grep -v '^\[\|^#\|^Track:' "${TMP}.gard" | tac | \
+ grep -v '^\[\|^#\|^Track:' "${TEMPFILE}.gard" | tac | \
awk '{ if($0 ~ /..:..:../ ) {
print $5 " " $6
} else {
print $3 " " $4
}
- }' | sed -e 's/ start/\n/' -e 's/ $//' | tac > "${TMP}.alt"
+ }' | sed -e 's/ start/\n/' -e 's/ $//' | tac > "${TEMPFILE}.alt"
- paste -d' ' "${TMP}.P_base" "${TMP}.alt" > "${TMP}.P_baseZ"
+ paste -d' ' "${TEMPFILE}.P_base" "${TEMPFILE}.alt" > "${TEMPFILE}.P_baseZ"
else
- cp "${TMP}.P_base" "${TMP}.P_baseZ"
+ cp "${TEMPFILE}.P_base" "${TEMPFILE}.P_baseZ"
fi
# add category numbers
- cat "${TMP}.P_baseZ" | awk 'BEGIN { FS=" " ; R=0 } \
+ cat "${TEMPFILE}.P_baseZ" | awk 'BEGIN { FS=" " ; R=0 } \
$1=="L" { printf(" 1 %d\nL %d 1\n", R, $2) ; ++R } ; \
$1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' \
- > "${TMP}.P_baseC"
+ > "${TEMPFILE}.P_baseC"
#### create digit header
- cat << EOF > "${TMP}.dig"
+ cat << EOF > "${TEMPFILE}.dig"
ORGANIZATION: GRASSroots organization
DIGIT DATE: `date "+%Y/%m/%d"`
DIGIT NAME: $PROG
@@ -734,12 +734,12 @@
EOF
#### merge in vertices
- cat "${TMP}.P_baseC" >> "${TMP}.dig"
+ cat "${TEMPFILE}.P_baseC" >> "${TEMPFILE}.dig"
#### if no name for vector file given, cat to stdout
if [ -z "$NAME" ] ; then
g.message "ASCII file redirected to stdout"
- cat "${TMP}.dig" 2> /dev/null
+ cat "${TEMPFILE}.dig" 2> /dev/null
else
#### import to binary vector file
if [ $GIS_FLAG_Z -eq 1 ] && [ "$HAVE_ALT" = "TRUE" ] ; then
@@ -749,14 +749,14 @@
fi
g.message "Importing with v.in.ascii..."
- v.in.ascii format=standard output="$NAME" input="${TMP}.dig" $ZFLAG
+ v.in.ascii format=standard output="$NAME" input="${TEMPFILE}.dig" $ZFLAG
#### check success/failure
if [ $? -eq 0 ] ; then
g.message -v message="Line vector <$NAME> successfully created"
else
g.message -e "An error occured creating <$NAME>, please check"'!'
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
@@ -771,7 +771,7 @@
echo "CREATE TABLE $NAME ($ATTR_COLS)" | db.execute
if [ $? -ne 0 ] ; then
g.message -e "Map created but failed to create database table."
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
@@ -810,7 +810,7 @@
# need to connect it before we can delete it. :-/
v.db.connect map="$NAME" table="$NAME" 2> /dev/null
v.db.droptable -f map=$NAME --quiet
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
### </hack>
@@ -832,7 +832,7 @@
v.support map="$NAME" cmdhist="${CMDLINE}"
#### clean up the mess
-\rm -f "${TMP}"*
+\rm -f "${TEMPFILE}"*
#### end
g.message "Done."
Modified: grass/branches/develbranch_6/scripts/v.in.gpsbabel/v.in.gpsbabel
===================================================================
--- grass/branches/develbranch_6/scripts/v.in.gpsbabel/v.in.gpsbabel 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.in.gpsbabel/v.in.gpsbabel 2010-01-27 05:12:20 UTC (rev 40690)
@@ -136,14 +136,14 @@
fi
#### set temporary files
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
#### trap ctrl-c so that we can clean up tmp
-trap 'rm -f "${TMP}."*' 2 3 15
+trap 'rm -f "${TEMPFILE}."*' 2 3 15
#### process command line arguments
@@ -171,13 +171,13 @@
if [ $GIS_FLAG_W -eq 1 ] && ([ $GIS_FLAG_R -eq 1 ] || [ $GIS_FLAG_T -eq 1 ]) ; then
g.message -e "One feature at a time please. Use v.patch if you need to combine them."
- rm -f "${TMP}"
+ rm -f "${TEMPFILE}"
exit 1
fi
# logic eludes me at pressent.. [combine with above]
if [ $GIS_FLAG_R -eq 1 ] && [ $GIS_FLAG_T -eq 1 ] ; then
g.message -e "One feature at a time please. Use v.patch if you need to combine them."
- rm -f "${TMP}"
+ rm -f "${TEMPFILE}"
exit 1
fi
@@ -221,7 +221,7 @@
if [ $PROJ_TYPE -eq 0 ] && [ $KEEP_WGS84 -ne 1 ] ; then
g.message -e "Cannot project to a XY location."
- rm -f "${TMP}"
+ rm -f "${TEMPFILE}"
exit 1
fi
@@ -251,12 +251,12 @@
fi
gpsbabel $TYPE -i $GIS_OPT_FORMAT -f "$GPSdevice" $PROGVERBOSE \
- -o xcsv,style="$STYLE" -F "$TMP".xcsv
+ -o xcsv,style="$STYLE" -F "$TEMPFILE".xcsv
EXITCODE=$?
- if [ "`wc -l < "${TMP}.xcsv"`" -eq 0 ] ; then
+ if [ "`wc -l < "${TEMPFILE}.xcsv"`" -eq 0 ] ; then
g.message -w 'No data! Exiting.'
- rm -f "${TMP}."*
+ rm -f "${TEMPFILE}."*
exit 0
fi
@@ -271,14 +271,14 @@
EXITCODE=$?
fi
gpsbabel $TYPE -i $GIS_OPT_FORMAT -f "$GPSdevice" $PROGVERBOSE \
- -o gpx -F "$TMP".gpx
+ -o gpx -F "$TEMPFILE".gpx
EXITCODE=$?
if [ $EXITCODE -eq 0 ] && \
- [ "`grep -c '<rte>' "${TMP}.gpx"`" -eq 0 ] && \
- [ "`grep -c '<trk>' "${TMP}.gpx"`" -eq 0 ] ; then
+ [ "`grep -c '<rte>' "${TEMPFILE}.gpx"`" -eq 0 ] && \
+ [ "`grep -c '<trk>' "${TEMPFILE}.gpx"`" -eq 0 ] ; then
g.message -e 'No data! Exiting.'
- rm -f "${TMP}."*
+ rm -f "${TEMPFILE}."*
exit 0
fi
fi
@@ -286,7 +286,7 @@
#### check success/failure
if [ $EXITCODE -ne 0 ] ; then
g.message -e "Error loading data from gpsbabel"
- rm -f "${TMP}."*
+ rm -f "${TEMPFILE}."*
exit 1
fi
@@ -295,25 +295,25 @@
if [ $CREATE_POINTS -eq 1 ] ; then
###################################
- cat "${TMP}.xcsv" | cut -f 1,2 -d '|'| tr '|' ' ' > "$TMP".base
+ cat "${TEMPFILE}.xcsv" | cut -f 1,2 -d '|'| tr '|' ' ' > "$TEMPFILE".base
# FIXME: if last field (comments) is empty it causes a not-enough fields error in v.in.ascii
# FIXME: if altitude column is empty (1st attr) v.in.ascii complains as the column type is defined as 'double'
- cat "${TMP}.xcsv" | tr '+' '|' | cut -f3,4,5,6 -d '|' | \
+ cat "${TEMPFILE}.xcsv" | tr '+' '|' | cut -f3,4,5,6 -d '|' | \
sed -e 's/-99999999.000000//' -e 's/|$/|_/' \
-e 's/01\/01\/1970|00:00:00 AM/|/' \
- -e 's/^|/-9999|/'> "$TMP".attributes
+ -e 's/^|/-9999|/'> "$TEMPFILE".attributes
#### reproject if needed
if [ "$IN_PROJ" = "$OUT_PROJ" ] || [ $KEEP_WGS84 -eq 1 ] ; then
g.message "No projection transformation performed"
- cp "${TMP}.base" "${TMP}.P_base"
+ cp "${TEMPFILE}.base" "${TEMPFILE}.P_base"
else
g.message "Attempting waypoint projection transform with cs2cs"
- cs2cs -f %.7f $IN_PROJ +to $OUT_PROJ < "${TMP}.base" > "${TMP}.P_base"
+ cs2cs -f %.7f $IN_PROJ +to $OUT_PROJ < "${TEMPFILE}.base" > "${TEMPFILE}.P_base"
EXITCODE=$?
# check if transform REALLY worked (e.g. when the grid file is not found)
- BAD_PTS="`grep -c "^\*" "${TMP}.P_base"`"
+ BAD_PTS="`grep -c "^\*" "${TEMPFILE}.P_base"`"
if [ "$BAD_PTS" -gt 0 ] ; then
g.message message=""
g.message -w "$BAD_PTS point(s) failed reprojection."
@@ -322,20 +322,20 @@
if [ $EXITCODE -ne 0 ] ; then
g.message -w "Projection transform failed, retaining WGS84"
g.message message=""
- cp -f "${TMP}.base" "${TMP}.P_base"
+ cp -f "${TEMPFILE}.base" "${TEMPFILE}.P_base"
fi
fi
- cat "${TMP}.P_base" | awk '{print $1 "|" $2}' > "${TMP}.vertices"
+ cat "${TEMPFILE}.P_base" | awk '{print $1 "|" $2}' > "${TEMPFILE}.vertices"
#### and put back together
# wpt list: x|y|<attr1>|...|<attr n>
- paste -d"|" "$TMP".vertices "$TMP".attributes > "$TMP".asc
+ paste -d"|" "$TEMPFILE".vertices "$TEMPFILE".attributes > "$TEMPFILE".asc
#### output or import
if [ -z "$NAME" ] ; then
g.message "ASCII file redirected to stdout"
- cat "${TMP}.asc" 2> /dev/null
+ cat "${TEMPFILE}.asc" 2> /dev/null
else
#### import into new points file
if [ $WPT -eq 1 ] ; then
@@ -346,14 +346,14 @@
g.message "Importing Tracks as points..."
fi
- v.in.ascii in="${TMP}.asc" output="$NAME" cat=0 \
+ v.in.ascii in="${TEMPFILE}.asc" output="$NAME" cat=0 \
columns='x double precision, y double precision, altitude double precision, gmt_date varchar(10), gmt_time varchar(11), comments varchar(40)'
EXITCODE=$?
# EXITCODE also used at pgm termination below!
if [ $EXITCODE -ne 0 ] ; then
g.message -e "While Importing data with v.in.ascii"
- rm -f "${TMP}"*
+ rm -f "${TEMPFILE}"*
exit 1
fi
fi
@@ -370,51 +370,51 @@
# if someone has any suggest please mail!!!!
# list of bytes where routes finish
- cat "$TMP.gpx" | grep -n "</rte>" > "$TMP.bytes"
+ cat "$TEMPFILE.gpx" | grep -n "</rte>" > "$TEMPFILE.bytes"
# number of routes
- cat "$TMP.bytes" | grep -c "</rte>" > "$TMP.var"
+ cat "$TEMPFILE.bytes" | grep -c "</rte>" > "$TEMPFILE.var"
ROUTE_NUMBER=0
- read ROUTE_NUMBER < "$TMP.var" # route number to process
+ read ROUTE_NUMBER < "$TEMPFILE.var" # route number to process
READ_BYTES=0 # offset of bytes already read
- cp "$TMP.gpx" "$TMP.gpx2" # file to be "eaten" by head commands in while
+ cp "$TEMPFILE.gpx" "$TEMPFILE.gpx2" # file to be "eaten" by head commands in while
ROUTE_ID=0 # route identifier
while [ "$ROUTE_NUMBER" -gt 0 ] ; do
- head -n 1 "$TMP.bytes" | cut -f 1 -d ':'> "$TMP.var"
+ head -n 1 "$TEMPFILE.bytes" | cut -f 1 -d ':'> "$TEMPFILE.var"
END_BYTE=0
- read END_BYTE < "$TMP.var" # this route ends at END_BYTE in $TMP.gpx file
+ read END_BYTE < "$TEMPFILE.var" # this route ends at END_BYTE in $TEMPFILE.gpx file
TO_READ=0
- TO_READ="`expr $END_BYTE - $READ_BYTES`" # bytes to read from $TMP.gpx2 file
+ TO_READ="`expr $END_BYTE - $READ_BYTES`" # bytes to read from $TEMPFILE.gpx2 file
READ_BYTES="`expr $READ_BYTES + $TO_READ`" # update readed bytes
# list of points in route
- head -n $TO_READ "$TMP.gpx2" | grep "<rtept" > "$TMP.points"
+ head -n $TO_READ "$TEMPFILE.gpx2" | grep "<rtept" > "$TEMPFILE.points"
POINTS=0 # number of points in route
- cat "$TMP.points" | grep -c "<rtept" > "$TMP.var"
- read POINTS < "$TMP.var"
- echo "L $POINTS 1" >> "$TMP.base"
+ cat "$TEMPFILE.points" | grep -c "<rtept" > "$TEMPFILE.var"
+ read POINTS < "$TEMPFILE.var"
+ echo "L $POINTS 1" >> "$TEMPFILE.base"
# read lat lon data
- cat "$TMP.points" | cut -f2 -d'<' | cut -f2,3 -d ' ' | cut -f2,4 -d '"' | tr '"' '\t' > "$TMP.latlon"
- cat "$TMP.latlon" | tr ',' '.' | awk '{printf(" %s %s\n", $2, $1) }' >> "$TMP.base"
+ cat "$TEMPFILE.points" | cut -f2 -d'<' | cut -f2,3 -d ' ' | cut -f2,4 -d '"' | tr '"' '\t' > "$TEMPFILE.latlon"
+ cat "$TEMPFILE.latlon" | tr ',' '.' | awk '{printf(" %s %s\n", $2, $1) }' >> "$TEMPFILE.base"
# create attribute line
- head -n $TO_READ "$TMP.gpx2" | grep -n "<rtept" | head -n 1 | cut -f1 -d ':' > "$TMP.var"
+ head -n $TO_READ "$TEMPFILE.gpx2" | grep -n "<rtept" | head -n 1 | cut -f1 -d ':' > "$TEMPFILE.var"
OFFSET=0
- read OFFSET < "$TMP.var"
- head -n $OFFSET "$TMP.gpx2" > "$TMP.rte_attr"
+ read OFFSET < "$TEMPFILE.var"
+ head -n $OFFSET "$TEMPFILE.gpx2" > "$TEMPFILE.rte_attr"
# read needed attributes
ROUTE_ID="`expr $ROUTE_ID + 1`"
- cat "$TMP.rte_attr"| grep "<number" | tail -n 1 | cut -f2 -d'<' | cut -f2 -d'>' > "$TMP.var"
+ cat "$TEMPFILE.rte_attr"| grep "<number" | tail -n 1 | cut -f2 -d'<' | cut -f2 -d'>' > "$TEMPFILE.var"
NUMBER=0
- read NUMBER < "$TMP.var" # read the route number
- cat "$TMP.rte_attr"| grep "<name" | tail -n 1 | cut -f2 -d'<' | cut -f2 -d'>' > "$TMP.var"
+ read NUMBER < "$TEMPFILE.var" # read the route number
+ cat "$TEMPFILE.rte_attr"| grep "<name" | tail -n 1 | cut -f2 -d'<' | cut -f2 -d'>' > "$TEMPFILE.var"
R_NAME=""
- read R_NAME < "$TMP.var" # read the route name
+ read R_NAME < "$TEMPFILE.var" # read the route name
OFFSET="`expr $TO_READ - $OFFSET`"
- head -n $TO_READ "$TMP.gpx2" | tail -n $OFFSET | grep "<name" | head -n 1 | cut -f2 -d'<' | cut -f2 -d'>' > "$TMP.var"
+ head -n $TO_READ "$TEMPFILE.gpx2" | tail -n $OFFSET | grep "<name" | head -n 1 | cut -f2 -d'<' | cut -f2 -d'>' > "$TEMPFILE.var"
START_PNT=""
- read START_PNT < "$TMP.var" # read the name of start point
+ read START_PNT < "$TEMPFILE.var" # read the name of start point
# check that numberic values don't try and pass an empty string
### variable names don't line up with column names ?!
@@ -427,84 +427,84 @@
g.message -w "Route $ROUTE_NUMBER: route ID was empty. Bug?"
fi
- echo "$ROUTE_ID|$NUMBER|$R_NAME|$START_PNT" >> "$TMP.route_atts"
+ echo "$ROUTE_ID|$NUMBER|$R_NAME|$START_PNT" >> "$TEMPFILE.route_atts"
ROUTE_NUMBER="`expr $ROUTE_NUMBER - 1`"
# eat files
- tail -n $ROUTE_NUMBER "$TMP.bytes" > "$TMP.bytes2"
- mv "$TMP.bytes2" "$TMP.bytes"
- head -n $TO_READ "$TMP.gpx2" > "$TMP.points"
+ tail -n $ROUTE_NUMBER "$TEMPFILE.bytes" > "$TEMPFILE.bytes2"
+ mv "$TEMPFILE.bytes2" "$TEMPFILE.bytes"
+ head -n $TO_READ "$TEMPFILE.gpx2" > "$TEMPFILE.points"
B_GPX=0
- wc -c < "$TMP.gpx2" > "$TMP.var"
- read B_GPX < "$TMP.var"
+ wc -c < "$TEMPFILE.gpx2" > "$TEMPFILE.var"
+ read B_GPX < "$TEMPFILE.var"
B_PNT=0
- wc -c < "$TMP.points" > "$TMP.var"
- read B_PNT < "$TMP.var"
+ wc -c < "$TEMPFILE.points" > "$TEMPFILE.var"
+ read B_PNT < "$TEMPFILE.var"
TO_READ="`expr $B_GPX - $B_PNT`"
- tail -c $TO_READ "$TMP.gpx2" > "$TMP.points"
- mv "$TMP.points" "$TMP.gpx2"
+ tail -c $TO_READ "$TEMPFILE.gpx2" > "$TEMPFILE.points"
+ mv "$TEMPFILE.points" "$TEMPFILE.gpx2"
done
# create attr table: cat(int), id number(int 0-19), name varchar(16+), starting_wpt(varchar 10)
- ATTR_FILE="${TMP}.route_atts"
+ ATTR_FILE="${TEMPFILE}.route_atts"
ATTR_COLS='cat int, route_id int, name varchar(40), start_wpt varchar(40)'
fi
if [ $TRK -eq 1 ] ; then
# list of bytes where tracks finish
- cat "$TMP.gpx" | grep -n "</trkseg>" > "$TMP.bytes"
+ cat "$TEMPFILE.gpx" | grep -n "</trkseg>" > "$TEMPFILE.bytes"
# number of tracks
- cat "$TMP.bytes" | grep -c "</trkseg>" > "$TMP.var"
+ cat "$TEMPFILE.bytes" | grep -c "</trkseg>" > "$TEMPFILE.var"
TRACK_NUMBER=0
- read TRACK_NUMBER < "$TMP.var" # route number to process
+ read TRACK_NUMBER < "$TEMPFILE.var" # route number to process
READ_BYTES=0 # offset of bytes already read
- cp "$TMP.gpx" "$TMP.gpx2" # file to be "eaten" by head commands in while
+ cp "$TEMPFILE.gpx" "$TEMPFILE.gpx2" # file to be "eaten" by head commands in while
TRACK_ID=0 # track identifier
while [ "$TRACK_NUMBER" -gt 0 ] ; do
- head -n 1 "$TMP.bytes" | cut -f 1 -d ':'> "$TMP.var"
+ head -n 1 "$TEMPFILE.bytes" | cut -f 1 -d ':'> "$TEMPFILE.var"
END_BYTE=0
- read END_BYTE < "$TMP.var" # this route ends at END_BYTE in $TMP.gpx file
+ read END_BYTE < "$TEMPFILE.var" # this route ends at END_BYTE in $TEMPFILE.gpx file
TO_READ=0
- TO_READ="`expr $END_BYTE - $READ_BYTES`" # bytes to read from $TMP.gpx2 file
+ TO_READ="`expr $END_BYTE - $READ_BYTES`" # bytes to read from $TEMPFILE.gpx2 file
READ_BYTES="`expr $READ_BYTES + $TO_READ`" # update readed bytes
# list of points in route
- head -n $TO_READ "$TMP.gpx2" | grep "<trkpt" > "$TMP.points"
+ head -n $TO_READ "$TEMPFILE.gpx2" | grep "<trkpt" > "$TEMPFILE.points"
POINTS=0 # number of points in track
- cat "$TMP.points" | grep -c "<trkpt" > "$TMP.var"
- read POINTS < "$TMP.var"
- echo "L $POINTS 1" >> "$TMP.base"
+ cat "$TEMPFILE.points" | grep -c "<trkpt" > "$TEMPFILE.var"
+ read POINTS < "$TEMPFILE.var"
+ echo "L $POINTS 1" >> "$TEMPFILE.base"
# read lat lon data
- cat "$TMP.points" | cut -f2 -d'<' | cut -f2,3 -d ' ' | cut -f2,4 -d '"' | tr '"' '\t' > "$TMP.latlon"
- cat "$TMP.latlon" | tr ',' '.' | awk '{printf(" %s %s\n", $2, $1) }' >> "$TMP.base"
+ cat "$TEMPFILE.points" | cut -f2 -d'<' | cut -f2,3 -d ' ' | cut -f2,4 -d '"' | tr '"' '\t' > "$TEMPFILE.latlon"
+ cat "$TEMPFILE.latlon" | tr ',' '.' | awk '{printf(" %s %s\n", $2, $1) }' >> "$TEMPFILE.base"
# create attribute line
- head -n $TO_READ "$TMP.gpx2" | grep -n "<trk" | head -n 1 | cut -f1 -d ':' > "$TMP.var"
+ head -n $TO_READ "$TEMPFILE.gpx2" | grep -n "<trk" | head -n 1 | cut -f1 -d ':' > "$TEMPFILE.var"
OFFSET=0
- read OFFSET < "$TMP.var"
+ read OFFSET < "$TEMPFILE.var"
S_LAT=""
- head -n 1 "$TMP.latlon" | cut -f1 > "$TMP.var"
- read S_LAT < "$TMP.var"
+ head -n 1 "$TEMPFILE.latlon" | cut -f1 > "$TEMPFILE.var"
+ read S_LAT < "$TEMPFILE.var"
S_LON=""
- head -n 1 "$TMP.latlon" | cut -f2 > "$TMP.var"
- read S_LON < "$TMP.var"
+ head -n 1 "$TEMPFILE.latlon" | cut -f2 > "$TEMPFILE.var"
+ read S_LON < "$TEMPFILE.var"
E_LAT=""
- tail -n 1 "$TMP.latlon" | cut -f1 > "$TMP.var"
- read E_LAT < "$TMP.var"
+ tail -n 1 "$TEMPFILE.latlon" | cut -f1 > "$TEMPFILE.var"
+ read E_LAT < "$TEMPFILE.var"
E_LON=""
- tail -n 1 "$TMP.latlon" | cut -f2 > "$TMP.var"
- read E_LON < "$TMP.var"
+ tail -n 1 "$TEMPFILE.latlon" | cut -f2 > "$TEMPFILE.var"
+ read E_LON < "$TEMPFILE.var"
OFFSET="`expr $TO_READ - $OFFSET`"
- head -n $TO_READ "$TMP.gpx2" | tail -n $OFFSET | grep "<time" > "$TMP.time"
+ head -n $TO_READ "$TEMPFILE.gpx2" | tail -n $OFFSET | grep "<time" > "$TEMPFILE.time"
S_TIME=""
- head -n 1 "$TMP.time" | cut -f 2 -d'>' | cut -f1 -d'<' > "$TMP.var"
- read S_TIME < "$TMP.var"
+ head -n 1 "$TEMPFILE.time" | cut -f 2 -d'>' | cut -f1 -d'<' > "$TEMPFILE.var"
+ read S_TIME < "$TEMPFILE.var"
E_TIME=""
- tail -n 1 "$TMP.time" | cut -f 2 -d'>' | cut -f1 -d'<' > "$TMP.var"
- read E_TIME < "$TMP.var"
+ tail -n 1 "$TEMPFILE.time" | cut -f 2 -d'>' | cut -f1 -d'<' > "$TEMPFILE.var"
+ read E_TIME < "$TEMPFILE.var"
TRACK_ID="`expr $TRACK_ID + 1`"
@@ -530,31 +530,31 @@
g.message -w "Track $TRACK_NUMBER: ending lon was empty. Bug?"
fi
- echo "$TRACK_ID|$S_TIME|$S_LAT|$S_LON|$E_TIME|$E_LAT|$E_LON" >> "$TMP.track_atts"
+ echo "$TRACK_ID|$S_TIME|$S_LAT|$S_LON|$E_TIME|$E_LAT|$E_LON" >> "$TEMPFILE.track_atts"
TRACK_NUMBER="`expr $TRACK_NUMBER - 1`"
# eat files
- tail -n $TRACK_NUMBER "$TMP.bytes" > "$TMP.bytes2"
- mv "$TMP.bytes2" "$TMP.bytes"
- head -n $TO_READ "$TMP.gpx2" > "$TMP.points"
+ tail -n $TRACK_NUMBER "$TEMPFILE.bytes" > "$TEMPFILE.bytes2"
+ mv "$TEMPFILE.bytes2" "$TEMPFILE.bytes"
+ head -n $TO_READ "$TEMPFILE.gpx2" > "$TEMPFILE.points"
B_GPX=0
- wc -c < "$TMP.gpx2" > "$TMP.var"
- read B_GPX < "$TMP.var"
+ wc -c < "$TEMPFILE.gpx2" > "$TEMPFILE.var"
+ read B_GPX < "$TEMPFILE.var"
B_PNT=0
- wc -c < "$TMP.points" > "$TMP.var"
- read B_PNT < "$TMP.var"
+ wc -c < "$TEMPFILE.points" > "$TEMPFILE.var"
+ read B_PNT < "$TEMPFILE.var"
TO_READ="`expr $B_GPX - $B_PNT`"
- tail -c $TO_READ "$TMP.gpx2" > "$TMP.points"
- mv "$TMP.points" "$TMP.gpx2"
+ tail -c $TO_READ "$TEMPFILE.gpx2" > "$TEMPFILE.points"
+ mv "$TEMPFILE.points" "$TEMPFILE.gpx2"
done
# create attr table: cat(int), start_time varchar(40), start_lat(double precision), start_lon(double precision), \
# end_time varchar(40), end_lat(double precision), end_lon(double precision)
- ATTR_FILE="${TMP}.track_atts"
+ ATTR_FILE="${TEMPFILE}.track_atts"
ATTR_COLS='cat int, start_time varchar(40), start_lat double precision, start_lon double precision, end_time varchar(40), end_lat double precision, end_lon double precision'
fi
@@ -562,14 +562,14 @@
#### reproject if needed
if [ "$IN_PROJ" = "$OUT_PROJ" ] || [ $KEEP_WGS84 -eq 1 ] ; then
g.message "No projection transformation performed"
- cat "${TMP}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
- $1!="L" { " %s %s\n", $1, $2) } END {;}' > "${TMP}.P_base"
+ cat "${TEMPFILE}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
+ $1!="L" { " %s %s\n", $1, $2) } END {;}' > "${TEMPFILE}.P_base"
else
g.message "Attempting waypoint projection transform with cs2cs"
- cs2cs -tL -f %.7f $IN_PROJ +to $OUT_PROJ < "${TMP}.base" > "${TMP}.P_mid"
+ cs2cs -tL -f %.7f $IN_PROJ +to $OUT_PROJ < "${TEMPFILE}.base" > "${TEMPFILE}.P_mid"
EXITCODE=$?
# check if transform REALLY worked (e.g. grid file not found)
- BAD_PTS="`grep -c "^\*" "${TMP}.P_mid"`"
+ BAD_PTS="`grep -c "^\*" "${TEMPFILE}.P_mid"`"
if [ "$BAD_PTS" -gt 0 ] ; then
g.message message=""
g.message -w "$BAD_PTS vertices failed reprojection."
@@ -578,22 +578,22 @@
if [ $EXITCODE -ne 0 ] ; then
g.message "Projection transform failed, retaining WGS84"
g.message message=""
- cat "${TMP}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
- $1!="L" { printf(" %s %s\n", $1, $2) } END {;}' > "${TMP}.P_base"
+ cat "${TEMPFILE}.base" | awk 'BEGIN {;} $1=="L" { print } ; \
+ $1!="L" { printf(" %s %s\n", $1, $2) } END {;}' > "${TEMPFILE}.P_base"
else
- cat "${TMP}.P_mid" | awk 'BEGIN {;} $1=="L" { print } ; \
- $1!="L" { printf(" %s %s\n", $1, $2) } END {;}' > "${TMP}.P_base"
+ cat "${TEMPFILE}.P_mid" | awk 'BEGIN {;} $1=="L" { print } ; \
+ $1!="L" { printf(" %s %s\n", $1, $2) } END {;}' > "${TEMPFILE}.P_base"
fi
fi
# add category numbers
- cat "${TMP}.P_base" | awk 'BEGIN { FS=" " ; R=0 } \
+ cat "${TEMPFILE}.P_base" | awk 'BEGIN { FS=" " ; R=0 } \
$1=="L" { printf(" 1 %d\nL %d 1\n", R, $2) ; ++R } ; \
- $1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' > "${TMP}.P_baseC"
+ $1!="L" { print } END { printf(" 1 %d\n", R) }' | sed -e '1d' > "${TEMPFILE}.P_baseC"
#### create digit header
- cat << EOF > "${TMP}.dig"
+ cat << EOF > "${TEMPFILE}.dig"
ORGANIZATION: GRASSroots organization
DIGIT DATE: `date "+%Y/%m/%d"`
DIGIT NAME: $PROG
@@ -608,16 +608,16 @@
#### merge in vertices
#HB#?? locale test fixed this
- cat "${TMP}.P_baseC" | tr ',' '.' >> "${TMP}.dig"
+ cat "${TEMPFILE}.P_baseC" | tr ',' '.' >> "${TEMPFILE}.dig"
#### if no name for vector file given, cat to stdout
if [ -z "$NAME" ] ; then
g.message "ASCII file redirected to stdout"
- cat "${TMP}.dig" 2> /dev/null
+ cat "${TEMPFILE}.dig" 2> /dev/null
else
#### import to binary vector file
g.message "Importing with v.in.ascii"
- v.in.ascii format=standard output="$NAME" input="${TMP}.dig"
+ v.in.ascii format=standard output="$NAME" input="${TEMPFILE}.dig"
#### check success/failure
if [ $? -eq 0 ] ; then
@@ -680,7 +680,7 @@
v.support map="$NAME" cmdhist="${CMDLINE}"
#### clean up the mess
-rm -f "${TMP}."* "${TMP}"
+rm -f "${TEMPFILE}."* "${TEMPFILE}"
#### end
g.message "Done."
Modified: grass/branches/develbranch_6/scripts/v.in.lines/v.in.lines
===================================================================
--- grass/branches/develbranch_6/scripts/v.in.lines/v.in.lines 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.in.lines/v.in.lines 2010-01-27 05:12:20 UTC (rev 40690)
@@ -58,14 +58,14 @@
#### setup temporary file
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "unable to create temporary files"
exit 1
fi
#### trap ctrl-c so that we can clean up tmp
-trap 'rm -f "$TMP"' 2 3 15
+trap 'rm -f "$TEMPFILE"' 2 3 15
#### parse field separator
if [ "$GIS_OPT_FS" = "space" ] || [ "$GIS_OPT_FS" = "tab" ] ; then
@@ -83,30 +83,30 @@
read REPLY
EXITCODE=$?
if [ -n "$REPLY" ] ; then
- echo "$REPLY" >> "$TMP.raw"
+ echo "$REPLY" >> "$TEMPFILE.raw"
fi
done
if [ "$fs" = " " ] ; then
- \mv -f "$TMP.raw" "$TMP"
+ \mv -f "$TEMPFILE.raw" "$TEMPFILE"
else
- tr "$fs" ' ' < "$TMP.raw" > "$TMP"
- \rm -f "$TMP.raw"
+ tr "$fs" ' ' < "$TEMPFILE.raw" > "$TEMPFILE"
+ \rm -f "$TEMPFILE.raw"
fi
# make sure we have at least one line of data
- if [ "`wc -l "$TMP" | cut -f1 -d' '`" -eq 0 ] ; then
+ if [ "`wc -l "$TEMPFILE" | cut -f1 -d' '`" -eq 0 ] ; then
g.message -e "Problem reading data from stdin"
exit 1
fi
- INFILE="$TMP"
+ INFILE="$TEMPFILE"
else
if [ "$fs" = " " ] ; then
INFILE="$GIS_OPT_INPUT"
else
- tr "$fs" ' ' < "$GIS_OPT_INPUT" > "$TMP"
- INFILE="$TMP"
+ tr "$fs" ' ' < "$GIS_OPT_INPUT" > "$TEMPFILE"
+ INFILE="$TEMPFILE"
fi
fi
@@ -119,7 +119,7 @@
if [ -z "`head -n 1 "$INFILE" | sed -e 's/[^ \t]*$//'`" ] ; then
g.message -e "Not enough data columns. (incorrect fs setting?)"
- rm -f "$TMP"
+ rm -f "$TEMPFILE"
exit 1
fi
@@ -127,7 +127,7 @@
EXITCODE=$?
#cleanup
-rm -f "$TMP"
+rm -f "$TEMPFILE"
exit $EXITCODE
Modified: grass/branches/develbranch_6/scripts/v.in.wfs/v.in.wfs
===================================================================
--- grass/branches/develbranch_6/scripts/v.in.wfs/v.in.wfs 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.in.wfs/v.in.wfs 2010-01-27 05:12:20 UTC (rev 40690)
@@ -61,28 +61,28 @@
exit 1
fi
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
-OUT=$GIS_OPT_output
+OUT="$GIS_OPT_output"
WFS_URL="$GIS_OPT_WFS"
g.message "Retrieving data ..."
-curl "$WFS_URL" > "$TMP.xml"
+curl "$WFS_URL" > "$TEMPFILE.xml"
-v.in.ogr dsn="$TMP.xml" out=$OUT -o
+v.in.ogr dsn="$TEMPFILE.xml" out=$OUT -o
if [ $? -ne 0 ] ; then
g.message -e "WFS-XML file not readable. Check if xerces-c support is compiled into GDAL/OGR library."
- rm -f "$TMP.xml" "$TMP" "$TMP.gfs"
+ rm -f "$TEMPFILE.xml" "$TEMPFILE" "$TEMPFILE.gfs"
exit 1
fi
-rm -f "$TMP.xml" "$TMP" "$TMP.gfs"
+rm -f "$TEMPFILE.xml" "$TEMPFILE" "$TEMPFILE.gfs"
-v.support $OUT cmdhist="${CMDLINE}"
+v.support "$OUT" cmdhist="${CMDLINE}"
g.message "Vector points map <$OUT> imported from WFS."
exit 0
Modified: grass/branches/develbranch_6/scripts/v.out.gpsbabel/v.out.gpsbabel
===================================================================
--- grass/branches/develbranch_6/scripts/v.out.gpsbabel/v.out.gpsbabel 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.out.gpsbabel/v.out.gpsbabel 2010-01-27 05:12:20 UTC (rev 40690)
@@ -150,8 +150,8 @@
#### set temporary files
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
@@ -160,7 +160,7 @@
cleanup()
{
g.message -v "Cleaning up ..."
- \rm -f "$TMP" "$TMP.gpx"
+ \rm -f "$TEMPFILE" "$TEMPFILE.gpx"
# only try to remove map if it exists to avoid ugly warnings
g.findfile element=vector file="tmp_vogb_epsg4326_$$" > /dev/null
if [ $? -eq 0 ] ; then
@@ -181,13 +181,13 @@
if [ $WPT -eq 1 ] && ([ $RTE -eq 1 ] || [ $TRK -eq 1 ]) ; then
g.message -e "One feature at a time please."
- rm -f "${TMP}"
+ rm -f "$TEMPFILE"
exit 1
fi
# logic eludes me at pressent.. [combine with above]
if [ $RTE -eq 1 ] && [ $TRK -eq 1 ] ; then
g.message -e "One feature at a time please."
- rm -f "${TMP}"
+ rm -f "$TEMPFILE"
exit 1
fi
@@ -310,7 +310,7 @@
g.message -v "Exporting data ..."
-v.out.ogr in="tmp_vogb_epsg4326_$$" dsn="$TMP.gpx" type="$GIS_OPT_TYPE" \
+v.out.ogr in="tmp_vogb_epsg4326_$$" dsn="$TEMPFILE.gpx" type="$GIS_OPT_TYPE" \
format=GPX ${LINETYPE} dsco="GPX_USE_EXTENSIONS=YES" --quiet
if [ $? -ne 0 ] ; then
@@ -321,7 +321,7 @@
if [ "$GIS_OPT_FORMAT" = gpx ] ; then
# short circuit, we have what we came for.
- mv -f "$TMP.gpx" "$GIS_OPT_OUTPUT"
+ mv -f "$TEMPFILE.gpx" "$GIS_OPT_OUTPUT"
cleanup
g.message -v "Fast exit."
exit 0
@@ -340,7 +340,7 @@
g.message -v "Running GpsBabel ..."
-gpsbabel $GTYPE -i gpx -f "$TMP.gpx" \
+gpsbabel $GTYPE -i gpx -f "$TEMPFILE.gpx" \
-o "$GIS_OPT_FORMAT" -F "$GIS_OPT_OUTPUT"
if [ $? -ne 0 ] ; then
Modified: grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats
===================================================================
--- grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.rast.stats/v.rast.stats 2010-01-27 05:12:20 UTC (rev 40690)
@@ -88,14 +88,14 @@
export LC_NUMERIC
#### setup temporary file
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
-SQLTMP="$TMP.sql"
+SQLTMP="$TEMPFILE.sql"
# we need a random name
-TMPNAME=`basename "$TMP"`
+TMPNAME=`basename "$TEMPFILE"`
cleanup()
{
@@ -108,7 +108,7 @@
g.message "Restoring previous MASK..."
g.rename "${TMPNAME}_origmask",MASK --quiet
fi
- rm -f "$TMP" "$TMPNAME" "$TMP.cats" "$SQLTMP"
+ rm -f "$TEMPFILE" "$TMPNAME" "$TEMPFILE.cats" "$SQLTMP"
}
# what to do in case of user break:
@@ -185,9 +185,9 @@
#dump cats to file to avoid "too many argument" problem:
-r.category "${VECTOR}_${TMPNAME}" fs=';' --quiet | cut -d';' -f1 > "$TMP.cats"
+r.category "${VECTOR}_${TMPNAME}" fs=';' --quiet | cut -d';' -f1 > "$TEMPFILE.cats"
#echo "List of categories found: $CATSLIST"
-NUMBER=`cat "$TMP.cats" | wc -l | awk '{print $1}'`
+NUMBER=`cat "$TEMPFILE.cats" | wc -l | awk '{print $1}'`
if [ $NUMBER -lt 1 ] ; then
g.message -e "No categories found in raster map"
cleanup
@@ -297,7 +297,7 @@
EXTSTAT=""
fi
-for i in `cat "$TMP.cats"` ; do
+for i in `cat "$TEMPFILE.cats"` ; do
g.message -v message="Processing category $i ($CURRNUM/$NUMBER)"
g.remove MASK --quiet 2>/dev/null
# r.mapcalc doesn't use the parser, so we set the env var version instead
Modified: grass/branches/develbranch_6/scripts/v.univar.sh/v.univar.sh
===================================================================
--- grass/branches/develbranch_6/scripts/v.univar.sh/v.univar.sh 2010-01-27 04:48:40 UTC (rev 40689)
+++ grass/branches/develbranch_6/scripts/v.univar.sh/v.univar.sh 2010-01-27 05:12:20 UTC (rev 40690)
@@ -80,15 +80,15 @@
export LC_NUMERIC
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
g.message -e "Unable to create temporary files"
exit 1
fi
cleanup()
{
- \rm -f "$TMP" "$TMP.sort"
+ \rm -f "$TEMPFILE" "$TEMPFILE.sort"
}
# what to do in case of user break:
@@ -118,9 +118,9 @@
fi
if [ -z "$GIS_OPT_WHERE" ] ; then
- db.select table="$GIS_OPT_TABLE" ${db} ${drv} sql="select $GIS_OPT_COLUMN from $GIS_OPT_TABLE" -c > "$TMP"
+ db.select table="$GIS_OPT_TABLE" ${db} ${drv} sql="select $GIS_OPT_COLUMN from $GIS_OPT_TABLE" -c > "$TEMPFILE"
else
- db.select table="$GIS_OPT_TABLE" ${db} ${drv} sql="select $GIS_OPT_COLUMN from $GIS_OPT_TABLE WHERE $GIS_OPT_WHERE" -c > "$TMP"
+ db.select table="$GIS_OPT_TABLE" ${db} ${drv} sql="select $GIS_OPT_COLUMN from $GIS_OPT_TABLE WHERE $GIS_OPT_WHERE" -c > "$TEMPFILE"
fi
@@ -133,7 +133,7 @@
#echo ""
#check if map contains only NULL's in current region
-LINES=`wc -l "$TMP" | awk '{print $1}'`
+LINES=`wc -l "$TEMPFILE" | awk '{print $1}'`
if [ "$LINES" -eq 0 ] ; then
g.message -e "Table $GIS_OPT_TABLE contains no data."
cleanup
@@ -142,7 +142,7 @@
# calculate statistics
g.message "Calculating statistics..."
-cat "$TMP" | awk 'BEGIN {sum = 0.0 ; sum2 = 0.0; min = 10e10 ; max = -min}
+cat "$TEMPFILE" | awk 'BEGIN {sum = 0.0 ; sum2 = 0.0; min = 10e10 ; max = -min}
function abs(x){return x < 0 ? -x : x}
(NF>0) {
sum += $1 ; sum2 += $1 * $1 ; sum3 += abs($1) ; N++;
@@ -170,14 +170,14 @@
if [ $GIS_FLAG_E -eq 1 ] ; then
#preparations:
- cat "$TMP" | sort -n > "$TMP.sort"
- NUMBER=`cat "$TMP.sort" | wc -l | awk '{print $1}'`
+ cat "$TEMPFILE" | sort -n > "$TEMPFILE.sort"
+ NUMBER=`cat "$TEMPFILE.sort" | wc -l | awk '{print $1}'`
ODDEVEN=`echo "$NUMBER" | awk '{print $1%2}'`
# 0.25 quartile
QUARTILE=0.25
QPOS=`echo $NUMBER $QUARTILE | awk '{printf "%d", $1 * $2 + 0.5}'`
- QELEMENT=`head -n $QPOS "$TMP.sort" | tail -n 1`
+ QELEMENT=`head -n $QPOS "$TEMPFILE.sort" | tail -n 1`
echo "1st Quartile: $QELEMENT"
#Calculate median
@@ -187,13 +187,13 @@
EVENMEDIANNUMBER=`expr $NUMBER / 2`
EVENMEDIANNUMBERPLUSONE=`expr $EVENMEDIANNUMBER + 1`
# select two numbers
- SELECTEDNUMBERS=`cat "$TMP.sort" | head -n $EVENMEDIANNUMBERPLUSONE | tail -n 2`
+ SELECTEDNUMBERS=`cat "$TEMPFILE.sort" | head -n $EVENMEDIANNUMBERPLUSONE | tail -n 2`
RESULTEVENMEDIAN=`echo $SELECTEDNUMBERS | awk '{printf "%f", ($1 + $2)/2.0}'`
echo "Median (even N): $RESULTEVENMEDIAN"
else
# odd
ODDMEDIANNUMBER=`echo $NUMBER | awk '{printf "%d", int($1/2+.5)}'`
- RESULTODDMEDIAN=`cat "$TMP.sort" | head -n $ODDMEDIANNUMBER | tail -n 1 | awk '{printf "%f", $1}'`
+ RESULTODDMEDIAN=`cat "$TEMPFILE.sort" | head -n $ODDMEDIANNUMBER | tail -n 1 | awk '{printf "%f", $1}'`
echo "Median (odd N): $RESULTODDMEDIAN"
fi
@@ -201,13 +201,13 @@
# 0.75 quartile
QUARTILE=0.75
QPOS=`echo $NUMBER $QUARTILE | awk '{printf "%d", $1 * $2 + 0.5}'`
- QELEMENT=`head -n $QPOS "$TMP.sort" | tail -n 1`
+ QELEMENT=`head -n $QPOS "$TEMPFILE.sort" | tail -n 1`
echo "3rd Quartile: $QELEMENT"
# 0.90 percentile
QUARTILE=0.9
QPOS=`echo $NUMBER $QUARTILE | awk '{printf "%d", $1 * $2 + 0.5}'`
- QELEMENT=`head -n $QPOS "$TMP.sort" | tail -n 1`
+ QELEMENT=`head -n $QPOS "$TEMPFILE.sort" | tail -n 1`
echo "90th Percentile: $QELEMENT"
fi
More information about the grass-commit
mailing list