#!/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 lw 2
set linetype 2 lw 1

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

set terminal pngcairo
set grid
set key outside below

FILE  = "../postProcessing/line/".TIME."/line.csv"
RFILE = "reference/line.csv"

set output "U.air.png"

set xlabel "U_{air} (m/s)"
set ylabel "z (m)"

plot FILE  u (column("U.air_z")):1 w l t "current", \
     RFILE u (column("U.air_z")):1 w l t "reference"

set output "U.water.png"

set xlabel "U_{water} (m/s)"

plot FILE  u (column("U.water_z")):1 w l t "current", \
     RFILE u (column("U.water_z")):1 w l t "reference", \


set output "alpha.air.png"

set xlabel "{/Symbol a}_{air} (-)"

plot FILE  u (column("alpha.air")):1 w l t "current", \
     RFILE u (column("alpha.air")):1 w l t "reference"


set output "residuals.png"

set xlabel "t (s)"
set ylabel "residuals (-)"
unset yrange
set logscale y
set format  y "10^{%T}"

plot "../postProcessing/residuals/0/residuals.dat" u 1:2 w l notitle

EOF

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