#!/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 linetype 1 lc rgb "red"     lw 2 dt 1
    set linetype 2 lc rgb "blue"    lw 2 dt 1
    set linetype 3 lc rgb "green"   lw 2 dt 1
    set linetype 4 lc rgb "black"   lw 2 dt 2
    set linetype 5 lc rgb "orange"  lw 2 dt 2
    set linetype 6 lc rgb "gray"    lw 2 dt 1
    set linetype 7 lc rgb "pink"    lw 2 dt 1

    set grid
    set key outside below noenhanced

    set terminal pngcairo enhanced

    set grid

    TIME =      system("foamListTimes -latestTime -case ..")

    set output "../postProcessing/report/alpha_shear_spatial.png"
    FILE =      "../postProcessing/graph/".TIME."/line.csv"
    set title   "t = ".TIME." s"
    set xlabel  "x"
    set ylabel 'r_{/Symbol a} [-], {/Symbol t} [N/m^2]'
    plot        FILE  u (column("x")):(column("alpha.water")) w l lt 1 t "alpha water", \
                FILE  u (column("x")):(column("alpha.airD"))  w l lt 2 t "alpha airD", \
                FILE  u (column("x")):(column("alpha.airC"))  w l lt 3 t "alpha airC", \
                FILE  u (column("x")):(column("wallShearStress.water_y")) w l lt 4 t "stress water", \
                FILE  u (column("x")):(column("wallShearStress.airC_y"))  w l lt 5 t "stress airC"

    set output '../postProcessing/report/drag_time.png'
    FILE  =     '../postProcessing/drag/0/surfaceFieldValue.dat'
    unset title
    set xlabel  't [s]'
    set ylabel  'Drag [N]'
    set yrange  [-5:]
    plot        FILE  u 1:(-\$2) '%lf (%lf %lf %lf) (%lf %lf %lf)' w l t 'airC', \
                FILE  u 1:(-\$5) '%lf (%lf %lf %lf) (%lf %lf %lf)' w l t 'water'

EOF

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