#!/bin/bash

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

gnuplot<<EOF

set terminal pngcairo enhanced size 800,600
set grid
set key outside below

set linetype 1 lc rgb "blue"   # default

CASE = system('(cd ../../ && basename "$PWD")')
TIME = system("foamListTimes -case .. -latestTime")
FILE = '../postProcessing/graph/'.TIME.'/line.csv'

H = 0.49
set xtics   nomirror
set xrange  [-0.004:0.004]
set xtics   0.002
set x2label '{/Symbol a}.air'
set x2tics
set x2range [-0.05:1.05]

set output 'U_components.png'

set multiplot layout 1,2 title CASE.'   t = '.TIME

set xlabel 'U.x'
set ylabel  'y/H'
set title  'Interface Parallel Velocity'
plot FILE u (column('U.water_x')):(\$1/H) w l lt 1 lw 1 dt 1 t 'U.water'    , \
     FILE u (column('U.air_x'))  :(\$1/H) w l lt 1 lw 3 dt 2 t 'U.air'      , \
     FILE u (column('alpha.air')):(\$1/H) axis x2y1 w l notitle

set xlabel 'U.y'
unset ylabel
set format y ''
set title  'Interface Normal Velocity'
plot FILE u (column('U.water_y')):(\$1/H) w l lt 1 lw 1 dt 1 notitle        , \
     FILE u (column('U.air_y'))  :(\$1/H) w l lt 1 lw 3 dt 2 notitle        , \
     FILE u (column('alpha.air')):(\$1/H) axis x2y1 w l t "{/Symbol a}.air"

unset multiplot

EOF

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