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


mv  -f ./energy.dat ./energy.dat.OLD

latt_const=4.04958 # exp value
perc=20. # vary in [(1-perc/100)*latt_const,(1+perc/100)*latt_const]
nstep=10.
min=$(echo "(1.-${perc}/100.)*${latt_const}"|bc -l)
max=$(echo "(1.+${perc}/100.)*${latt_const}"|bc -l)
step=$(echo "(${max}-${min})/(${nstep}-1)"|bc -l)

counter=0
for i in $(seq ${min} ${step} ${max})
do :
# ecutrho=$(echo "$i*8"|bc -l)
sed -E -e's|@A@|'$i'|' scf.in.in > scf.in
rm -rf ./tmp
label=$(printf "%02d" ${counter})
mpirun pw.x < scf.in 2>&1 |tee  scf-${label}.out
# echo $(printf "%02d" ${counter})

read d d d d nrg rest < <(egrep '! *total energy' scf-${label}.out)
echo ${i} ${nrg} >> ./energy.dat

counter=$((${counter}+1))

done # for i...

exit
