#!/bin/sh
#
# This script starts an IDL Runtime or Virtual Machine application
# from an IDL installation located in a subdirectory of the directory
# containing the script.
#


# Find the location of this script
topdir=`dirname $0`
if (test $topdir = ".") ; then
   topdir=$PWD;
fi

# Specify the path to the IDL SAVE file that launches
# the application, relative to $topdir.
idlapp=./dave.sav

# Specify the path to the top directory of the IDL
# distribution, relative to $topdir.
idl_install_dir=idl87
IDL_DIR=$topdir/$idl_install_dir ; export IDL_DIR

# Change the working directory
cd $topdir

# 01/09/14  Przemek/RTA
# In RHEL 6.5 DAVE segfaults b/c of the IDL bundled libxerces library used by the XML dlm.
# Workaround is to preload the system libxerces library
   if (! test -e /usr/lib/libxerces-c* && ! test -e /usr/lib64/libxerces-c* ); then
      echo 
      echo ##################################################################
      echo Need RHEL 6.5 version of libxerces-c library from xerces-c package
      echo ##################################################################
      exit
   fi
   echo "Pre-loading system xerces-c library for RHEL 6.5 ..."
   if (test -e /usr/lib/libxerces-c.so) ; then 
      LD_PRELOAD=/usr/lib/libxerces-c.so
   elif (test -e /usr/lib/libxerces-c-3.0.so); then
      LD_PRELOAD=/usr/lib/libxerces-c-3.0.so
   elif (test -e /usr/lib64/libxerces-c-3.0.so); then
      LD_PRELOAD=/usr/lib64/libxerces-c-3.0.so
   elif (test -e /usr/lib64/libxerces-c.so); then
      LD_PRELOAD=/usr/lib64/libxerces-c.so
   fi
   export LD_PRELOAD

# Run the application
exec $IDL_DIR/bin/idl -rt=$idlapp
