#!/bin/bash
#
# source functions
#
for f in `ls ${HOME}/scripts/sh-funcs/*.sh 2>/dev/null`;do . $f;done


# rm -f ./latt_const.gnuplot

# i, 2 3 4 5 6
# for i in 2 3 4 5 6 7 8 9 
# for i in 10 11 12 13
# for i in 14 15 16 17
# for i in 15 25 35 45
for i in 55 65 75 85
do :
ecutrho=$(echo "$i*8"|bc -l)
sed -E -e's|@ECUT@|'$i'|' -e's|@RHO@|'$ecutrho'|' relax.in.in > relax.in
rm -rf ./tmp
mpirun pw.x < relax.in 2>&1 |tee  relax-$i.out

# catch results
lines=$(egrep -A 1 'CELL_PARAMETERS' relax-$i.out|tail -2)
alat=$(echo ${lines}|sed -E -e's|^.*alat= *||'|sed -E -e's|\).*||')
a_prim=$(echo ${lines}|sed -E -e's|^.*\) *||'|sed -E -e's| .*$||')
# echo "${alat}"
# echo "${a_prim}"
A=$(echo "scale=4;-2.*${alat}*${a_prim}*0.52917721"|bc -l)
# echo ${A}
read d d d d nk rest < <(egrep 'number of k points=' relax-$i.out)
echo ${i} ${A} >> ./latt_const.gnuplot

done # for i...

exit
