#!/bin/sh

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

gnuplot<<EOF
    set terminal postscript eps color enhanced font "Helvetica,20"
    set output '../void_fraction.eps'

    set xlabel 'r (mm)'
    set ylabel '{/Symbol a} (-)'

    alpha = system("ls ../postProcessing/singleGraph/$(foamListTimes -case .. -latestTime)/line_alpha*.xy")
    forces = system("ls ../postProcessing/singleGraph/$(foamListTimes -case .. -latestTime)/line_lift*.xy")

    plot alpha u (\$1*1000):4 w l lw 3 lc rgb 'black' t 'total',\
    alpha u (\$1*1000):2 w l lw 2 lc rgb 'green' t 'd < 5.5mm',\
    alpha u (\$1*1000):3 w l lw 2 lc rgb 'red' t 'd > 5.5mm'

    set output '../nonDragForces.eps'

    set ylabel 'F_{r} (N/m^3)'

    plot forces u (\$1*1000):(-\$2) w l lw 2 t 'Lift',\
    forces u (\$1*1000):(-\$5) w l lw 2 t 'Wall lubrication',\
    forces u (\$1*1000):(-\$8) w l lw 2 t 'Turbulent dispersion'
EOF

gnuplot<<EOF
    set terminal postscript eps color enhanced font "Helvetica,20"
    set output '../volumeDensity.eps'

    set xlabel 'd (mm)'
    set ylabel '({/Symbol a}/{/Symbol a}_{tot})/{/Symbol D}d (mm^{-1})'
    set xtics 1

    injection = system("ls ../postProcessing/probabilityDensity.injection/$(foamListTimes -case .. | tail -1)/*.dat")
    outlet = system("ls ../postProcessing/probabilityDensity.outlet/$(foamListTimes -case .. | tail -1)/*.dat")

    plot injection u (\$3/1e-3):(\$4/1e3) w histeps lw 3 lc rgb 'green' t 'injection',\
    outlet u (\$3/1e-3):(\$4/1e3) w histeps lw 3 lc rgb 'red' t 'outlet'
EOF

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