#!/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 '../species.eps'

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

    file = system("ls ../postProcessing/singleGraph/$(foamListTimes -case .. | tail -1)/*.xy")

    plot file u 1:2 w l t 'TiCl4',\
    file u 1:3 w l t 'O2',\
    file u 1:4 w l t 'Cl2',\
    file u 1:5 axis x1y2 w l t '{/Symbol a}_{particles}'
EOF

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

    set xlabel 'Mobility diameter ({/Symbol m}m)'
    set ylabel 'N_i/N_t/{/Symbol D}ln d'
    set y2label '{/Symbol k} (m^{-1})'
    set logscale xyy2
    set tics format '%1.e'
    set ytics nomirror
    set y2tics nomirror
    set xrange [1e-3:1]
    set yrange [1e-3:3]

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

    plot result u (\$3/1e-6):4 w lp t 'Size distribution',\
    result u (\$3/1e-6):(\$2/\$1) axis x1y2 w l t '{/Symbol k}',\
    result u (\$3/1e-6):(6./((6./pi*\$1)**(1./3.))) axis x1y2 w l t '{/Symbol k} lower bound'
EOF

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