#!/usr/bin/env bash
#############################################
## This script will launch FakeRaT in the interactive mode.
## It will get the latest orbit and set the necessary
## environment variables for you. Just enjoy :)
#############################################
#############################################
## Set the environment variables
#############################################
FAKERAT_PATH=`readlink -f $0`
export FAKERAT_PATH=`dirname $FAKERAT_PATH`
export FAKERATLIB_PATH=`dirname $FAKERAT_PATH`/fakeratlib_180915
#export FAKERATLIB_PATH=`dirname $FAKERAT_PATH`/fakeratlib_180821
export PATH=$FAKERAT_PATH:$FAKERATLIB_PATH:$PATH
#############################################
## Check if PGPLOT_DIR is set
#############################################
if [ -z "$PGPLOT_DIR" ];then
 # Try to guess
 if [ -d /usr/lib/pgplot5 ];then
  export PGPLOT_DIR=/usr/lib/pgplot5/
 elif [ -d /usr/lib64/pgplot ];then
  export PGPLOT_DIR=/usr/lib64/pgplot
 else
  echo "
ERROR: the environment variable PGPLOT_DIR is not set!
Please install PGPLOT and set PGPLOT_DIR
"
 fi
fi
#############################################
# Change directory to where FakeRaT is
cd $FAKERAT_PATH
#############################################
## Update orbit
#############################################
#./autofake.sh update
#if [ $? -ne 0 ];then
# echo "
# ERROR running the automatic orbit update!!!!!!!!!!!!!!!
#
# ##### Please make sure you manually set up the latest orbit! #####
#
# " 
#fi
# The check below is actually obsolete as the new FakeRaT sets the orbit file from the menu
# Check that the orbit file is actually there
#if [ ! -f orbit/ra_orbit ];then
# echo "ERROR: the orbit file is not found at orbit/ra_orbit"
# exit 1
#fi
#############################################
## Run the original run script that will run FakeRaT
#############################################
./run -c
