set -o errexit

export ALLENSDK_PATH=/shared/bioapps/infoapps/lims2_modules/lib/allensdk

NEURON_HOME=/shared/utils.x86_64/nrn-7.4-1370
export PYTHONPATH=${NEURON_HOME}/lib/python:${ALLENSDK_PATH}:${PYTHONPATH}

export PYTHON_HOME=/shared/utils.x86_64/python-2.7
export PYTHON=${PYTHON_HOME}/bin/python
export PATH=${PYTHON_HOME}/bin:${NEURON_HOME}/x86_64/bin:${PATH}

IN_JSON=$1
OUT_JSON=$2

IN_JSON_ABSOLUTE=$(readlink -f ${IN_JSON})
BASEDIR=$(dirname ${IN_JSON_ABSOLUTE})
cd ${BASEDIR}
echo 'Directory changed to ' `pwd`

export SIMULATE="${PYTHON} -W ignore -m allensdk.internal.model.biophysical.run_simulate_lims"
MANIFEST=manifest_sdk.json

rm -rf x86_64 modfiles cell.hoc work ${MANIFEST}

${SIMULATE} generate_manifest_lims ${IN_JSON} ${MANIFEST}
${SIMULATE} copy_local ${MANIFEST} ${OUT_JSON}
${SIMULATE} nrnivmodl ${MANIFEST} ${OUT_JSON} 
${SIMULATE} start_specimen ${MANIFEST} ${OUT_JSON}

# clean up
rm -rf x86_64 modfiles cell.hoc work ${MANIFEST}
