#!/bin/bash

if ! command -v gnuplot > /dev/null 2>&1
then
    echo 'gnuplot not found - skipping graph creation' >&2
    exit 1
else
    mkdir -p ../postProcessing/report
fi

epsilon=$(foamDictionary ../caseParameterDict -entry epsilon -value)
alpha=$(foamDictionary ../caseParameterDict -entry alpha -value)

gnuplot<<EOF

#\*---------------------General settings--------------------------------------*/

TIME = system("foamListTimes -functionEntries -case .. | tail -n1")
CASE = system("foamDictionary ../caseParameterDict -entry case -value")

set term pngcairo

set grid
set key box

set style line 1 dt 2 lt 1 lw 2 pt 2 lc "black"
set style line 2 lt 2 lw 5 pt 2 lc "red"
set style line 3 lt 2 lw 2 pt 2 lc "green"
set style line 4 lt 4 lw 2 pt 2 lc "violet"
set style line 5 lt 5 lw 2 pt 2 lc "cyan"


#\*-------------------Diameter over time--------------------------------------*/

set output '../postProcessing/report/diameter.png'
set xlabel 't (s)'
set ylabel 'd (mm)'

set title '({/Symbol e}_{water} = $epsilon [m^{2}s^{-3}], {/Symbol a}_{air} = $alpha [-])'

plot '../postProcessing/probes(points=((0.50.50.5)),d.air)/0/d.air' u 1:(\$2*1000) t 'Simulation L' w l ls 1

#\*-------------------Size distribution---------------------------------------*/

set output '../postProcessing/report/sizeDistribution.png'
set xlabel 'd (mm)'
set ylabel '({/Symbol a_{i}}/{/Symbol a}_{d})/{/Symbol D} d (mm^{-1})'

set style fill transparent solid 0.5 border

ini = system("ls ../postProcessing/sizeDistributionL/0/sizeDistributionL.csv")
sim = system("ls ../postProcessing/sizeDistributionL/".TIME."/sizeDistributionL.csv")

plot ini u (\$1/1e-3):(\$2/1e3) w boxes lc 'red' t 'Init. cond. (Exp. L)',\
     sim u (\$1/1e-3):(\$2/1e3) w histeps ls 1 t 'Simulation'
EOF

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