#!/bin/sh

# Plot lsfitpar-predicted Potential Energy Surface from ene file.
# Run without command-line arguments for usage information.

# Copyright (C) 2011 Kenno Vanommeslaeghe
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

unset id help
getopts i: f 2> /dev/null
if [ $? -eq 0 ] ; then
  if [ "$f" = "i" ] ; then
    id=$OPTARG
    shift 2
   else
    help=1
   fi
 fi
if [ $# -eq 0 -o "$help" ] ; then
  echo "Usage: `basename $0` [-i <id>] <ene file(s)>
Where <ene file(s)> must be generated by Kenno\'s torsional fit program
      <id> is an identifier to be integrated in the output file name"
  exit 1
 fi
echo "#!/usr/bin/gnuplot" > all$id.gpt
for i in $* ; do
  echo "set title \"$i\"
plot \"$i\" using 1 with lines t \"qm\" lw 2, \"$i\" using 2 with lines t \"mm0\" lw 2, \"$i\" using 3 with lines t \"mme\" lw 2
pause mouse" >> all$id.gpt
 done
chmod 755 all$id.gpt
./all$id.gpt
