#!/bin/sh

# launcher for octave 3d geometry plotter

LIB="share/mcstas/tools/matlab/mcdisplay/"
TOOL="mcdisplay"
MCRUN="mcrun"
VERS="3.5"

canrun_o() {
    if ! [ -x ${LIB}/${TOOL}.m ]; then
        exit 127;
    fi
    
    # is octave on the path?
    if ! [ `which octave` ]; then
            exit 127;
    fi
}


if ( canrun_o ); then
    octave --eval "addpath('${LIB}');${TOOL} ${MCRUN} $* ; disp('--> Right-click in axis for toggles etc.'); disp('Press a key to exit mcdisplay-octave ...'); set(gcf,'closerequestfcn','exit'); pause"
else
    echo ":: Failed to run Octave ${TOOL}, trying default ${TOOL} instead."
    echo ":: If this fails too, consider reinstalling ${TOOL}."
    echo ""

    # Try old Perl-version of mcplot if Python version cannot run
    ${TOOL} $*
fi
