#!/bin/sh

# check whether echo has the -e option
if test "`echo -e`" = "-e" ; then ECHO=echo ; else ECHO="echo -e" ; fi

MY_QE='../../../../bin/'
OUTDIR='./fd_files/'
IN_DIR='./fd_files/'
FORCEDIR='./fd_files/'

# scf calculation

$MY_QE/pw.x < si.scf.in> si.scf.out

$MY_QE/fd.x < fd.in > fd.out

# scf calculation for displacements

$MY_QE/pw.x < $IN_DIR/displaced.0.0.0.in > $OUTDIR/displaced.0.0.0.out

for i in `seq 1 1 ` ; do
    for n in `seq 1 1 ` ; do
        for m in `seq 1 1 ` ; do

$MY_QE/pw.x < $IN_DIR/displaced.$m.$i.$n.in > $OUTDIR/displaced.$m.$i.$n.out

        done
    done
done

grep 'force =   ' $OUTDIR/displaced.0.0.0.out | grep '     atom ' > forces
awk '{printf("% 18.12f % 18.12f % 18.12f \n",$7,$8,$9)}' < forces > $FORCEDIR/force.0.0.0
rm forces

for i in `seq 1 1 ` ; do
    for n in `seq 1 1 ` ; do
        for m in `seq 1 1 ` ; do

    grep 'force =   ' $OUTDIR/displaced.$m.$i.$n.out | grep '     atom ' > forces
    awk '{printf("% 18.12f % 18.12f % 18.12f \n",$7,$8,$9)}' < forces > $FORCEDIR/force.$m.$i.$n
    rm forces

        done
    done
done

$MY_QE/fd_ifc.x < fd_ifc.in > fd_ifc.out
