#!/bin/bash
#
################################################################################
#
# Bash script for plotting file "check-energy-derivatives" using gnuplot.
#
# @Pasquale Pavone  (2010, October, 8)
#_______________________________________________________________________________

pointsize=0.9

unit='[cm^-^1]'
xlab='Maximum displacement u [alat]'
inpf='check-energy-derivatives'

if [ -f 'gnu-input' ]; then
    rm gnu-input
fi
    
order=$(cat ./order-of-derivative)

let "f1=$order"
let "f2=$order+2"
let "f3=$order+4"

cat>>gnu-input<<***
 set ter pos landscape enhanced color solid lw 2
 set out 'gnu.ps'
 set multiplot   
 set data sty lp
#set xtics 0.01
 set mxtics 0
 set grid 
 set key o r
 set key spacing 1.5 
 set key box
#===============================================
 set size    0.86, 0.83
 set origin  0.05, 0.05
 set yr [$1:$2]
 set xr [:]
 set title "$3"  0,-0.8  font "Helvetica,18"
 set xlabel "$xlab"  0.0,0.0 font "Helvetica,18"     
 set ylabel "Force derivative of order $order $unit" 0.0,0.0 font "Helvetica,18"
 set xtics font "Helvetica,16"
 set ytics font "Helvetica,16"
 plot '$inpf' u 1:6 pt 7 ps $pointsize lt 2 lw 2 title 'Fit order $f3',\
      '$inpf' u 1:4 pt 7 ps $pointsize lt 3 lw 2 title 'Fit order $f2',\
      '$inpf' u 1:2 pt 7 ps $pointsize lt 1 lw 2 title 'Fit order $f1'    
#===============================================
 unset multiplot  
 quit
***
gnuplot < gnu-input
rm gnu-input
#-----------------------------------------------------------------------
#convert gnu.ps -rotate 90 $1-vs.png
#-----------------------------------------------------------------------

