[GRASS-SVN] r40689 - in grass/branches/develbranch_6/scripts: v.colors v.db.dropcol v.db.renamecol v.db.univar

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 26 23:48:44 EST 2010


Author: hamish
Date: 2010-01-26 23:48:40 -0500 (Tue, 26 Jan 2010)
New Revision: 40689

Modified:
   grass/branches/develbranch_6/scripts/v.colors/v.colors
   grass/branches/develbranch_6/scripts/v.db.dropcol/v.db.dropcol
   grass/branches/develbranch_6/scripts/v.db.renamecol/v.db.renamecol
   grass/branches/develbranch_6/scripts/v.db.univar/v.db.univar
Log:
rename TMP variable to avoid namespace collision on MS Windows (trac #890)

Modified: grass/branches/develbranch_6/scripts/v.colors/v.colors
===================================================================
--- grass/branches/develbranch_6/scripts/v.colors/v.colors	2010-01-27 04:38:47 UTC (rev 40688)
+++ grass/branches/develbranch_6/scripts/v.colors/v.colors	2010-01-27 04:48:40 UTC (rev 40689)
@@ -117,8 +117,8 @@
 
 cleanup()
 {
-   if [ -n "$TMP" ] ; then
-      \rm "$TMP" "${TMP}_vcol.sql"
+   if [ -n "$TEMPFILE" ] ; then
+      \rm "$TEMPFILE" "${TEMPFILE}_vcol.sql"
    fi
    eval `g.findfile elem=windows file="tmp_vcolors.$$" | grep '^name='`
    if [ -n "$name" ] ; then
@@ -278,8 +278,8 @@
 
 
 
-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 file"
     cleanup
     exit 1
@@ -295,21 +295,21 @@
       #g.message message="LINE=[$LINE]"
       VALUE=`echo $LINE | cut -f1 -d'|'`
       COLR=`echo $LINE | cut -f2 -d'|'`
-      echo "UPDATE $TABLE SET $GIS_OPT_RGB_COLUMN = '$COLR' WHERE $GIS_OPT_COLUMN = $VALUE;" >> "${TMP}_vcol.sql"
+      echo "UPDATE $TABLE SET $GIS_OPT_RGB_COLUMN = '$COLR' WHERE $GIS_OPT_COLUMN = $VALUE;" >> "${TEMPFILE}_vcol.sql"
   done )
 
 
-if [ ! -e "${TMP}_vcol.sql" ] ; then
+if [ ! -e "${TEMPFILE}_vcol.sql" ] ; then
     g.message -e "No values found in color range"
     cleanup
     exit 1
 fi
 
 # apply SQL commands to update the table with values
-NUM_RULES=`wc -l < "${TMP}_vcol.sql"`
+NUM_RULES=`wc -l < "${TEMPFILE}_vcol.sql"`
 g.message "Writing $NUM_RULES colors ..."
-#less "$TMP"
-db.execute input="${TMP}_vcol.sql"
+#less "$TEMPFILE"
+db.execute input="${TEMPFILE}_vcol.sql"
 if [ $? -ne 0 ] ; then
    g.message -e "Processing SQL transaction"
    cleanup

Modified: grass/branches/develbranch_6/scripts/v.db.dropcol/v.db.dropcol
===================================================================
--- grass/branches/develbranch_6/scripts/v.db.dropcol/v.db.dropcol	2010-01-27 04:38:47 UTC (rev 40688)
+++ grass/branches/develbranch_6/scripts/v.db.dropcol/v.db.dropcol	2010-01-27 04:48:40 UTC (rev 40689)
@@ -67,15 +67,15 @@
 PROG=`basename $0`
 
 #### 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
 
 cleanup()
 {
- \rm -f "$TMP" "$TMP.coltypes" "$TMP.colnames" "$TMP.coldesc"
+ \rm -f "$TEMPFILE" "$TEMPFILE.coltypes" "$TEMPFILE.colnames" "$TEMPFILE.coldesc"
 }
 
 # what to do in case of user break:
@@ -127,12 +127,12 @@
 if [ "$driver" = "sqlite" ] ; then
 	#echo "Using special trick for SQLite"
 	# http://www.sqlite.org/faq.html#q13
-	v.info --q -c map=$GIS_OPT_MAP layer=$GIS_OPT_LAYER | cut -d'|' -f1,2 | grep -v "|${col}$" > "$TMP.coldesc"
+	v.info --q -c map=$GIS_OPT_MAP layer=$GIS_OPT_LAYER | cut -d'|' -f1,2 | grep -v "|${col}$" > "$TEMPFILE.coldesc"
 	# need to revert order:
-	cat "$TMP.coldesc" | cut -d'|' -f1 > "$TMP.coltypes"
-	cat "$TMP.coldesc" | cut -d'|' -f2 > "$TMP.colnames"
-	COLDEF=`paste -d' ' "$TMP.colnames" "$TMP.coltypes" | tr '\n' ',' | sed 's+,$++g'`
-	COLNAMES=`cat "$TMP.colnames" | tr '\n' ',' | sed 's+,$++g'`
+	cat "$TEMPFILE.coldesc" | cut -d'|' -f1 > "$TEMPFILE.coltypes"
+	cat "$TEMPFILE.coldesc" | cut -d'|' -f2 > "$TEMPFILE.colnames"
+	COLDEF=`paste -d' ' "$TEMPFILE.colnames" "$TEMPFILE.coltypes" | tr '\n' ',' | sed 's+,$++g'`
+	COLNAMES=`cat "$TEMPFILE.colnames" | tr '\n' ',' | sed 's+,$++g'`
 echo "BEGIN TRANSACTION;
 CREATE TEMPORARY TABLE ${table}_backup(${COLDEF});
 INSERT INTO ${table}_backup SELECT ${COLNAMES} FROM ${table};
@@ -140,8 +140,8 @@
 CREATE TABLE ${table}(${COLDEF});
 INSERT INTO ${table} SELECT ${COLNAMES} FROM ${table}_backup;
 DROP TABLE ${table}_backup;
-COMMIT;" > "$TMP"
-	db.execute input="$TMP"
+COMMIT;" > "$TEMPFILE"
+	db.execute input="$TEMPFILE"
 	if [ $? -eq 1 ] ; then
 	    	g.message -e 'Cannot continue (problem deleting column)'
 	    	cleanup

Modified: grass/branches/develbranch_6/scripts/v.db.renamecol/v.db.renamecol
===================================================================
--- grass/branches/develbranch_6/scripts/v.db.renamecol/v.db.renamecol	2010-01-27 04:38:47 UTC (rev 40688)
+++ grass/branches/develbranch_6/scripts/v.db.renamecol/v.db.renamecol	2010-01-27 04:48:40 UTC (rev 40689)
@@ -63,33 +63,20 @@
 
 PROG=`basename $0`
 
-#### setup temporary file
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
-    g.message -e 'Unable to create temporary files'
-    exit 1
-fi
 
-cleanup()
-{
- \rm -f "$TMP" "$TMP.coltypes" "$TMP.colnames" "$TMP.coldesc"
-}
-
 # what to do in case of user break:
 exitprocedure()
 {
- g.message -e 'User break!'
- cleanup
- exit 1
+   g.message -e 'User break!'
+   exit 1
 }
 # shell check for user break (signal list: trap -l)
 trap "exitprocedure" 2 3 15
 
 error()
 {
-  g.message -e 'Cannot continue (problem renaming column)'
-  cleanup
-  exit 1
+   g.message -e 'Cannot continue (problem renaming column)'
+   exit 1
 }
 
 ### setup enviro vars ###
@@ -105,7 +92,6 @@
 table="`v.db.connect -g map="$GIS_OPT_MAP" fs=";" | grep -w "^$GIS_OPT_LAYER" | cut -f2 -d';'`"
 if [ -z "$table" ] ; then
    g.message -e 'There is no table connected to the input vector map! Cannot rename any column'
-   cleanup
    exit 1
 fi
 
@@ -122,7 +108,6 @@
   if [ "$NAMELEN" -gt 11 ] ; then
    g.message -e "Column name <$newcol> too long. The DBF driver supports column names\
     not longer than 10 characters"
-   cleanup
    exit 1
   fi
 fi
@@ -130,16 +115,14 @@
 if [ "$oldcol" = "$keycol" ] ; then
    g.message -e "Cannot rename column <$oldcol> as it is needed to keep table <$table>\
      connected to the input vector map"
-   cleanup
    exit 1
 fi
 
 # old col there?
 v.info --quiet -c map="$GIS_OPT_MAP" layer=$GIS_OPT_LAYER | cut -d'|' -f1,2 | grep "|${oldcol}$" 2>&1 >/dev/null
 if [ $? -ne 0 ] ; then
-	g.message -e "Column <$oldcol> not found in table"
-	cleanup
-	exit 1
+   g.message -e "Column <$oldcol> not found in table"
+   exit 1
 fi
 
 # describe old col
@@ -160,8 +143,6 @@
 	echo "ALTER TABLE $table RENAME $oldcol TO $newcol" | db.execute database="${database}" driver=${driver} || error
 fi
 
-# cleanup
-cleanup
 
 # write cmd history:
 v.support map="${GIS_OPT_MAP}" cmdhist="${CMDLINE}"

Modified: grass/branches/develbranch_6/scripts/v.db.univar/v.db.univar
===================================================================
--- grass/branches/develbranch_6/scripts/v.db.univar/v.db.univar	2010-01-27 04:38:47 UTC (rev 40688)
+++ grass/branches/develbranch_6/scripts/v.db.univar/v.db.univar	2010-01-27 04:48:40 UTC (rev 40689)
@@ -77,15 +77,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:
@@ -115,9 +115,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
 
 
@@ -130,7 +130,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
@@ -139,7 +139,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++;
@@ -167,14 +167,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
@@ -184,13 +184,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
 
@@ -198,13 +198,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