#!/usr/local/bin/bash 
#   start 
./A22cgGS1 
#   energy 
#
cat NewP  ala22poig.dat  > ala22PointAll
cat obenC5 ala22poig.dat > C5.input 
#
# call gaussian03
#
./subg3 
#
cat C5.output >> ala22C5All
grep  'SCF Done:  E'  C5.output >> ala22EnergyAll
grep  'SCF Done:  E'  C5.output > energy   
tr -s ' ' < energy > entr 
cut -d' ' -f6 entr > energy
cp  energy ala22ener.dat 
grep 'SCF Done:  E' C5.output >> ala22proto.txt
grep D13 C5.output |grep estimate >>ala22D13All
grep D27 C5.output |grep estimate >>ala22D27All
#
export num=650
grep -n 'Axes restored to original set' C5.output | head -n 1 >Noline
cut -d':' -f1 Noline > Noli
./num3
export num=$?
export num=$[$num+626]
head -n $num C5.output |tail -22  >gradfile 
cat gradfile >> ala22GradAll
cp  gradfile ala22grad.dat
#
#  make the projector
./A22cgGS2
# special direction
# ForcesSPniedrig.dat in use for  ala22Rs.dat
# do the predictor 
./A22cgGS5 
cat NewP ala22poig.dat >> ala22PointAll
# ############################################
#                   GS  cycle                #
# ############################################
export status=0
while (test $status -ne 10) do
#   energy and gradient 
cat obenC5 ala22poig.dat > C5.input
#
# call gaussian03
#
./subg3
#
cat C5.output >> ala22C5All
grep  'SCF Done' C5.output > energy
cat  energy >>  ala22EnergyAll
tr -s ' ' < energy > entr  
cut -d' ' -f6 entr > energy
cp  energy ala22ener.dat
#
# gradient 
#
export num=650
grep -n 'Axes restored to original set' C5.output | head -n 1 >Noline
cut -d':' -f1 Noline > Noli
./num3
export num=$?
export num=$[$num+626]
head -n $num C5.output |tail -22  >gradfile
cat gradfile >> ala22GradAll
cp  gradfile ala22grad.dat
#
#   new GS point and test
./A22cgGS3 
export status=$?
#
if (test $status -eq 1) 
then
grep D13 C5.output |grep estimate >>ala22D13All
grep D27 C5.output |grep estimate >>ala22D27All
cat  energy >>  ala22EnergyAll
#
#   projector
./A22cgGS2
#   predictor
./A22cgGS5
export status=$?
fi
done
#                     end GS cycle
exit

