#!/bin/bash

FUNC="B86SRP68-DF2"
gnuplot<<EOF
set output "${FUNC}.ps"
set terminal postscript enhanced color landscape
set multiplot layout 1,4 title "${FUNC} E_0({/Symbol n},J) trendline Cu(111) \n fit f(x) = a + bx + cx^2 + dx^3" font ",12"

set bmargin 1.0
set tmargin 6.5
set lmargin 3.5
set rmargin 0.5

set tics font "Helvetica, 10"

set title "H_2 {/Symbol n} = 0" font ",10"
unset key
set ylabel "E_0({/Symbol n},J) [ev]
set xlabel "J"
set xrange[0.:11.]
set yrange [0.25:0.9]
#exp
z(x) = 0.702458 + 0.0267495*x + -0.00572332*x**2 + 5.70992e-05*x**3
#func
f(x) = 0.770073 + 0.0195511*x + -0.00342879*x**2 + -7.83476e-05*x**3
g(x) = 0.782862 + 0.0163772*x + -0.00243298*x**2 + -0.000168026*x**3
plot "exp.H2.v0"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.H2.v0" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1, "${FUNC}.QD.H2.v0" lc 2 pointtype 7 pointsize 0.5,g(x) lc 2 

#plot 2
unset ylabel
set title "H_2 {/Symbol n} = 1"
set key t
set key font "Helvetica, 7"
set xrange[0.:7]
set yrange [0.25:0.9]
#exp
z(x) = 0.342209 + 0.00771786*x + 0.000713788*x**2 + -0.000437424*x**3
#func
f(x) = 0.483561 + -0.0452976*x + 0.0131439*x**2 + -0.00121212*x**3
g(x) = 0.445162 + -0.00968254*x + 0.00428571*x**2 + -0.000555556*x**3
plot "exp.H2.v1"  lc -1 pointtype 7 pointsize 0.5 title"exp.", z(x) lc -1 title"", "${FUNC}.H2.v1" lc 1 pointtype 7 pointsize 0.5 title"${FUNC}", f(x) lc 1 title"", "${FUNC}.QD.H2.v1" lc 2 pointtype 7 pointsize 0.5 title"${FUNC} QD" , g(x) lc 2 title""

#plot 3
set title"D_2 {/Symbol n} = 0"
unset key 
set xlabel"J"
set xrange [0.:11.]
set yrange [0.25:0.9]
#exp
z(x) = 0.736055 + 0.023116*x + -0.0021321*x**2 + -5.46313e-05*x**3
#func
f(x) = 0.831941 + -0.000826581*x + 0.00244117*x**2 + -0.000295908*x**3

plot "exp.D2.v0"  lc -1 pointtype 7 pointsize 0.5 , z(x) lc -1 , "${FUNC}.D2.v0" lc 1 pointtype 7 pointsize 0.5 , f(x) lc 1 

#plot 4
unset key
set title"D_2 {/Symbol n} = 1" 
set xlabel"J"
set xrange [0.:7.]
set yrange [0.25:0.9]
#exp
z(x) = 0.477429 + 0.0064582*x + 0.00070729*x**2 + -0.000259151*x**3
#func
f(x) = 0.598712 + -0.0204365*x + 0.00478355*x**2 + -0.000353535*x**3

plot "exp.D2.v1"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.D2.v1" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1
EOF

ps2pdf ${FUNC}.ps
#evince ${FUNC}.pdf


FUNC="PBEa57-DF2"
gnuplot<<EOF
set output "${FUNC}.ps"
set terminal postscript enhanced color landscape
set multiplot layout 1,4 title "${FUNC} E_0({/Symbol n},J) trendline Cu(111) \n fit f(x) = a + bx + cx^2 + dx^3" font ",12"

set bmargin 0.5
set tmargin 6.5
set lmargin 3.5
set rmargin 0.5

set tics font "Helvetica, 10"

set title "H_2 {/Symbol n} = 0" font ",10"
unset key
set ylabel "E_0({/Symbol n},J) [ev]
set xlabel "J"
set xrange[-0.5:11.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.702458 + 0.0267495*x + -0.00572332*x**2 + 5.70992e-05*x**3
#func
f(x) = 0.762729 + 0.0193589*x + -0.00349761*x**2 + -7.70526e-05*x**3
plot "exp.H2.v0"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.H2.v0" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1

#plot 2
unset ylabel
set title "H_2 {/Symbol n} = 1"
set key t
set key font "Helvetica, 7"
set xrange[-0.5:7.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.342209 + 0.00771786*x + 0.000713788*x**2 + -0.000437424*x**3
#func
f(x) = 0.465606 + -0.0531944*x + 0.015487*x**2 + -0.00142677*x**3
plot "exp.H2.v1"  lc -1 pointtype 7 pointsize 0.5 title"exp.", z(x) lc -1 title"", "${FUNC}.H2.v1" lc 1 pointtype 7 pointsize 0.5 title"${FUNC}", f(x) lc 1 title""

#plot 3
set title"D_2 {/Symbol n} = 0"
unset key 
set xlabel"J"
set xrange [-0.5:11.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.736055 + 0.023116*x + -0.0021321*x**2 + -5.46313e-05*x**3
#func
f(x) = 0.826374 + 0.00021312*x + 0.00219031*x**2 + -0.000285548*x**3
plot "exp.D2.v0"  lc -1 pointtype 7 pointsize 0.5 , z(x) lc -1 , "${FUNC}.D2.v0" lc 1 pointtype 7 pointsize 0.5 , f(x) lc 1 

#plot 4
unset key
set title"D_2 {/Symbol n} = 1" 
set xlabel"J"
set xrange [-0.5:7.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.477429 + 0.0064582*x + 0.00070729*x**2 + -0.000259151*x**3
#func
f(x) = 0.585152 + -0.0282738*x + 0.0071158*x**2 + -0.000530303*x**3
plot "exp.D2.v1"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.D2.v1" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1
EOF

ps2pdf ${FUNC}.ps
#evince ${FUNC}.pdf

FUNC="SRP48"
gnuplot<<EOF
set output "${FUNC}.ps"
set terminal postscript enhanced color landscape
set multiplot layout 1,4 title "${FUNC} E_0({/Symbol n},J) trendline Cu(111) \n fit f(x) = a + bx + cx^2 + dx^3" font ",12"

set bmargin 0.5
set tmargin 6.5
set lmargin 3.5
set rmargin 0.5

set tics font "Helvetica, 10"

set title "H_2 {/Symbol n} = 0" font ",10"
unset key
set ylabel "E_0({/Symbol n},J) [ev]
set xlabel "J"
set xrange[-0.5:11.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.702458 + 0.0267495*x + -0.00572332*x**2 + 5.70992e-05*x**3
#func
f(x) = 0.733791 + 0.00776529*x + -0.00093365*x**2 + -0.000210761*x**3
plot "exp.H2.v0"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.H2.v0" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1

#plot 2
unset ylabel
set title "H_2 {/Symbol n} = 1"
set key t
set key font "Helvetica, 7"
set xrange[-0.5:7.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.342209 + 0.00771786*x + 0.000713788*x**2 + -0.000437424*x**3
#func
f(x) = 0.469091 + -0.0720635*x + 0.0187338*x**2 + -0.0015404*x**3
plot "exp.H2.v1"  lc -1 pointtype 7 pointsize 0.5 title"exp.", z(x) lc -1 title"", "${FUNC}.H2.v1" lc 1 pointtype 7 pointsize 0.5 title"${FUNC}", f(x) lc 1 title""

#plot 3
set title"D_2 {/Symbol n} = 0"
unset key 
set xlabel"J"
set xrange [-0.5:11.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.736055 + 0.023116*x + -0.0021321*x**2 + -5.46313e-05*x**3
#func
f(x) = 0.795842 + -0.00534304*x + 0.00260559*x**2 + -0.00027454*x**3
plot "exp.D2.v0"  lc -1 pointtype 7 pointsize 0.5 , z(x) lc -1 , "${FUNC}.D2.v0" lc 1 pointtype 7 pointsize 0.5 , f(x) lc 1 

#plot 4
unset key
set title"D_2 {/Symbol n} = 1" 
set xlabel"J"
set xrange [-0.5:7.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.477429 + 0.0064582*x + 0.00070729*x**2 + -0.000259151*x**3
#func
f(x) = 0.571288 + -0.0163889*x + -0.000140693*x**2 + 0.000214646*x**3
plot "exp.D2.v1"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.D2.v1" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1
EOF

ps2pdf ${FUNC}.ps
#evince ${FUNC}.pdf

FUNC="MS.B86b"
gnuplot<<EOF
set output "${FUNC}.ps"
set terminal postscript enhanced color landscape
set multiplot layout 1,4 title "${FUNC}l E_0({/Symbol n},J) trendline Cu(111) \n fit f(x) = a + bx + cx^2 + dx^3" font ",12"

set bmargin 0.5
set tmargin 6.5
set lmargin 3.5
set rmargin 0.5

set tics font "Helvetica, 10"

set title "H_2 {/Symbol n} = 0" font ",10"
unset key
set ylabel "E_0({/Symbol n},J) [ev]
set xlabel "J"
set xrange[-0.5:11.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.702458 + 0.0267495*x + -0.00572332*x**2 + 5.70992e-05*x**3
#func
f(x) = 0.763773 + 0.0117407*x + -0.00178682*x**2 + -0.000158638*x**3
plot "exp.H2.v0"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.H2.v0" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1

#plot 2
unset ylabel
set title "H_2 {/Symbol n} = 1"
set key t
set key font "Helvetica, 7"
set xrange[-0.5:7.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.342209 + 0.00771786*x + 0.000713788*x**2 + -0.000437424*x**3
#func
f(x) = 0.520985 + -0.0775*x + 0.0211634*x**2 + -0.0017803*x**3
plot "exp.H2.v1"  lc -1 pointtype 7 pointsize 0.5 title"exp.", z(x) lc -1 title"", "${FUNC}.H2.v1" lc 1 pointtype 7 pointsize 0.5 title"${FUNC}l", f(x) lc 1 title""

#plot 3
set title"D_2 {/Symbol n} = 0"
unset key 
set xlabel"J"
set xrange [-0.5:11.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.736055 + 0.023116*x + -0.0021321*x**2 + -5.46313e-05*x**3
#func
f(x) = 0.824853 + -0.0063419*x + 0.00309302*x**2 + -0.000307563*x**3
plot "exp.D2.v0"  lc -1 pointtype 7 pointsize 0.5 , z(x) lc -1 , "${FUNC}.D2.v0" lc 1 pointtype 7 pointsize 0.5 , f(x) lc 1 

#plot 4
unset key
set title"D_2 {/Symbol n} = 1" 
set xlabel"J"
set xrange [-0.5:7.5]
set yrange [0.25:0.9]
#exp
z(x) = 0.477429 + 0.0064582*x + 0.00070729*x**2 + -0.000259151*x**3
#func
f(x) = 0.616894 + -0.0138492*x + -0.00114177*x**2 + 0.000315657*x**3
plot "exp.D2.v1"  lc -1 pointtype 7 pointsize 0.5, z(x) lc -1, "${FUNC}.D2.v1" lc 1 pointtype 7 pointsize 0.5, f(x) lc 1
EOF

ps2pdf ${FUNC}.ps
#evince ${FUNC}.pdf

gnuplot<<EOF
set output "trend.ps"
set terminal postscript enhanced color landscape
set multiplot layout 1,4 title "trendlines of E_0({/Symbol n},J) Cu(111) \n fit f(x) = a + bx + cx^2 + dx^3" font ",12"

set bmargin 0.5
set tmargin 6.5
set lmargin 3.5
set rmargin 0.5

set tics font "Helvetica, 10"

set title "H_2 {/Symbol n} = 0" font ",10"
unset key
set ylabel "E_0({/Symbol n},J) [ev]
set xlabel "J"
set xrange[-0.5:11.5]
set yrange [0.25:0.9]
f1(x) = 0.702458 + 0.0267495*x + -0.00572332*x**2 + 5.70992e-05*x**3		#exp.
f2(x) = 0.770073 + 0.0195511*x + -0.00342879*x**2 + -7.83476e-05*x**3		#B86SRP68-DF2
f3(x) = 0.782862 + 0.0163772*x + -0.00243298*x**2 + -0.000168026*x**3		#B86SRP68-DF2 QD
f4(x) = 0.762729 + 0.0193589*x + -0.00349761*x**2 + -7.70526e-05*x**3		#PBEa57-DF2
f5(x) = 0.733791 + 0.00776529*x + -0.00093365*x**2 + -0.000210761*x**3		#SRP48
f6(x) = 0.763773 + 0.0117407*x + -0.00178682*x**2 + -0.000158638*x**3		#MS-B86bl

plot f1(x) lc -1 , f2(x) lc 1, f3(x) lc 2 , f4(x) lc 3, f5(x) lc 4, f6(x) lc 5

unset ylabel
set title"H_2 {/Symbol n} = 1"
set key t
set key font "Helvetica, 7"
set xlabel "J"
set xrange[-0.5:7.5]
f1(x) = 0.342209 + 0.00771786*x + 0.000713788*x**2 + -0.000437424*x**3
f2(x) = 0.483561 + -0.0452976*x + 0.0131439*x**2 + -0.00121212*x**3
f3(x) = 0.445162 + -0.00968254*x + 0.00428571*x**2 + -0.000555556*x**3
f4(x) = 0.465606 + -0.0531944*x + 0.015487*x**2 + -0.00142677*x**3
f5(x) = 0.469091 + -0.0720635*x + 0.0187338*x**2 + -0.0015404*x**3
f6(x) = 0.520985 + -0.0775*x + 0.0211634*x**2 + -0.0017803*x**3

plot f1(x) lc -1 title"exp.", f2(x) lc 1 title"B86SRP68-DF2", f3(x) lc 2 title"B86SRP68-DF2 QD" , f4(x) lc 3 title"PBEa57-DF2", f5(x) lc 4 title"SRP48", f6(x) lc 5 title"MS-B86bl"

set title"D_2 {/Symbol n} = 0"
unset key
set xrange[-0.5:11.5]
set xlabel "J"
f1(x) = 0.736055 + 0.023116*x + -0.0021321*x**2 + -5.46313e-05*x**3
f2(x) = 0.831941 + -0.000826581*x + 0.00244117*x**2 + -0.000295908*x**3
#f3
f4(x) = 0.826374 + 0.00021312*x + 0.00219031*x**2 + -0.000285548*x**3
f5(x) = 0.795842 + -0.00534304*x + 0.00260559*x**2 + -0.00027454*x**3
f6(x) = 0.824853 + -0.0063419*x + 0.00309302*x**2 + -0.000307563*x**3

plot f1(x) lc -1 , f2(x) lc 1, f4(x) lc 3, f5(x) lc 4, f6(x) lc 5

set title"D_2 {/Symbol n} = 1"
unset key 
set xlabel "J"
set xrange[-0.5:7.5]
f1(x) = 0.477429 + 0.0064582*x + 0.00070729*x**2 + -0.000259151*x**3
f2(x) = 0.598712 + -0.0204365*x + 0.00478355*x**2 + -0.000353535*x**3
#f3
f4(x) = 0.585152 + -0.0282738*x + 0.0071158*x**2 + -0.000530303*x**3
f5(x) = 0.571288 + -0.0163889*x + -0.000140693*x**2 + 0.000214646*x**3
f6(x) = 0.616894 + -0.0138492*x + -0.00114177*x**2 + 0.000315657*x**3

plot f1(x) lc -1 , f2(x) lc 1, f4(x) lc 3, f5(x) lc 4, f6(x) lc 5
EOF

ps2pdf trend.ps

gnuplot<<EOF
set output "trend2.ps"
set terminal postscript enhanced color landscape
set multiplot layout 1,4 title "trendlines of E_0({/Symbol n},J) Cu(111) \n fit f(x) =  bx + cx^2 + dx^3 \n a parameter removed for comparison!" font ",12"

set bmargin 0.5
set tmargin 6.5
set lmargin 3.5
set rmargin 0.5

set tics font "Helvetica, 10"

set title "H_2 {/Symbol n} = 0" font ",10"
unset key
#set ylabel "E_0({/Symbol n},J) [ev]
set xlabel "J"
set ylabel "arb. units"
set xrange[0.:11]
set yrange [-0.4:0.1]
f1(x) =  0.0267495*x + -0.00572332*x**2 + 5.70992e-05*x**3		#exp.
f2(x) =  0.0195511*x + -0.00342879*x**2 + -7.83476e-05*x**3		#B86SRP68-DF2
f3(x) =  0.0163772*x + -0.00243298*x**2 + -0.000168026*x**3		#B86SRP68-DF2 QD
f4(x) =  0.0193589*x + -0.00349761*x**2 + -7.70526e-05*x**3		#PBEa57-DF2
f5(x) =  0.00776529*x + -0.00093365*x**2 + -0.000210761*x**3		#SRP48
f6(x) =  0.0117407*x + -0.00178682*x**2 + -0.000158638*x**3		#MS-B86bl

plot f1(x) lc -1 , f2(x) lc 1, f3(x) lc 2 , f4(x) lc 3, f5(x) lc 4, f6(x) lc 5

set title"H_2 {/Symbol n} = 1"
set key b
set key font "Helvetica, 7"
set xlabel "J"
unset ylabel
set xrange[0:7]

f1(x) =  0.00771786*x + 0.000713788*x**2 + -0.000437424*x**3
f2(x) =  -0.0452976*x + 0.0131439*x**2 + -0.00121212*x**3
f3(x) =  -0.00968254*x + 0.00428571*x**2 + -0.000555556*x**3
f4(x) =  -0.0531944*x + 0.015487*x**2 + -0.00142677*x**3
f5(x) =  -0.0720635*x + 0.0187338*x**2 + -0.0015404*x**3
f6(x) =  -0.0775*x + 0.0211634*x**2 + -0.0017803*x**3

plot f1(x) lc -1 title"exp.", f2(x) lc 1 title"B86SRP68-DF2", f3(x) lc 2 title"B86SRP68-DF2 QD" , f4(x) lc 3 title"PBEa57-DF2", f5(x) lc 4 title"SRP48", f6(x) lc 5 title"MS-B86bl"

set title"D_2 {/Symbol n} = 0"
unset key
set xrange[0:11]
set xlabel "J"
f1(x) =  0.023116*x + -0.0021321*x**2 + -5.46313e-05*x**3
f2(x) =  -0.000826581*x + 0.00244117*x**2 + -0.000295908*x**3
#f3
f4(x) =  0.00021312*x + 0.00219031*x**2 + -0.000285548*x**3
f5(x) =  -0.00534304*x + 0.00260559*x**2 + -0.00027454*x**3
f6(x) =  -0.0063419*x + 0.00309302*x**2 + -0.000307563*x**3

plot f1(x) lc -1 , f2(x) lc 1, f4(x) lc 3, f5(x) lc 4, f6(x) lc 5

set title"D_2 {/Symbol n} = 1"
unset key 
set xlabel "J"
set xrange[0:7]
f1(x) =  0.0064582*x + 0.00070729*x**2 + -0.000259151*x**3
f2(x) =  -0.0204365*x + 0.00478355*x**2 + -0.000353535*x**3
#f3
f4(x) =  -0.0282738*x + 0.0071158*x**2 + -0.000530303*x**3
f5(x) =  -0.0163889*x + -0.000140693*x**2 + 0.000214646*x**3
f6(x) =  -0.0138492*x + -0.00114177*x**2 + 0.000315657*x**3

plot f1(x) lc -1 , f2(x) lc 1, f4(x) lc 3, f5(x) lc 4, f6(x) lc 5
EOF

ps2pdf trend2.ps


pdfunite B86SRP68-DF2.pdf PBEa57-DF2.pdf SRP48.pdf MS.B86b.pdf trend.pdf trend2.pdf out.pdf
evince out.pdf
