#!/bin/ksh
#
# Wrapper for EDF - spd - programs (P.Boesecke).
# SPDVERSION 'new' | 'old' | 'current'
#
# Written by Els Homan (homan@embl-grenoble.fr)
#
# The executable is started in
# 
# SPDVERSION == "new": 
# get_arch == x86_64 : $progbase/new/`.get_os`_x86_64/$progname
# otherwise          : $progbase/new/`.get_os`/$progname
#
# SPDVERSION == "old":
# get_arch == x86_64 : $progbase/old/`.get_os`_x86_64/$progname
# otherwise          : $progbase/old/`.get_os`/$progname
# 
# SPDVERSION is anything else or not set:
# get_arch == x86_64 : $progbase/`.get_os`_x86_64/$progname
# otherwise          : $progbase/`.get_os`/$progname
#

if [ `expr ":$PATH:" : ".*:/sware/exp/saxs/bin:*"` -eq 0 ]; then
  export PATH=$PATH:/sware/exp/saxs/bin
fi
progname=`basename $0`
progbase=/sware/exp/saxs/spd

ostype=`/sware/exp/saxs/bin/.get_os`
if [ "$ostype" == "unknown system type" ]; then
  echo "Unknown system type."
  exit 1
fi

subdir=""
if [ "${SPDVERSION}" == "new" ]; then
  subdir="new/"
else if [ "${SPDVERSION}" == "old" ]; then
  subdir="old/"
  fi
fi

osarch="${ostype}"
prog2=${progbase}/${subdir}${ostype}/${progname}

architype=`/sware/exp/saxs/bin/.get_arch`
if [ "${architype}" == "x86_64" ]; then
  osarch="${ostype}_${architype}"
fi

prog1=${progbase}/${subdir}${osarch}/${progname}

if [ -a ${prog1} ]; then
  $prog1 ${1:+"$@"}
else 
  if [ -a ${prog2} ]; then
    echo "using " $prog2
    $prog2 ${1:+"$@"}
  else
    echo ${SPDVERSION} $progname "does not exist for "${ostype}" "${architype}
    exit 1
  fi
fi
