#!/bin/ksh
#
#  dlgx -- extract DLG data from tar files
#
#  usage:  dlgx tgzfile...
#
#  -- unpacks USGS *.sdts.tar.gz.* DLG tar files into current directory
#  -- renames TR* files that would otherwise overwrite each other
#  -- deletes DDF files not used by dlgvu  
#
#  22-june-2000/gmt


function rename {	# rename XX file
    for f in `tar tfz $2 | sed -n 's/^TR//p'`; do
    	mv TR$f $1$f
    done
    echo $2 '(renamed TR* to '$1'*)'
}


for t in $*; do
    gunzip <$t | tar xf -
    case "$t" in
    	*.MT.* | *_mt*)	rename MT $t;;
    	*.RR.* | *_rr*)	rename RR $t;;
    	*.RD.* | *_rd*)	rename RD $t;;
	*)		echo $t;;
    esac
    rm `find *.DDF \
    	! -name '????[AIX]???.DDF' \
	! -name '????[LN][EP]??.DDF' \
	! -name '????SPDM'.DDF`
done