# version for UNIX / LINUX (using the bash shell)
#
# Use: runalabb filename [list of filenames]
#
#       filename     name of a file containing the definition
#                    definition for the problem of interest.
#

export ALABB=$HOME/Desktop/bmpru

export SRC=$ALABB/src
export INTLIB=$ALABB/intlib
export PROBS=$ALABB/problems

export BLAS=$ALABB/blas
export LAPACK=$ALABB/lapack

export QP=$ALABB/qp
export GENLIN=$ALABB/genlin
export SIMPLEX=$ALABB/nr-simplx
export MINOS=$ALABB/minos

export CURREN=$ALABB/experiments

if [ ! -e $CURREN/alabb-table.out ] ; then

  touch $CURREN/alabb-table.out ;

fi

if (( $# == 0 )) ; then

  echo 'Syntax: runalabb filename [list of filenames],'
  echo 'where filename is the name of a file containing '
  echo 'the definition for the problem of interest. '

else

  for i in $*

    do

    if [ ! -e $PROBS/${i}.f ] ; then

      echo "file ${i}.f does not exist in "$PROBS" directory"

    else

      gfortran -O4 $INTLIB/*.o $BLAS/*.o $LAPACK/*.o $MINOS/minos.o \
           $QP/*.o $GENLIN/genlin.o $SIMPLEX/*.o $SRC/*.o $PROBS/${i}.f \
           -o alabbma

#     ulimit -St 3600
      ulimit -St unlimited

      $CURREN/alabbma

      ulimit -St unlimited

      if [ -e $CURREN/alabb-tabline.out ] ; then

        printf "%8s" $i               >> $CURREN/alabb-table.out ;
        cat $CURREN/alabb-tabline.out >> $CURREN/alabb-table.out ;

      else

        if [ -e $CURREN/abb-tabline.out ] ; then

          printf "%8s" $i             >> $CURREN/alabb-table.out ;
          cat $CURREN/abb-tabline.out >> $CURREN/alabb-table.out ;

        else

          printf "%8s  300.00   5 " $i      >> $CURREN/alabb-table.out ;
          printf "NO INFORMATION AT ALL\n"  >> $CURREN/alabb-table.out ;

        fi

      fi

      rm -f $CURREN/alabbma $CURREN/alabb.out \
            $CURREN/alabb-tabline.out $CURREN/abb-tabline.out

    fi

    done

fi
