#!/bin/bash

if [ -d /afs/slac/g/lcls ]; then
    export LCLS_ROOT=/afs/slac/g/lcls
else
    export LCLS_ROOT=/usr/local/lcls
fi

if [ -f $TOOLS/oracle/oracleSetup.bash ]; then
    source $TOOLS/oracle/oracleSetup.bash
fi
if [ -f $PHYSICS_TOP/setup/javaSetup.bash ]; then
    source $PHYSICS_TOP/setup/javaSetup.bash
fi

if [ -f $EPICS_SETUP/fixed-epics-setup.bash ]; then
    source $EPICS_SETUP/fixed-epics-setup.bash
    if [ -f ${LCLS_ROOT}/epics/setup/epicsenv-3.14.12.bash ]; then
        source ${LCLS_ROOT}/epics/setup/epicsenv-3.14.12.bash
    fi
fi


invokeMatlabSetup() {
    export MATLAB_VER=2012a
    local EPICS_HOST_ARCH=linux-x86
    if [ -f $TOOLS/matlab/setup/matlabSetup.bash ]; then
        source $TOOLS/matlab/setup/matlabSetup.bash
    fi
}

invokeMatlabSetup

TYPE=$1
if [ "$#" -eq 1 ]; then
    echo "Running: vvs20_30Ramp('${TYPE,,}')"
    /usr/local/matlab/2012a/bin/matlab -glnx86 -nosplash -nodesktop -r "vvs20_30Ramp('${TYPE,,}')"
elif [ "$#" -eq 2 ]; then
    LOCATION=$2
    echo "Running: vvs20_30Ramp('${TYPE,,}', '${LOCATION^^}')"
    /usr/local/matlab/2012a/bin/matlab -glnx86 -nosplash -nodesktop -r "vvs20_30Ramp('${TYPE,,}', '${LOCATION^^}')"
else
    echo -e "Incorrect number of arguments.\nUsage: vvs20_30Ramp TYPE [LOCATION]"
    exit 1
fi
