#! /bin/sh
#-----------------------------------------------------------------------+
#									|
#   This material contains proprietary software of Entropic Speech,	|
#   Inc.  Any reproduction, distribution, or publication without the	|
#   prior written permission of Entropic Speech, Inc. is strictly	|
#   prohibited.  Any public distribution of copies of this work		|
#   authorized in writing by Entropic Speech, Inc. must bear the	|
#   notice								|
#									|
#    "Copyright (c) 1987 Entropic Speech, Inc. All rights reserved."	|
#									|
#-----------------------------------------------------------------------+
#									|
#  cover function for scatplot						|
#									|
#  by Rodney W. Johnson, Entropic Speech, Inc.				|
#									|
#  This command file runs the C program scatplot,			|
#  depending on the name by which the command file is invoked.  It	|
#  pipes the output through various filter combinations selected by	|
#  the -T option							|
#									|
#-----------------------------------------------------------------------+
# Sccs information: @(#)plot_script3	3.18 8/9/91 ESI

PLOTDIR1=$PLOTDIR$
PLOTDIR2=$PLOTDIR$
IPR=$PLOTCOMMAND$
SPSBIN=$SPSBIN$
MCD=$MCD$
XWIN=$XWIN$
GPSTOHP=$SPSBIN/gpstohp

MACH=`mach_type`
BACKGROUND="&" 

if test $XWIN = YES
then
	case $MACH in
	SUN3 | SUN4 | SUN386i)
		if test x$EPLOTDEV = xsuntools
	 	then
	  		XWIN=NO
			MCD=mcd
		fi ;;
	esac
fi

if test $XWIN = YES
 then
  MACH=HP
fi

case $BUNDLE in
"")
    STOU=$PLOTDIR1/stou ;;
*)
    STOU=$PLOTDIR1/stou\ -b$BUNDLE ;;
esac

PLOTAS=$PLOTDIR1/plotas
TPEN=$PLOTDIR1/tpen

case $0 in
scatplot)
    TITLE="ESPS Scatter Plot"
#    ICON=-iscatplot.icon
    XICON=" -iEPI "
    PLOT=$PLOTDIR2/scatplot ;;
*/scatplot)
    TITLE="ESPS Scatter Plot"
#    ICON=-iscatplot.icon
    XICON=" -iEPI "
    PLOT=$PLOTDIR2/scatplot ;;
esac


device=$MCD

if test $device = mcd -a `mach_type` = M5600
 then
  MCD=mcd
 else
  MCD=$SPSBIN/$MCD
fi

# Get command-line options and filenames.

WINOPT=" "
prevarg=
for i
do
    case $prevarg in
    -T)
	device=$i
	prevarg= ;;
    -t)
	command=$command" "\"$i\"
	prevarg= ;;
    -H)
	command=$command" "\"$i\"
	prevarg= ;;
    -V)
	command=$command" "\"$i\"
	prevarg= ;;
    -W)
        WINOPT=$i
        prevarg= ;;
    "")
	case $i in
	-x)
	    set -x
	    prevarg= ;;
	-T)
	    prevarg=-T ;;
	-T*)
	    device=`echo $i | awk '{print substr($0, 3)}'` ;;
	-t)
	    command=$command" "$i
	    prevarg=-t ;;
	-t*)
	    command=$command" "-t" "\"`echo $i \
				    | awk '{print substr($0, 3)}'`\" ;;
	-H)
	    command=$command" "$i
	    prevarg=-H ;;
	-H*)
	    command=$command" "-H" "\"`echo $i \
				    | awk '{print substr($0, 3)}'`\" ;;
	-V)
	    command=$command" "$i
	    prevarg=-V ;;
	-V*)
	    command=$command" "-V" "\"`echo $i \
				    | awk '{print substr($0, 3)}'`\" ;;
        -W)
            prevarg=-W ;;
        -W*)
            WINOPT=`echo $i | awk '{print substr($0, 3)}'` ;;

	-)
	    BACKGROUND=" " 
	    command=$command" "$i 
	    prevarg= ;;
	    
	*)
	    command=$command" "$i ;;
	esac;;
    esac
done

case $prevarg in
-T)
    echo $PLOT: -T requires argument.
    exit 1 ;;
-t)
    echo $PLOT: -t requires argument.
    exit 1 ;;
-H)
    echo $PLOT: -H requires argument.
    exit 1 ;;
-V)
    echo $PLOT: -V requires argument.
    exit 1 ;;
esac

if test $device = suntools -a \( `mach_type` = SUN3 -o `mach_type` = SUN4 \)
 then
  XWIN=NO
  SUNTOOLS=YES
  MCD=mcd
  device=mcd
fi

if test $device = mcd -a `mach_type` = M5600
 then
 XWIN=NO
 SUNTOOLS=NO
 MCD=mcd
 BACKGROUND=" "
fi


SUN=NO
case $MACH in
SUN3)	SUN=YES
	MCDOPT=-t" "\"$TITLE\""  "$ICON ;;
SUN4)	SUN=YES
	MCDOPT=-t" "\"$TITLE\""  "$ICON ;;
SUN386i)	SUN=YES
	MCDOPT=-t" "\"$TITLE\""  "$ICON ;;
HP)	SUN=NO
	MCDOPT=-t" "\"$TITLE\""  "$XICON ;;
*)	MCDOPT=" "
esac


# Build and execute command.

command=$PLOT" "$command

case $device in
gps)
    command=$command" | "$STOU
    sh -c "$command" ;;
mcd|mcdigh|xmcd)
    if test -n "$ESPS_TEMP_PATH"
    then 
	if test -d $ESPS_TEMP_PATH
	then
	  tmp=$ESPS_TEMP_PATH/plot$$
	else
	  tmp=/usr/tmp/plot$$
	fi
    else
	tmp=/usr/tmp/plot$$
    fi
    command=$command" >"$tmp
    eval "$command"
    if test -s $tmp
     then
	command=cat" "$tmp" | "$STOU" | "$MCD" "$MCDOPT" "$WINOPT" "$BACKGROUND
	eval "$command"
     else
	rm -f $tmp
	exit 1
    fi
    sleep 5
    rm -f $tmp ;;
tek)
    command=$command" | "$PLOTAS" | "$TPEN
    sh -c "$command" ;;
hardcopy|imagen)
    command=$command" | "$PLOTAS" | "$TPEN" | "$IPR
    sh -c "$command" ;;
hp)
    command=$command" | "$STOU" | "$GPSTOHP
    sh -c "$command" ;;
no_mcd)
    echo Cannot plot to screen in this version.
    echo Check installation parameters.
esac
exit 0
