[GRASS-SVN] r40687 - in grass/branches/develbranch_6/scripts: r.in.wms r.mask r.plane r.regression.line r.univar.sh

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


Author: hamish
Date: 2010-01-26 23:31:22 -0500 (Tue, 26 Jan 2010)
New Revision: 40687

Modified:
   grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp
   grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms
   grass/branches/develbranch_6/scripts/r.in.wms/wms.download
   grass/branches/develbranch_6/scripts/r.mask/r.mask
   grass/branches/develbranch_6/scripts/r.plane/r.plane
   grass/branches/develbranch_6/scripts/r.regression.line/r.regression.line
   grass/branches/develbranch_6/scripts/r.univar.sh/r.univar.sh
Log:
rename TMP variable to avoid namespace collision on MS Windows (trac #890)

Modified: grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.in.wms/r.in.gdalwarp	2010-01-27 04:31:22 UTC (rev 40687)
@@ -83,8 +83,8 @@
 g.message -d "[r.in.gdalwarp]"
 
 #### 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
@@ -96,7 +96,7 @@
 exitprocedure()
 {
 	g.message -e 'User break!'
-	rm -f "${TMP}"*
+	rm -f "${TEMPFILE}"*
 	exit 1
 }
 trap "exitprocedure" 2 3 15
@@ -118,7 +118,7 @@
 warpimport () {
 	FILE="$1"
 	MAP=$2
-	WARPFILE="${TMP}warped.geotiff"
+	WARPFILE="${TEMPFILE}warped.geotiff"
 	TMPMAPNAME=${2}_tmp
 
 	# Warp it and convert it to geotiff with alpha band to be sure we get nulls:
@@ -129,7 +129,7 @@
 
 	if [ $? -ne 0 ] ; then
 	    g.message -e message="`basename $0`: gdalwarp failure."
-	    rm -f "${TMP}"*
+	    rm -f "${TEMPFILE}"*
 	    exit 1
 	fi
 
@@ -137,7 +137,7 @@
 	r.in.gdal $FLAGS input="$WARPFILE" output="$TMPMAPNAME" --quiet
 	if [ $? -ne 0 ] ; then
 	    g.message -e message="`basename $0`: r.in.gdal failure."
-	    rm -f "${TMP}"*
+	    rm -f "${TEMPFILE}"*
 	    exit 1
 	fi
 
@@ -237,7 +237,7 @@
 	r.in.gdal -o $FLAGS input="$FILE" output="$MAP" --quiet
 	if [ $? -ne 0 ] ; then
 	    g.message -e message="`basename $0`: r.in.gdal failure."
-	    rm -f "${TMP}"*
+	    rm -f "${TEMPFILE}"*
 	    exit 1
 	fi
 
@@ -427,4 +427,4 @@
 fi
 
 # Clean up:
-rm -f "${TMP}"*
+rm -f "${TEMPFILE}"*

Modified: grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.in.wms/r.in.wms	2010-01-27 04:31:22 UTC (rev 40687)
@@ -199,8 +199,8 @@
 fi
 
 #### 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
@@ -283,7 +283,7 @@
 	# is this bogus? won't PATH revert on exit anyway?
 	PATH="$prevPATH"
 	export PATH
-	\rm -f "${TMP}"*
+	\rm -f "${TEMPFILE}"*
 	exit 1
 }
 trap "exitprocedure" 2 3 15
@@ -331,7 +331,7 @@
 
 listLayers() {
 
-	CAPABILITIES_FILE="${TMP}capabilities.xml"
+	CAPABILITIES_FILE="${TEMPFILE}capabilities.xml"
 
 	STRING="service=WMS&request=GetCapabilities&${GIS_OPT_WMSQUERY}";
 	g.message -d message="POST-data: [$STRING]"
@@ -354,7 +354,7 @@
 
 	    if [ ! -e "$CAPABILITIES_FILE" ] ; then
 		g.message -e "Downloading XML file"
-		\rm "$TMP"
+		\rm "$TEMPFILE"
 		exit 1
 	    fi
 
@@ -382,13 +382,13 @@
 
 	if [ ! -e "$CAPABILITIES_FILE" ] ; then
 	    g.message -e "Downloading XML file"
-	    \rm "$TMP"
+	    \rm "$TEMPFILE"
 	    exit 1
 	fi
 
 	if [ `wc -c < "$CAPABILITIES_FILE"` -eq 0 ] ; then
 	     g.message -e "Downloaded XML file was empty"
-	     \rm -f "$CAPABILITIES_FILE" "$TMP"
+	     \rm -f "$CAPABILITIES_FILE" "$TEMPFILE"
 	     exit 1
 	fi
 
@@ -402,7 +402,7 @@
 		      -e "s/.*Layer\\/Abstract=/  |/" \
 		      -e "s/.*Layer\\/Style\\/Name=/  STYLE: /" \
 		      -e "s/.*Layer\\/Style\\/Title=/    Style title: /" \
-		  > "${TMP}capabilities.txt"
+		  > "${TEMPFILE}capabilities.txt"
 
 	else : # xml2 is not available
 		g.message -w "The 'xml2' program was not found. Proceeding with internal XML parsing which may not be as reliable."
@@ -421,21 +421,21 @@
 		      -e "s/<Title>\(.*\)<\/Title>/\t --\1 /" \
 		      -e "s/<\/Title>//" \
 		      -e "s/<\/*.*\/*\/*>//" \
-		    > "${TMP}capabilities.txt"
+		    > "${TEMPFILE}capabilities.txt"
 	fi
 
-	if [ `wc -l < "${TMP}capabilities.txt"` -eq 0 ] ; then
+	if [ `wc -l < "${TEMPFILE}capabilities.txt"` -eq 0 ] ; then
 	    g.message message=""
 	    g.message -e "Parsing XML file"
 	    g.message message="------------------------"
 	    cat "$CAPABILITIES_FILE"
 	else
-	    cat "${TMP}capabilities.txt"
+	    cat "${TEMPFILE}capabilities.txt"
 	fi
 	g.message message=""
 
 	if [ -e "$CAPABILITIES_FILE" ] ; then
-	    \rm -f "${TMP}capabilities.txt" "$TMP"
+	    \rm -f "${TEMPFILE}capabilities.txt" "$TEMPFILE"
 
 	    if [ -n "$GIS_OPT_CAP_FILE" ] ; then
 		mv "$CAPABILITIES_FILE" "$GIS_OPT_CAP_FILE"
@@ -555,7 +555,7 @@
   g.message "#################################"
   cat "$FILES"
   g.message message=""
-  \rm -f "${TMP}"*
+  \rm -f "${TEMPFILE}"*
   exit 1
 fi
 
@@ -592,6 +592,6 @@
 g.message -v message="Map <${GIS_OPT_OUTPUT}> written"
 
 # Clean up:
-\rm -f "${TMP}"*
+\rm -f "${TEMPFILE}"*
 
 exit

Modified: grass/branches/develbranch_6/scripts/r.in.wms/wms.download
===================================================================
--- grass/branches/develbranch_6/scripts/r.in.wms/wms.download	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.in.wms/wms.download	2010-01-27 04:31:22 UTC (rev 40687)
@@ -64,8 +64,8 @@
 g.message -d "[wms.download]"
 
 #### 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
@@ -92,7 +92,7 @@
 exitprocedure()
 {
 	g.message -e 'User break!'
-	rm -f "${TMP}"*
+	rm -f "${TEMPFILE}"*
 	exit 1
 }
 trap "exitprocedure" 2 3 15
@@ -212,5 +212,5 @@
 GetTiles
 
 # Clean up:
-rm -f "${TMP}"*
+rm -f "${TEMPFILE}"*
 

Modified: grass/branches/develbranch_6/scripts/r.mask/r.mask
===================================================================
--- grass/branches/develbranch_6/scripts/r.mask/r.mask	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.mask/r.mask	2010-01-27 04:31:22 UTC (rev 40687)
@@ -58,11 +58,11 @@
 fi
 
 # temp file
-TMP="r_mask_$$"
+TEMPRAST="r_mask_$$"
 
 cleanup()
 {
- g.remove --q rast=$TMP
+ g.remove --q rast=$TEMPRAST
 }
 
 # what to do in case of user break:
@@ -113,9 +113,9 @@
 	fi
 
         if [ "$GIS_FLAG_I" -eq 1 ]; then
-		g.rename --q rast=MASK,$TMP
-		r.mapcalc "MASK=if(isnull($TMP),1,null())"
-		g.remove --q rast=$TMP
+		g.rename --q rast=MASK,$TEMPRAST
+		r.mapcalc "MASK=if(isnull($TEMPRAST),1,null())"
+		g.remove --q rast=$TEMPRAST
 		g.message "Inverted MASK created. All subsequent raster operations"
 	else
 	  g.message "MASK created. All subsequent raster operations"

Modified: grass/branches/develbranch_6/scripts/r.plane/r.plane
===================================================================
--- grass/branches/develbranch_6/scripts/r.plane/r.plane	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.plane/r.plane	2010-01-27 04:31:22 UTC (rev 40687)
@@ -86,14 +86,14 @@
 fi
 
 #### 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
 
 # setting environment, so that awk works properly in all languages
 unset LC_ALL
@@ -180,7 +180,7 @@
 
 
 ### now the actual algorithm in awk (stored in a temporary file) ###
-cat > "$TMP" << EOF
+cat > "$TEMPFILE" << EOF
 
 {
 if (NR==1) {
@@ -246,13 +246,13 @@
 
 ### execute awk and remove temporary file ###
 
-awk  -f "$TMP" -v east=$e west=$w north=$n south=$s ea=$ea no=$no typeflag=$typeflag \
-  nsres=$nsres ewres=$ewres  dip=$dip az=$az el=$el "$TMP" > "$TMP".2
+awk  -f "$TEMPFILE" -v east=$e west=$w north=$n south=$s ea=$ea no=$no typeflag=$typeflag \
+  nsres=$nsres ewres=$ewres  dip=$dip az=$az el=$el "$TEMPFILE" > "$TEMPFILE".2
 
-rm -f "$TMP"
+rm -f "$TEMPFILE"
 
 g.message "Running r.in.ascii, please stand by.."
-r.in.ascii `echo $typeflag` i="$TMP".2 o=$name
+r.in.ascii `echo $typeflag` i="$TEMPFILE".2 o=$name
 
 r.support $name hist="$PROG name=$name dip=$dip azimuth=$az easting=$ea \\"
 r.support $name hist="northing=$no elevation=$el type=$type"
@@ -263,5 +263,5 @@
   aspect=$az degrees ccw from north."
 #echo "$dat, user: $user"
 
-rm -f "$TMP".2
+rm -f "$TEMPFILE".2
 

Modified: grass/branches/develbranch_6/scripts/r.regression.line/r.regression.line
===================================================================
--- grass/branches/develbranch_6/scripts/r.regression.line/r.regression.line	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.regression.line/r.regression.line	2010-01-27 04:31:22 UTC (rev 40687)
@@ -86,8 +86,8 @@
  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
@@ -96,13 +96,13 @@
 #calculate regression equation
 if [ $GIS_FLAG_S -eq 1 ] ; then
    # slower but accurate
-   r.stats -n1  input=$GIS_OPT_MAP1,$GIS_OPT_MAP2 | sed 's+$+ 1+g' > "$TMP"
+   r.stats -n1  input=$GIS_OPT_MAP1,$GIS_OPT_MAP2 | sed 's+$+ 1+g' > "$TEMPFILE"
 else
    # count "identical" pixels
-   r.stats -cnA input=$GIS_OPT_MAP1,$GIS_OPT_MAP2  > "$TMP"
+   r.stats -cnA input=$GIS_OPT_MAP1,$GIS_OPT_MAP2  > "$TEMPFILE"
 fi
 
-if [ ! -s "$TMP" ] ; then
+if [ ! -s "$TEMPFILE" ] ; then
     g.message -e "One or both input maps only contain no data (NULL) pixels in the current region"
     exit 1
 fi
@@ -115,16 +115,16 @@
 mediaX=sumX/tot;sumsqX=sumsqX/tot;varX=sumsqX-(mediaX^2);sdX=varX^0.5;\
 mediaY=sumY/tot;sumsqY=sumsqY/tot;varY=sumsqY-(mediaY^2);sdY=varY^0.5;\
 A=mediaY - B*mediaX; F= R^2/(1-R^2/tot-2);\
-print A, B, R, tot, F, mediaX, sdX, mediaY, sdY}' "$TMP" > "$TMP"b
+print A, B, R, tot, F, mediaX, sdX, mediaY, sdY}' "$TEMPFILE" > "$TEMPFILE"b
 
-echo "a b R N F medX sdX medY sdY" | tr -s ' ' '\n' > "$TMP"d
-cat "$TMP"b | tr -s ' ' '\n' > "$TMP"e
+echo "a b R N F medX sdX medY sdY" | tr -s ' ' '\n' > "$TEMPFILE"d
+cat "$TEMPFILE"b | tr -s ' ' '\n' > "$TEMPFILE"e
 
 #send output to screen or text file
 if [ -z "$GIS_OPT_OUTPUT" ] 
 then
 	if [ $GIS_FLAG_G -eq 1 ] ; then
-	   paste -d'=' "$TMP"d "$TMP"e
+	   paste -d'=' "$TEMPFILE"d "$TEMPFILE"e
 	else
 	   echo "y = a + b*x"
            echo "   a: offset"
@@ -134,24 +134,24 @@
            echo "   medX, medY: Means"
            echo "   sdX, sdY: Standard deviations"
            echo "a  b  R  N  F medX  sdX  medY  sdY"
-	   RESULTADO=`cat "$TMP"b`
+	   RESULTADO=`cat "$TEMPFILE"b`
            echo ${RESULTADO}
 	fi
 else
 	if [ $GIS_FLAG_G -eq 1 ] ; then
-	   paste -d'=' "$TMP"d "$TMP"e >> "$TMP"c
+	   paste -d'=' "$TEMPFILE"d "$TEMPFILE"e >> "$TEMPFILE"c
 	else
-	   echo "y = a + b*x" > "$TMP"c
-           echo "   a: offset" >> "$TMP"c
-           echo "   b: gain" >> "$TMP"c
-           echo "   R: sumXY - sumX*sumY/tot" >> "$TMP"c
-           echo "   N: number of elements" >> "$TMP"c
-           echo "   medX, medY: Means" >> "$TMP"c
-           echo "   sdX, sdY: Standard deviations" >> "$TMP"c
-           echo "a  b  R  N  F medX  sdX  medY  sdY" >> "$TMP"c
-	   cat "$TMP"b >> "$TMP"c
+	   echo "y = a + b*x" > "$TEMPFILE"c
+           echo "   a: offset" >> "$TEMPFILE"c
+           echo "   b: gain" >> "$TEMPFILE"c
+           echo "   R: sumXY - sumX*sumY/tot" >> "$TEMPFILE"c
+           echo "   N: number of elements" >> "$TEMPFILE"c
+           echo "   medX, medY: Means" >> "$TEMPFILE"c
+           echo "   sdX, sdY: Standard deviations" >> "$TEMPFILE"c
+           echo "a  b  R  N  F medX  sdX  medY  sdY" >> "$TEMPFILE"c
+	   cat "$TEMPFILE"b >> "$TEMPFILE"c
 	fi
-	mv "$TMP"c "$GIS_OPT_OUTPUT"
+	mv "$TEMPFILE"c "$GIS_OPT_OUTPUT"
 	cat "$GIS_OPT_OUTPUT"
 fi
-rm -f "$TMP" "$TMP"b "$TMP"c "$TMP"d "$TMP"e
+rm -f "$TEMPFILE" "$TEMPFILE"b "$TEMPFILE"c "$TEMPFILE"d "$TEMPFILE"e

Modified: grass/branches/develbranch_6/scripts/r.univar.sh/r.univar.sh
===================================================================
--- grass/branches/develbranch_6/scripts/r.univar.sh/r.univar.sh	2010-01-27 04:15:08 UTC (rev 40686)
+++ grass/branches/develbranch_6/scripts/r.univar.sh/r.univar.sh	2010-01-27 04:31:22 UTC (rev 40687)
@@ -65,8 +65,8 @@
 
 COVER="$GIS_OPT_MAP"
 
-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
@@ -74,7 +74,7 @@
 
 cleanup()
 {
-   \rm -f "$TMP" "$TMP.sort"
+   \rm -f "$TEMPFILE" "$TEMPFILE.sort"
 }
 
 # what to do in case of user break:
@@ -89,10 +89,10 @@
 
 g.message "Calculation for map $COVER (ignoring NULL cells)..."
 g.message "Reading raster map..."
-r.stats -1n input=$COVER > "$TMP"
+r.stats -1n input=$COVER > "$TEMPFILE"
 
 #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 "Map $COVER contains only NULL data in current region."
  cleanup
@@ -101,7 +101,7 @@
 
 # calculate statistics
 g.message "Calculating statistics..."
-cat "$TMP" | awk 'BEGIN {sum = 0.0 ; sum2 = 0.0}
+cat "$TEMPFILE" | awk 'BEGIN {sum = 0.0 ; sum2 = 0.0}
 function abs(x){return x < 0 ? -x : x}
 NR == 1{min = $1 ; max = $1}
        {sum += $1 ; sum2 += $1 * $1 ; sum3 += abs($1) ; N++}
@@ -124,14 +124,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
@@ -141,13 +141,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
 
@@ -155,13 +155,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"
 
   # XX percentile
   QUARTILE=$GIS_OPT_PERCENTILE
   QPOS=`echo $NUMBER $QUARTILE | awk '{printf "%d", $1 * $2/100. + 0.5}'`
-  QELEMENT=`head -n $QPOS "$TMP.sort" | tail -1`
+  QELEMENT=`head -n $QPOS "$TEMPFILE.sort" | tail -1`
   echo "${GIS_OPT_PERCENTILE} Percentile: $QELEMENT"
 
 fi



More information about the grass-commit mailing list