#!/bin/bash

OPTIND=1

all=false
help=false
while getopts ":ah" opt
do
  case $opt in
    a) all=true ;;
    h) help=true ;;
    esac
done

shift $(($OPTIND - 1))

# sanity checks
if $help
then
  echo "Lists prepared BOXMOX mechanism."
  echo ""
  echo "Use -a to include mechanisms that are available but not yet prepared."
  exit 0
fi

# check if BOXMOX is correctly set up
validate_BOXMOX_installation || { echo "Validating BOXMOX installation failed"; exit 1; }

BOXMOX_MECH_PATH=${KPP_HOME}/compiled_mechs

if [ ! -z $(ls -A ${BOXMOX_MECH_PATH}) ]; then
  for mech in $(ls -1 -d ${BOXMOX_MECH_PATH}/*)
  do
    mechList+=($(basename $mech))
  done
fi

if $all
then
  for mech in $(ls -1 ${KPP_HOME}/models/*.eqn)
  do
    mechi=$(basename $mech)
    mechList+=(${mechi/.eqn/})
  done
fi

echo $( for i in "${mechList[@]}"; do echo $i; done | sort -u )

