--- /dev/null
+#!/bin/bash
+
+# get the kohn sham levels (plotted nicely)
+
+# spin component 1
+
+file=$1/OUTCAR
+
+WUP=1.2
+WDOWN=1.8
+PS=2
+OPT=7
+UPT=4
+
+if [ ! -f $file ]; then
+ echo "no OUTCAR file found ..."
+ exit
+fi
+
+rm -f $1/ks_levels_*
+
+center="0"
+
+
+# spin component 1
+startline=`grep -n spin\ component\ 1 $file | tail -1 | awk -F: '{ print $1 }'`
+echo -en "spin component 1 ($startline)... "
+sed -n "$startline,/spin component 2/p" $file | grep ^' '*[0-9] | \
+ while read number energy occu; do
+ if [ "$occu" != "0.00000" ]; then
+ echo "0.18 $energy 0.1" >> $1/ks_levels_o
+ else
+ echo "0.18 $energy 0.1" >> $1/ks_levels_u
+ fi
+ done
+echo "done"
+
+# spin component 2
+startline=`grep -n spin\ component\ 2 $file | tail -1 | awk -F: '{ print $1 }'`
+echo -en "spin component 2 ($startline) ... "
+sed -n "$startline,/---/p" $file | grep ^' '*[0-9] | \
+ while read number energy occu; do
+ if [ "$occu" != "0.00000" ]; then
+ echo "0.42 $energy 0.1" >> $1/ks_levels_o
+ else
+ if [ "$center" = "0" ]; then
+ echo -en "setting mid value -> $energy ... "
+ center=$energy
+ echo "$energy" > $1/temp_e
+ fi
+ echo "0.42 $energy 0.1" >> $1/ks_levels_u
+ fi
+ done
+echo "done"
+
+center=`cat $1/temp_e`
+yl=`echo $center $WDOWN | awk '{ print $1-$2 }'`
+yh=`echo $center $WUP | awk '{ print $1+$2 }'`
+echo "generating gnuplot file ($center, $yl, $yh, $ly) ..."
+cat > $1/ksl_plot.gpi <<!
+plot "ks_levels_o" w xerrorbars pt $OPT ps $PS t "", "ks_levels_u" w xerrorbars pt $UPT ps $PS t ""
+unset bars
+set ylabel "Kohn-Sham levels [eV]"
+set xrange [0:0.6]
+set yrange [$yl:$yh]
+set xlabel "Spin up / down"
+set format x ""
+unset xtics
+set mytics 5
+set size ratio 3.0
+replot
+set term epslatex standalone color solid size 3.5,7
+set out "ksl.tex"
+replot
+!
+
+cd $1
+
+echo "running gnuplot and latex ..."
+gnuplot ksl_plot.gpi
+latex ksl
+dvips ksl
+gv ksl
+
+cd ../..
+
+echo "done"
+echo "file: $1/ksl.ps"
+echo