#!/bin/bash
###############################################################################
#
# cutest2octave: build the bridge between CUTEst and Octave
#
# this is the modified cutest2matlab, written by Nick Gould, for Octave
#
# Romana Jezek, 2023
# produced as part of the project Derivative-Free Optimization funded
# by the Austrian Science Fund
###############################################################################

if [[ -z "$MYOCTAVEARCH" ]]; then
  if [[ -z "$MYARCH" ]]; then
    echo ' neither environment variable MYOCTAVEARCH nor MYARCH is set.'
    echo ' Set MYOCTAVEARCH as a gfortran-installed version from the list '
    /bin/ls -1 $CUTEST/versions 2>/dev/null
    echo ' and re-run.'
    exit 1
  else
    ARCH=${MYARCH}
  fi
else
  ARCH=${MYOCTAVEARCH}
fi
echo $ARCH

# check that the architecture provided in MYOCTAVEARCH or MYARCH exists

if [[ ! -e $CUTEST/versions/$ARCH ]] ; then
    echo ' The architecture provided by the environment variables MYOCTAVEARCH'
    echo '  and MYARCH has not been installed. Install a gfortran version of'
    echo ' CUTEst using install_cutest and re-run.'
    exit 2
fi


if [[ $# > 0 ]] ; then
  ${CUTEST}/bin/runcutest -A $ARCH -p octave -D $1
else
  ${CUTEST}/bin/runcutest -A $ARCH -p octave
fi
exit 0
