----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 11

The attached script will work for raster files. Enough seems to have
been said about vectors. If the script doesn't come across with your
mail program, contact me directly.

Tom

_______________________________
Tom D'Avello
USDA-NRCS, Champaign, IL
davello@sogis.il.nrcs.usda.gov
_______________________________
----------
X-Sun-Data-Type: shell-script
X-Sun-Data-Description: shell-script
X-Sun-Data-Name: grass2bil
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 90

#!/bin/sh
# This script reads a GRASS cellhd file and creates a "world" file and "header" file for
# display in ArcView or ArcInfo as a "bil" file. T. D'Avello 12/18/97.
# (Color schemes in GRASS won't replicate in AV)
# USAGE: grass2bil <raster_file>

if [ "${1}" = "" ]
    then
      echo "Enter GRASS raster FILENAME  "
       read FILENAME
	else
	 FILENAME=$1
fi

if [ "${FILENAME}" = "" ]
     then
       echo "ERROR: You MUST enter a filename.  -- Command aborted!"
	exit 4
fi


if [ ! -s $LOCATION/cellhd/${FILENAME} ]
   then
	echo "ERROR:  File not found"
	echo "ERROR:  Run this command in MAPSET containing data"
	exit 5
fi

cell=$LOCATION/cellhd

#  Get info from cellhd for bilw and hdr

res=`cut -c13- $cell/$FILENAME | sed -n '9p'` 

col=`cut -c13- $cell/$FILENAME | sed -n '7p'` 

row=`cut -c13- $cell/$FILENAME | sed -n '8p'` 

nrt=`cut -c13- $cell/$FILENAME | sed -n '3p'` 

wst=`cut -c13- $cell/$FILENAME | sed -n '6p'` 

compress=`cut -c13 $cell/$FILENAME | sed -n '12p'`

# check for compression status and uncompress if needed

 if [ "$compress" -eq 1 ]
   then
     r.compress -u map=$FILENAME
      echo "Uncompressing GRASS file"
 fi

# Make directory "BIL" to store resulting files

if [ ! -d $LOCATION/BIL ]
     then
     mkdir $LOCATION/BIL
fi

# Write Header file
echo "nrows $row" >> BIL/$FILENAME.hdr
echo "ncols $col" >> BIL/$FILENAME.hdr
echo "nbands 1" >> BIL/$FILENAME.hdr
echo "nbits 8" >> BIL/$FILENAME.hdr
echo "layout bil" >> BIL/$FILENAME.hdr
echo "skipbytes 0" >> BIL/$FILENAME.hdr
echo "bandrowbytes $col" >> BIL/$FILENAME.hdr
echo "totalrowbytes $col" >> BIL/$FILENAME.hdr


# Variables for world file
echo "$wst	$nrt	$res" > 1.tmp

# Write World file

ulx=`cat 1.tmp | awk '{ printf("%f",$1-($3*0.5)) }'`  
uly=`cat 1.tmp | awk '{ printf("%f",$2-($3*0.5)) }'`

echo "$res" >> BIL/$FILENAME.bilw
echo "0.0" >> BIL/$FILENAME.bilw
echo "0.0" >> BIL/$FILENAME.bilw
echo "-$res" >> BIL/$FILENAME.bilw
echo "$ulx" >> BIL/$FILENAME.bilw
echo "$uly" >> BIL/$FILENAME.bilw


cp $LOCATION/cell/$FILENAME BIL/$FILENAME.bil


rm 1.tmp

