#!/bin/bash

if ! which gnuplot > /dev/null 2>&1
then
    echo 'gnuplot not found - skipping graph creation' >&2
    exit 1
fi

gnuplot<<EOF

    set linetype 1 lc rgb "red"   lw 2 dt 1
    set linetype 2 lc rgb "black" lw 2 dt 1
    set linetype 3 lc rgb "blue"  lw 2 dt 1

    set grid
    set key outside below noenhanced
    set terminal pngcairo enhanced

    AFILE   = "../postProcessing/UAirMaxMagValue/0/volFieldValue.dat"
    WFILE   = "../postProcessing/UWaterMaxMagValue/0/volFieldValue.dat"

    RAFILE  = "reference/postProcessing/UAirMaxMagValue/0/volFieldValue.dat"
    RWFILE  = "reference/postProcessing/UWaterMaxMagValue/0/volFieldValue.dat"

    NAFILE  = "referenceWithout/postProcessing/UAirMaxMagValue/0/volFieldValue.dat"
    NWFILE  = "referenceWithout/postProcessing/UWaterMaxMagValue/0/volFieldValue.dat"

    set output  "UMax.png"
    set title   "Maximum phase velocity magnitude"
    set xlabel  "t (s)"
    set ylabel  "max|U| (m/s)"
    set yrange [0:0.03]
    plot WFILE   u 1:2 w l lt 3      t "water - current", \
         RWFILE  u 1:2 w l lt 3 dt 2 t "water - reference", \
         NWFILE  u 1:2 w l lt 3 dt 4 t "water - no limiter", \
         AFILE   u 1:2 w l lt 1      t "air - current", \
         RAFILE  u 1:2 w l lt 2 dt 2 t "air - reference", \
         NAFILE  u 1:2 w l lt 2 dt 4 t "air - no limiter"

    set output  "UMax-log.png"
    set title   "Maximum phase velocity magnitude"
    set xlabel  "t (s)"
    set ylabel  "max|U| (m/s)"
    unset yrange
    set logscale y
    set format y "10^{%.0T}"
    plot WFILE   u 1:2 w l lt 3      t "water - current", \
         RWFILE  u 1:2 w l lt 3 dt 2 t "water - reference", \
         NWFILE  u 1:2 w l lt 3 dt 4 t "water - no limiter", \
         AFILE   u 1:2 w l lt 1      t "air - current", \
         RAFILE  u 1:2 w l lt 2 dt 2 t "air - reference", \
         NAFILE  u 1:2 w l lt 2 dt 4 t "air - no limiter"

EOF

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