#!/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 output '../d.air_y.png'

    set xlabel 'd (mm)'
    set ylabel 'y (m)'
    set key bottom center

    latestTime = system("foamListTimes -case .. -latestTime")
    p0 = $(tail -n1 ../postProcessing/cellZoneAverage/0/volFieldValue.dat | awk '{print $2}')
    file = '../postProcessing/graph/'.latestTime.'/line.xy'

    plot file u (\$2*1000):1 w l lc rgb 'black' t 'prediction',\
    'line.xy' u (\$2*1000):1 w l lc rgb 'red' lw 3 t 'prediction Ref.',\
    file u (0.003*(p0/\$3)**(1./3.)*1000):1 w l dt 2 lc rgb 'black' t 'exact result'

    set output '../alpha.air_y.png'

    set xlabel '{/Symbol a} (-)'

    plot file u 4:1 w l dt 2 lc rgb 'black' t 'air1',\
    file u 5:1 w l dt 3 lc rgb 'black' t 'air2',\
    file u 6:1 w l dt 4 lc rgb 'black' t 'air3',\
    'line.xy' u 4:1 w l dt 2 lc rgb 'red' lw 3 t 'air1 Ref.',\
    'line.xy' u 5:1 w l dt 3 lc rgb 'red' lw 3 t 'air2 Ref.',\
    'line.xy' u 6:1 w l dt 4 lc rgb 'red' lw 3 t 'air3 Ref.',\
    'line.xy' u 7:1 w l lc rgb 'red' lw 3 t 'air total Ref.',\
    file u 7:1 w l lc rgb 'black' t 'air total'
EOF

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