#!/bin/bash

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

gnuplot<<EOF

    set terminal pngcairo color enhanced size 800,600
    set grid

    #---particleHoldup---
    set output 'particle_holdup.png'

    FILE  = '../postProcessing/particleHoldup/0/volFieldValue.dat'
    RFILE = 'particleHoldup/0/volFieldValue.dat'

    set xlabel 't [s]'
    set ylabel '{/Symbol a}_S [-]'

    plot RFILE w l      lw 2 t 'Reference'  , \
          FILE w l dt 2 lw 2 t 'Current'

    #---graph---
    PATH = '../postProcessing/graph/'

    LIST = system("ls -1 ".PATH." | sort -g")
    NUM = words(LIST)
    TIMES(n) = word(LIST,n)

    FILES(n) = PATH.TIMES(n)."/line.csv"

    set xlabel 'y [m]'
    set yrange [0:0.02]
    set ylabel '{/Symbol a} [-]'

    do for [i=1:NUM] {
        TIME = sprintf("%.2i", TIMES(i)+0)

        set output 'particle_distribution_'.TIME.'.png'

        set title 't = '.TIME.' s'

        plot FILES(i) u 1:(\$2*0):2                     w filledcu t "particle" , \
             FILES(i) u 1:2      :(\$2+\$3*\$4*\$7/\$6) w filledcu t "particle aggregate"
    }

EOF

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