#!/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 3 dt 1 pt 7 ps 0.5
set linetype 2 lc rgb "black" lw 3 dt 2 pt 9 ps 0.5
set linetype 3 lc rgb "blue"  lw 3      pt 5 ps 0.5

set grid
set key outside below

PATH =      "../postProcessing/"
RPATH =     "reference/"


#---PNG---
set terminal pngcairo color enhanced size 800,600
FType = '.png'

#---residuals---
FILE =      "residuals/0/residuals.dat"

set output "../postProcessing/report/residuals".FType
set xlabel  "t"
set ylabel  "initial residuals p_{rgh}"
set logscale y
set format y "10^{%T}"
plot PATH.FILE u 1:2 w l lw 2 notitle

unset logscale y
set format y "%g"


#---bubbleProperties---
FILE =      "bubbleProperties/0/bubbleProperties.dat"

set output "../postProcessing/report/bubblePosition".FType
set xlabel  "t"
set ylabel  "CG.y"
plot  PATH.FILE u 1:3 w l lt 1 t "current"                  , \
     RPATH.FILE u 1:3 w l lt 2 t "reference"

set output "../postProcessing/report/bubbleVelocity".FType
set ylabel  "U_b.y"
plot  PATH.FILE u 1:6    w l lt 1 t "current"               , \
     RPATH.FILE u 1:6    w l lt 2 t "reference"

set output "../postProcessing/report/bubbleCircularity".FType
set ylabel  "c"
plot  PATH.FILE u 1:10  w l lt 1 t "current"                , \
     RPATH.FILE u 1:10  w l lt 2 t "reference"
unset yrange

EOF

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