#!/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

gnuplot<<EOF
    set term pngcairo
    set output '../postProcessing/report/species.png'

    set xlabel 't (s)'
    set ylabel 'Y (-)'
    set y2label '{/Symbol a} (-)'
    set ytics nomirror
    set y2tics nomirror
    set key center

    dir = '../postProcessing/probes(points=((0.50.50.5)),fields=(alpha.particlesTiCl4.vapourO2.vapourCl2.vapour))/0'

    plot ''.dir.'/TiCl4.vapour' w l t 'TiCl4',\
    ''.dir.'/O2.vapour' w l t 'O2',\
    ''.dir.'/Cl2.vapour' w l t 'Cl2',\
    ''.dir.'/alpha.particles' axis x1y2 w l t '{/Symbol a}_{particles}'
EOF

gnuplot<<EOF
    set term pngcairo
    set output '../postProcessing/report/sizeDistribution.png'

    set xlabel 'd_{m} ({/Symbol m}m)'
    set ylabel 'N_i/N_t/{/Symbol D}ln d'
    set logscale
    set tics format '%1.e'
    set yrange[1e-3:]
    set xrange[:1e1]

    result = system("ls ../postProcessing/numberDensity/$(foamListTimes -case .. | tail -1)/numberDensity.csv")

    plot '../validation/exptData/sizeDistribution' w p t 'Akhtar (1991) exp.',\
    result u (\$1/1e-6):2 w lp t 'Result'
EOF

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