#!/bin/csh

# This script takes the output of a JAGUAR frequency calculation
# $1.out  and runs FreqQRC on it to generate the ${1}.fdt file
# The script then uses sed to edit the input file for the frequency
# calculation ${1}.in into two input files for the QRC calculation:
# ${1}QRCadd.in   ${1}QRCsub.in
# This script assumes that the original input file has a line:
# igeopt=2   which it changes to igeopt=2



grep frequencies $1.out | grep -v Vibrational | head -3

FreqQRC $*

sed s/"igeopt=2"/"igeopt=1"/ < $1.in | grep -v "ifreq" > ttt$1.qrctmp
head -`grep -n zmat ttt$1.qrctmp | cut -f1 -d":"` ttt$1.qrctmp > ttt$1.qrctmp2
tail +`grep -n Adding $1.fdt | cut -f1 -d":"` $1.fdt > ttt$1.qrctmp3
head -`grep -n Subtracting ttt$1.qrctmp3 | cut -f1 -d":"` ttt$1.qrctmp3 | grep "\." > ttt$1.qrcadd
tail +`grep -n Subtracting $1.fdt | cut -f1 -d":"` $1.fdt | grep "\." > ttt$1.qrcsub

cat ttt$1.qrctmp2 ttt$1.qrcadd > $1QRCadd.in
cat ttt$1.qrctmp2 ttt$1.qrcsub > $1QRCsub.in
echo "&" >> $1QRCadd.in
echo "&" >> $1QRCsub.in

rm ttt$1.qrctmp ttt$1.qrctmp2 ttt$1.qrctmp3 ttt$1.qrcadd ttt$1.qrcsub


