#!/bin/ksh
#
#--------------------------------------------------------------------------------#
#
# Current revisions:
# ------------------
# 
# 
# Former revisions:
# -----------------
# $Id: run_kpp4palm.ksh 2603 2017-11-03 17:44:45Z forkel $ 
#
# 
# Small adaptations (added MECH as argument, re-introduced relative path,
#                    adaption to changing kp4 to kpp4palm)
# filename changed from run_kp4.ksh to run_kpp4palm.ksh
# 
# 
# 
#
# Nov. 2016: Initial Version of KPP chemistry by Klaus Ketelsen
#

echo "\$1 = " $1 

if [[ $1 == "clean" ]]
then
  cd kpp
  make distclean
  cd ..

  cd kpp4palm
  make distclean                 
  cd ..
  exit
fi

export PATH=$PATH:`pwd`/kpp4palm/bin

# build kpp

cp mechanisms/UserRateLaws.f90 kpp/util
cd kpp
make
cd ..

# build kpp4palm.exe

cd kpp4palm
make install                    
cd ..

# run kpp4palm with default Setup
#    -d   DEFDIR=$OPTARG;;          # directory of definition files
#    -i   DE_INDEX="YES";;          # if set, deindexing
#    -f   DE_INDEX_FAST="YES";;     # if set, fast deindexing
#    -k   KEEP="YES";;              # keep Working directory
#    -o   OUTDIR=$OPTARG;;          # Output directory of Geneated Code
#    -p   PREFIX=$OPTARG;;          # Name Prefix
#    -s   KPP_SOLVER=$OPTARG;;      # Name Prefix

 
echo $PATH
# use smog mechnism as default
MECH=smog

while  getopts m:  opt   # get options
do case $opt in
      m)   MECH=$OPTARG;;          # mechanism name as part of mechanisms/def_[mechanism_name]

      \?)  print ${0##*/} "unknown option:" $OPTARG
           print "USAGE: ${0##*/} [ -m mechanism_name ] "
           exit 1;;
   esac
done
echo $MECH

kpp4palm.ksh -d `pwd`/mechanisms/def_$MECH -k
