#!/bin/sh -x
P=`basename $0`

#-----------------------------------------------------------
# mkplots: script for plotting results from 'deut'
#-----------------------------------------------------------
die() {
echo "$P: $1"
exit 1
}

for x0 in 2.0 4.0 6.0 8.0; do 
   dir="x0=$x0"
   test -d $dir || die "Directory '$dir' does not exist"
   sfile="$dir/solution"
   test -f $sfile || \
      die "Solution file '$sfile' does not exist"
done

test -f u.ps || gnuplot<<END
set terminal postscript portrait
set output "u.ps"
set size square
set title "Toy Model Deuteron Wave Functions\nUnit \
depth square-well potential with range x0\n(Wave \
functions are unnormalized)"
set xlabel "x"
set ylabel "u(x)"
plot [0:20] [0:3] \
     "x0=2.0/solution" title "x0=2.0" with lines, \
     "x0=4.0/solution" title "x0=4.0" with lines, \
     "x0=6.0/solution" title "x0=6.0" with lines, \
     "x0=8.0/solution" title "x0=8.0" with lines 
quit
END

dir="x0=2.0-detail"
test -d $dir || mkdir $dir
cd $dir

for E in -0.0900 -0.1100 -0.1000 -0.1050 -0.1025; do
   test -f E=$E || \
      deut 2.0 $E 30.0 0.01 1.0d-10 | nth 1 2 > E=$E
done

test -f ../shoot.ps || gnuplot<<END
set terminal postscript portrait
set output "shoot.ps"
set size square
set title "Toy Model Deuteron Wave Functions\nUnit depth \
square-well potential with range x0=2.0\nIllustration of \
bisection solution for eigenvalue"
set xlabel "x"
set ylabel "u(x)"
plot [0:30] [-40:40] \
     "E=-0.0900" title "E=-0.0900" with lines, \
     "E=-0.1100" title "E=-0.1100" with lines, \
     "E=-0.1000" title "E=-0.1000" with lines, \
     "E=-0.1050" title "E=-0.1050" with lines, \
     "E=-0.1025" title "E=-0.1025" with lines
quit
END

test -f ../zshoot.ps || gnuplot<<END
set terminal postscript portrait
set output "zshoot.ps"
set size square
set title "Toy Model Deuteron Wave Functions\nUnit depth \
square-well potential with range x0=2.0\nIllustration of \
bisection solution for eigenvalue (detail)"
set xlabel "x"
set ylabel "u(x)"
plot [0:10] [0:1.2] \
     "E=-0.0900" title "E=-0.0900" with lines, \
     "E=-0.1100" title "E=-0.1100" with lines, \
     "E=-0.1000" title "E=-0.1000" with lines, \
     "E=-0.1050" title "E=-0.1050" with lines, \
     "E=-0.1025" title "E=-0.1025" with lines
quit
END

ls *.ps > /dev/null 2>&1 && mv *.ps ..
cd ..

ls -lt *ps
