rm -f gap_vs_temp.dat

for i in 0 200 400 #250 300 350 400 450 500 550 600 650 700
do
   nions=`grep NIONS OUTCAR.${i} | awk '{print $12}'`
   occ_pristine=`grep -A $((nions * 2)) " band energies" OUTCAR.pristine | tail -3 | awk '{sum += $2} END {print sum/NR}'`
   con_pristine=`grep -A $((nions * 2 + 6)) " band energies" OUTCAR.pristine | tail -6 | awk '{sum += $2} END {print sum/NR}'`
   occ_oneshot=`grep -A $((nions * 2)) " band energies" OUTCAR.${i} | tail -3 | awk '{sum += $2} END {print sum/NR}'`
   con_oneshot=`grep -A $((nions * 2 + 6)) " band energies" OUTCAR.${i} | tail -6 | awk '{sum += $2} END {print sum/NR}'`
   gap_pristine=$(awk -v con="$con_pristine" -v occ="$occ_pristine" 'BEGIN {print con - occ}')
   gap_oneshot=$(awk -v con="$con_oneshot" -v occ="$occ_oneshot" 'BEGIN {print con - occ}')
   gap_diff=`awk -v gpris=$gap_pristine -v gonesh=$gap_oneshot 'BEGIN{print gonesh-gpris}'`
   echo $i $gap_diff >> gap_vs_temp.dat
done
