#!/bin/sh
#################################################################
#  $Id: Make_start,v 1.10 2006/05/10 19:19:00 saroun Exp $
#  *****  creates starting script file for RESTRAX  *****
#
#  arguments are 
#  1) installation directory
#  2) program name (info only)
#  3) version number (info only)
#  4) build date (info only)
#
# Don't edit !
# Used internally by installation script "Install"
#
##################################################################
HOMEPAGE="http://omega.ujf.cas.cz/restrax"
INSTDIR=$1
PGMNAME=$2
VERSION=$3
BDATE=$4
ILL=$5
# Name of the output:
T=$INSTDIR/start$ILL

# check syntax
if [ "x$1" = "x" -o "x$2" = "x" -o "x$3" = "x" -o "x$4" = "x" ]; then 
	echo "Some arguments to Make_start are missing:"
	echo 
	echo " 1) installation directory"
	echo " 2) program name"
	echo " 3) version number"
	echo " 4) build date"
	exit
fi

############ Start output to the script file ##############
echo "#!/bin/sh" > $T
echo "# Set inst. directory, version, etc..." >> $T
echo "INSTDIR=\"$INSTDIR\"" >> $T
echo "VERSION=\"$VERSION\"" >> $T
echo "HOMEPAGE=\"$HOMEPAGE\"" >> $T

############ PART 1: intro label
cat >> $T << \EOD
EXCILIB=""
# Information about configuration/version
echo 
echo "---------------------------------------------------------" 
echo 
EOD
echo 'echo "'"$PGMNAME $VERSION, configured $BDATE"'"' >> $T
############ end 1           



############ PART 2: motd
cat >> $T << \EOD
# Message for users is printed from motd
echo 
echo "---------------------------------------------------------" 
echo 
if [ -f $INSTDIR/motd ] ; then
cat $INSTDIR/motd
echo "---------------------------------------------------------" 
echo "press ENTER to continue ..."
read ANSW
fi
EOD
############ end 2            

# optional menu for ILL instruments
if [ "x$ILL" = "xILL" ] ; then

############ PART 3: optional menu for instruments
cat >> $T << \EOD

# Select an instrument or choose a demo
# ---------------------------------------
echo 
echo "Select session/instrument:"
echo "--------------------------"
echo "1 ... IN1"
echo "2 ... IN3"
echo "3 ... IN8"
echo "4 ... IN12"
echo "5 ... IN14"
echo "6 ... IN20"
echo "7 ... demo"
read INST

NEWMENU="n"
case "${INST}" 
 in
  1) 
     CFGDIR="$INSTDIR/../IN1";;
  2) 
     CFGDIR="$INSTDIR/../IN3";;
  3) 
     CFGDIR="$INSTDIR/../IN8";;
  4) 
     CFGDIR="$INSTDIR/../IN12";;
  5) 
     CFGDIR="$INSTDIR/../IN14";;
  6) 
     CFGDIR="$INSTDIR/../IN20";;
  *) 
     NEWMENU="y";;
esac
EOD
############ end 3           

else
  echo "NEWMENU=\"y\"" >> $T
fi

############ PART 4: demo selection
cat >> $T << \EOD
# Select a demo sesssion or default
# ---------------------------------------
if [ "$NEWMENU" = "y" ] ; then     
echo 
echo "Select session/instrument:"
echo "--------------------------"
echo "1 ... default"
echo "2 ... demo, data fitting (damped oscillators)"
echo "3 ... demo, phonons in Si, maps of S(Q)"
echo "4 ... demo, phonons in Si, scans"
echo "5 ... demo, flatcone multianalyzer, incommensurate satellites"
# echo "6 ... demo, numerical optimization"
# echo "7 ... demo, simutaneous fitting of multiple data sets"
read INST
case "${INST}" 
 in
  2) 
     EXCILIB="res_exci_osc";
     CFGDIR="$INSTDIR/demo/osc";;
  3) 
     EXCILIB="res_exci_bcm";
     CFGDIR="$INSTDIR/demo/bcm";;
  4) 
     EXCILIB="res_exci_bcm";
     CFGDIR="$INSTDIR/demo/bcm_scan";;
  5) 
     EXCILIB="res_exci_incom";
     CFGDIR="$INSTDIR/demo/flatcone";;    
  6) 
     EXCILIB="res_exci_osc";
     CFGDIR="$INSTDIR/demo/opt";;     
  7) 
     EXCILIB="res_exci_osc1";
     CFGDIR="$INSTDIR/demo/multifit";;     
  *)
     CFGDIR="$INSTDIR/setup";;  
esac
fi
EOD
############ end 4          

############ PART 5: module selection and run
cat >> $T << \EOD
# Select initial EXCI module (if not selected before)
# ---------------------------------------------------
echo "NOTE:"
echo "To create own EXCI module with sample S(Q,E), get:" 
echo "$HOMEPAGE/download/restrax-$VERSION-exci.tar.gz"  
if [ "a$EXCILIB" = "a" ] ; then
	echo 
	echo Start with model : 
	echo ------------------
	echo "1 ... Damped oscillators"
	echo "2 ... Damped oscillators with free dispersion gradient"
	echo "3 ... BC model (phonons in Si, Ge, ...)"
	echo "4 ... Incommensurate satellites"
	echo "(use command EXCI to load another library at runtime)"
	read MODEL
	case "${MODEL}" 
	 in
	  1)
	     EXCILIB="res_exci_osc";;
	  2)
	     EXCILIB="res_exci_osc1";;
	  3) 
	     EXCILIB="res_exci_bcm";;
	  4) 
	     EXCILIB="res_exci_incom";;
	  *)
	     EXCILIB="res_exci_osc";;
	esac        
fi
echo 
# execute RESTRAX with selected options:
# pass start arguments to restrax_run
$INSTDIR/restrax_run $CFGDIR $EXCILIB "$@"

EOD
############ end 5          

# set privileges
chmod 755 $T
