#!/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
    set grid
    set key bottom right

    time=system("grep '^endTime' ../system/controlDict | tr -s ' ' | cut -d ' ' -f 2 | cut -d ';' -f 1")

    set output 'velocityProfile.png'
    set xlabel 'y'
    set ylabel 'u'
    analytical(x) = -25*x**2 + 50*x
    plot '../postProcessing/graph/'.time.'/line.csv' u 1:2 w l lw 2           t 'gas1'          , \
         '../postProcessing/graph/'.time.'/line.csv' u 1:5 w l lw 2 dt 2      t 'gas2'          , \
            'postProcessing/graph/'.time.'/line.csv' u 1:2 w l lw 2           t 'reference gas1', \
            'postProcessing/graph/'.time.'/line.csv' u 1:5 w l lw 2 dt 2      t 'reference gas2', \
         analytical(x)                                     w l lw 3 dt 3 lc 0 t 'analytical'


    set output 'probe.png'
    set xlabel 't'
    set ylabel 'u'
    plot '../postProcessing/probes/0/U.gas1' u 1:2 '%lf (%lf %lf %lf)' w l lw 2      t 'gas1'           , \
         '../postProcessing/probes/0/U.gas2' u 1:2 '%lf (%lf %lf %lf)' w l lw 2 dt 2 t 'gas2'           , \
            'postProcessing/probes/0/U.gas1' u 1:2 '%lf (%lf %lf %lf)' w l lw 2      t 'reference gas1' , \
            'postProcessing/probes/0/U.gas2' u 1:2 '%lf (%lf %lf %lf)' w l lw 2 dt 2 t 'reference gas2'

EOF

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