#!/bin/bash



a=2
b=2
grid=run.cgd
sol=run.cfl

###########
# Pressure
###########
echo "
clear all

grid $grid
sol $sol

###########
# Velocity
###########
if [ $a == $b ]; then
echo "
clear all
grid $grid
solution $sol

units inches

zone 1
subset i all j all k 1
cut at x 4.9922

variable y in
variable u m sec

genplot output yufive

clear all
grid $grid
solution $sol

units inches

zone 1
subset i all j all k 1
cut at x 7.9871

variable y in
variable u m sec

genplot output yueight

clear all
grid $grid
solution $sol

units inches

zone 1
subset i all j all k 1
cut at x 10.9821

variable y in
variable u m sec


genplot output yueleven

clear all
grid $grid
solution $sol

units inches

zone 1
subset i all j all k 1
cut at x 12.9794

variable y in
variable u m sec

genplot output yuthirteen
exit
" > velocity.jou

cfpost_prod.exe < velocity.jou

grep -v -e 'Exported' -e 'Strong' -e 'y' -e 'u' yufive.gen > ifive.dat
grep -v -e 'Exported' -e 'Strong' -e 'y' -e 'u' yueight.gen > ieight.dat
grep -v -e 'Exported' -e 'Strong' -e 'y' -e 'u' yueleven.gen > ieleven.dat
grep -v -e 'Exported' -e 'Strong' -e 'y' -e 'u' yuthirteen.gen > ithirteen.dat



mv *.gen ifive.dat ieight.dat ieleven.dat ithirteen.dat results/
rm velocity.jou
fi

###########
# Residuals
###########
#Extract max residuals of N-S equations for all zones
for ((nzone=1; nzone<=1; nzone++))
do
  grep -a RES run.lis | awk '{ print $2 "    " $4 "    " $9 }' | grep "   $nzone   " | awk '{ print $3 }' > maxres$nzone.dat
  grep -a S-A run.lis | awk '{ print $2 "    " $4 "    " $9 }' | grep "   $nzone   " | awk '{ print $3 }' > maxsa$nzone.dat
done

mv maxres* maxsa* results/
rm cfpost.jou
