[GRASS-SVN] r30139 - grass/branches/releasebranch_6_3/scripts/r.in.srtm

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 14 00:19:56 EST 2008


Author: hamish
Date: 2008-02-14 00:19:55 -0500 (Thu, 14 Feb 2008)
New Revision: 30139

Modified:
   grass/branches/releasebranch_6_3/scripts/r.in.srtm/r.in.srtm
Log:
replace 'file' with 'unzip -t' as 'file' isn't portable.


Modified: grass/branches/releasebranch_6_3/scripts/r.in.srtm/r.in.srtm
===================================================================
--- grass/branches/releasebranch_6_3/scripts/r.in.srtm/r.in.srtm	2008-02-14 05:18:53 UTC (rev 30138)
+++ grass/branches/releasebranch_6_3/scripts/r.in.srtm/r.in.srtm	2008-02-14 05:19:55 UTC (rev 30139)
@@ -115,12 +115,12 @@
 fi
 
 # use these from now on:
-FILE=`echo $GIS_OPT_INPUT | sed 's+.hgt++'| sed 's+.zip++'`
+FILE=`echo "$GIS_OPT_INPUT" | sed 's+.hgt++'| sed 's+.zip++'`
 TILE=`echo "$FILE" | sed 's+^.*/++'`
 FDIR=`echo "$FILE" | sed 's+[^/]*$++'`
 
 if [ -z "$GIS_OPT_OUTPUT" ] ; then
-  TILEOUT=$TILE
+  TILEOUT="$TILE"
 else
   TILEOUT="$GIS_OPT_OUTPUT"
 fi
@@ -128,13 +128,17 @@
 
 if [ -f "$FILE.hgt.zip" ] ; then
     #### check if we have unzip
-    if [ ! -x "`which unzip`" ] || [ ! -x "`which file`" ] ; then
-	g.message -e "\"unzip\" and \"file\" are required, please install them first"
+    if [ ! -x "`which unzip`" ] ; then
+	g.message -e "The \"unzip\" program is required, please install it first"
 	exit 1
     fi
 
     # really a ZIP file?
-    if [ "`file -ib "$FILE.hgt.zip"`" != "application/x-zip" ] ; then
+    # make it quiet in a safe way (just in case -qq isn't portable)
+    UNZIP=-qq
+    export UNZIP
+    unzip -t "$FILE.hgt.zip" 
+    if [ $? -ne 0 ] ; then
 	g.message -e "'$FILE.hgt.zip' does not appear to be a valid zip file."
 	exit 1
     fi
@@ -179,7 +183,7 @@
 fi
 
 g.message "Converting input file to BIL..."
-mv $TILE.hgt "$TMPDIR"/$TILE.bil
+mv "$TILE.hgt" "${TMPDIR}/$TILE.bil"
 
 LL_LATITUDE=`echo $TILE  | cut -b2-3`
 LL_LONGITUDE=`echo $TILE | cut -b5-7`
@@ -217,7 +221,7 @@
 ULXMAP $ULXMAP
 ULYMAP $ULYMAP
 XDIM 0.000833333333333
-YDIM 0.000833333333333"> $TILE.hdr
+YDIM 0.000833333333333"> "$TILE.hdr"
 else
   g.message "Attempting to import 1-arcsec data."
   echo "BYTEORDER M
@@ -234,18 +238,25 @@
 ULXMAP $ULXMAP
 ULYMAP $ULYMAP
 XDIM 0.000277777777777778
-YDIM 0.000277777777777778"> $TILE.hdr
+YDIM 0.000277777777777778"> "$TILE.hdr"
 fi
 
 #create prj file: To be precise, we would need EGS96! But who really cares...
 echo "GEOGCS["wgs84",DATUM["WGS_1984",SPHEROID["wgs84",6378137,298.257223563],TOWGS84[0.000000,0.000000,0.000000]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]" > $TILE.prj
 
-r.in.gdal in=$TILE.bil out=$TILEOUT
+r.in.gdal in="$TILE.bil" out="$TILEOUT"
+EXITCODE=$?
 
-\rm -f $TILE.bil $TILE.hdr $TILE.prj $TILE.hgt.zip
+\rm -f "$TILE.bil" "$TILE.hdr" "$TILE.prj" "$TILE.hgt.zip"
 cd ..
 rmdir "$TMPDIR"
 
+if [ "$EXITCODE" -ne 0 ] ; then
+   g.message -e "Unable to import data"
+   exit 1
+fi
+
+
 #nice color table #and zoom to tile
 r.colors color=srtm map="$TILEOUT"
 #g.region rast=$TILEOUT



More information about the grass-commit mailing list