#!/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

#\*-----------------------------General settings------------------------------*/

PATH    = '../postProcessing/'
RPATH   = 'reference/'

LIST = system("foamListTimes -case ..")
NUM  = words(LIST)
TIMES(n) = word(LIST,n)

set terminal pngcairo
set grid

set style line 1 dt 2 lt 1 lw 2 pt 2 lc "black"
set style line 2 dt 3 lt 1 lw 3 pt 2 lc "black"
set style line 3      lt 3 lw 2 pt 2 lc "green"
set style line 4      lt 3 lw 3 pt 2 lc "green"

#\*------------------------------Horizontal line------------------------------*/
set output '../postProcessing/report/horizontalLine.png'

FILE(n) =  PATH.'horizontalLine/'.TIMES(n).'/line.csv'
RFILE   = RPATH.'horizontalLine/10/line.csv'

set xlabel  'x'
set xrange  [0:2.04]
set ylabel  'r_{/Symbol a}'
set yrange  [-0.05:1.05]
plot RFILE     u (column('x')):(column('alpha.waterC')) w l ls 3 t 'waterC - Reference '    , \
     RFILE     u (column('x')):(column('alpha.airD'))   w l ls 4 t 'airD - Reference '      , \
     FILE(NUM) u (column('x')):(column('alpha.waterC')) w l ls 1 t 'waterC - Simulation'    , \
     FILE(NUM) u (column('x')):(column('alpha.airD'))   w l ls 2 t 'airD - Simulation'


set output '../postProcessing/report/horizontalLine_evolution.png'

set palette defined
set cbrange [0:]
set cblabel 't'
plot for [i=1:NUM] FILE(i) u (column('x')):(column('alpha.waterC')) w l ls 1 lc palette cb i notitle

set autoscale xy

#\*-------------------------------Vertical line-------------------------------*/
set output '../postProcessing/report/verticalLine.png'

FILE(n) =   PATH.'verticalLine/'.TIMES(n).'/line.csv'

set xlabel  'r_{/Symbol a}'
set xrange [-0.05:1.05]
set ylabel  'y'
plot FILE(NUM) u (column('alpha.waterC')):(column('y')) w l ls 1 t 'waterC - Simulation'    , \
     FILE(NUM) u (column('alpha.airD'  )):(column('y')) w l ls 2 t 'airD - Simulation'

EOF

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