#!/bin/bash

if ! which gnuplot > /dev/null 2>&1
then
    echo 'gnuplot not found - skipping graph creation' >&2
    exit 1
fi

gnuplot<<EOF

set linetype 1 lc rgb "blue"  lw 2 dt 1
set linetype 2 lc rgb "brown" lw 4 dt 3
set linetype 3 lc rgb "red"   lw 3 dt 6

set key top center
set grid

#---EPS---
set term pngcairo size 1000,600
FType = '.png'


#---singleGraph---
TIMES = system('ls -1 ../postProcessing/graphA | sort -g')
NUM = words(TIMES)
TIME(n) = word(TIMES, n)
TIME = (NUM >= 18 ? "1.7" : TIME(NUM))

FILEA = "../postProcessing/graphA/".TIME."/line.csv"
FILEB = "../postProcessing/graphB/".TIME."/line.csv"


set output  "alphaU".FType

set multiplot layout 1,2 margins .11,.99,.20,.97 spacing 0.02,0

set yrange [0:0.5]
set ytics 0.0, 0.1, 0.501
set ylabel  "y" offset 1.5
set xrange [-0.05:1.05]
set xlabel "r_{/Symbol a}" offset 1.5
plot FILEA u 3:1 w l t "water", \
     FILEA u 4:1 w l t "oil"  , \
     FILEA u 5:1 w l t "air"

unset ylabel
set ytics ("" 0, "" 0.1, "" 0.2, "" 0.3, "" 0.4, "" 0.5)
set xrange [-0.25:0.25] # ymin:ymax
set xlabel "U_{{/Symbol a},y}" offset 1.5
plot FILEB u 3:1 w l notitle, \
     FILEB u 6:1 w l notitle, \
     FILEB u 9:1 w l notitle

unset multiplot

EOF

#------------------------------------------------------------------------------
