:

# nv2sites
# for making a sites file out of points piped from NVIZ to a file
# uses the Topo attribute as the first fp attribute
# uses the Color attribute as a second fp attribute

tempE=`g.tempfile pid=$$`
tempN=`g.tempfile pid=$$`
tempatt1=`g.tempfile pid=$$`
tempatt2=`g.tempfile pid=$$`

if [ $# = 0 ]
    then
    echo "USAGE: ${0} ascii_import_file [new_site_filename]"
    exit 0
fi
if [ $# = 1 ]
    then
    newname=nvimport.$$
fi
if [ $# = 2 ]
    then
    newname=$2
fi

if [ ! -d $LOCATION/site_lists ]
then
    mkdir $LOCATION/site_lists
fi
grep easting $1 | awk '{print $2}' > $tempE
grep northing $1 | awk '{print $2}' > $tempN
grep Topo $1 | awk '{ print $3 }' | sed 's=[\(\)]==g' > $tempatt1
grep Color $1 | awk '{ print $3 }' | sed 's=[\(\)]==g' > $tempatt2

outF="$LOCATION/site_lists/$newname"

echo "# This file created by $USER" > $outF
echo "# from query output of nviz" >> $outF
echo "labels|easting|northing|%elev%coloratt" >> $outF
echo "form|||%%" >> $outF
echo "time|" `date +"%e %b %Y"` >> $outF


paste $tempE $tempN $tempatt1 $tempatt2 | awk '{printf "%f|%f|%%%f %%%f\n", $1, $2, $3, $4}' >> $outF

echo 
echo CREATED SITES FILE $newname
echo $0 COMPLETE

