#!/bin/csh
#
# $Log: not supported by cvs2svn $
#
# Check arguments
if ("$1" == "") then
	echo "Usage: medmsetup <sddsfile>"
	exit 1
endif

# Define variables
set cdir = /tmp
set tmp1 = ${cdir}/medmsetup.tmp1.$USER
set tmp2 = ${cdir}/medmsetup.tmp2.$USER
set tmp3 = ${cdir}/medmsetup.tmp3.$USER
set tmp4 = ${cdir}/medmsetup.tmp4.$USER

# Check files
if !(-e $1 ) then
	echo "Cannot find $1"
	exit 1
endif

set check = `sddsquery -col $1 | grep MEDMArguments`
# Make Medm command
if ("$check" == "") then
 sddsprocess $1 $tmp1 \
   -print=column,MEDMCommand1,'medm -dg %hdx%hd+%hd+%hd -x %s/%s -xrm @*workspaceList: %s@ &',Width,Height,X,Y,Path,ScreenName,Workspace
else
 sddsprocess $1 $tmp1 \
   -print=column,MEDMCommand1,'medm -x %s -dg %hdx%hd+%hd+%hd -x %s/%s -xrm @*workspaceList: %s@ &',MEDMArguments,Width,Height,X,Y,Path,ScreenName,Workspace
endif

sddsprocess $tmp1 $tmp2 -edit=col,MEDMCommand,MEDMCommand1,%/0x0//

# Make a script file from MEDMCommand, leaving out the quotes
sdds2stream $tmp2 -column=MEDMCommand | tr -d \" | tr @ \" >! $tmp3

# Execute the script file
csh $tmp3
\rm $tmp1 $tmp2 $tmp3


