#!/bin/sh

cat << EOF > phband.in
&general
PREFIX = BGG_band_harm
MODE = phonons
NKD = 3
KD = Ba Ga Ge
MASS = 137.327 69.723 72.64

FCSXML = ../BGG_cell+2_harm.xml
#FCSXML = ../BGG_FPMD800K_random2_lasso1.xml

ISMEAR = -1
TMIN = 0; TMAX = 1000; DT = 10
BCONNECT = 2
/

&cell
 21.114
  1.0 0.0 0.0
  0.0 1.0 0.0
  0.0 0.0 1.0
/

&kpoint
1
G 0.0 0.05 0.05 M 0.0 0.5 0.5 901
/
EOF
mpijob ~/src/alamode/anphon/anphon phband.in > phband.log
tail -n 901 BGG_band_harm.connection | awk '{if (NR%100 == 1) print $2}' > mode1.tmp
tail -n 901 BGG_band_harm.connection | awk '{if (NR%100 == 1) print $3}' > mode2.tmp
tail -n 901 BGG_band_harm.connection | awk '{if (NR%100 == 1) print $4}' > mode3.tmp
echo "10" > target_harm_TA1.dat
echo "10" > target_harm_TA2.dat
echo "10" > target_harm_LA.dat
paste ktmp.dat mode1.tmp >> target_harm_TA1.dat
paste ktmp.dat mode2.tmp >> target_harm_TA2.dat
paste ktmp.dat mode3.tmp >> target_harm_LA.dat

for temp in 10 20 30 40 50 60 70 80 90 100 200 300
do
cat << EOF > phband.in
&general
PREFIX = BGG_band_${temp}K
MODE = phonons
NKD = 3
KD = Ba Ga Ge
MASS = 137.327 69.723 72.64

FCSXML = ../BGG_SCPH+2_offdiag_${temp}K.xml

ISMEAR = -1
TMIN = 0; TMAX = 1000; DT = 10
BCONNECT = 2
/

&cell
 21.114
  1.0 0.0 0.0
  0.0 1.0 0.0
  0.0 0.0 1.0
/

&kpoint
1
G 0.0 0.05 0.05 M 0.0 0.5 0.5 901
/
EOF
mpijob ~/src/alamode/anphon/anphon phband.in > phband.log
tail -n 901 BGG_band_${temp}K.connection | awk '{if (NR%100 == 1) print $2}' > mode1.tmp
tail -n 901 BGG_band_${temp}K.connection | awk '{if (NR%100 == 1) print $3}' > mode2.tmp
tail -n 901 BGG_band_${temp}K.connection | awk '{if (NR%100 == 1) print $4}' > mode3.tmp
echo "10" > target_SCP${temp}K_TA1.dat
echo "10" > target_SCP${temp}K_TA2.dat
echo "10" > target_SCP${temp}K_LA.dat
paste ktmp.dat mode1.tmp >> target_SCP${temp}K_TA1.dat
paste ktmp.dat mode2.tmp >> target_SCP${temp}K_TA2.dat
paste ktmp.dat mode3.tmp >> target_SCP${temp}K_LA.dat
done

rm mode1.tmp
rm mode2.tmp
rm mode3.tmp

