#!/bin/bash
OUT="basic_diagn.pdf"
XKEY="11.5"
plot="set terminal pdfcairo enhanced size 3.5,3.1 font ', 9';set out '$OUT';"
plot="$plot set xrange [3:27];set lmargin 8;set rmargin 1;set tmargin 1;set bmargin 3;set title 'Golem shot No:12529' offset 0,-1;"
plot="$plot set multiplot;set size 1,0.285;set format x '';set xtics 2;"
plot="$plot;set origin 0,0.715;set format y '%.0f';set ytics 5;set key at $XKEY, 29;set ylabel 'U_{l} [V]' offset -2;set yrange [-0.5:31];plot '< wget -q -O - http://golem.fjfi.cvut.cz/utils/data/$(ShotNo)/loop_voltage' u (\$1*1000):(\$2) w l lw 2 lc rgb '#0000aa' title 'Loop voltage'; unset title;"
plot="$plot;set origin 0,0.5361;set format y '%.2f';set yrange [-0.01:0.32];set key at $XKEY, 0.3;set ytics 0.06;set ylabel 'B_{t} [T]' offset 0;plot 'toroidal_field_12529.txt' u (\$1*1000):(\$2) w l lw 2 lc rgb '#0000aa' title 'Toroidal mag. field';"
plot="$plot;set origin 0,0.3574;set format y '%.1f';set yrange [-0.1:4.4];set key at $XKEY, 4.1;set ytics 0.8;set ylabel 'I_{pl} [kA]' offset -1;plot 'plasma_current_12529.txt' u (\$1*1000):(\$2/1000) w l lw 2 lc rgb '#0000aa' title 'Plasma current';"
plot="$plot;set origin 0,0.1787;;set format y '%.2f';set yrange [-0.006:0.22];set key at $XKEY, 0.205;set ytics 0.04;set ylabel 'Intensity [a.u.]' offset 0;plot 'photodiode_alpha_12529.txt' u (\$1*1000):(\$2) w l lw 2 lc rgb '#00aa88' title 'H_{/Symbol a}','photodiode_12529.txt' u (\$1*1000):(\$2) w l lw 2 lc rgb '#0000aa' title 'Visible',;"
plot="$plot;set origin 0,0;set ylabel 'n_e [10^{18} m^{-3}]' offset -3.3;set key at $XKEY, 5;set format y '%.0f';set yrange [-0.15:5.5];set ytics 1;set xlabel 'time [ms]';set format x '%.0f';plot 'electron_density_12529.txt' u (\$1*1000):(\$2*1e-19) w l lw 2 lc rgb '#0000aa' title 'Electron density';"
# GPf=set datafile separator ';';set xrange [0:$(XRANGE)];set tmargin 0;set bmargin 1;set lmargin $(LMARGIN);set format y '%3.1f';set rmargin 3;set multiplot;set title 'Golem shot No:`cat ../ShotNo`';set size $(SIZEX),$(SIZEY);set origin 0,$(OR1);set ylabel 'U_{loop} [V]';unset key;unset xtics;set style data dots; set yrange [-5:30];plot 'Uloop_dp.csv' u 1:2;\
# unset title; set origin 0,$(OR2);set ylabel 'B_t [T]';set format y '%3.2f';unset key;unset xtics;set yrange [-0.05:*];plot 'Btoroidal_dp.csv';\
# unset title; set origin 0,$(OR3);set ylabel 'I_{p+ch} [kA]';set format y '%3.1f';unset key;unset xtics;set yrange [*:*];plot 'Irogowski_dp.csv' u 1:(\$$2/1000);\
# unset title; set origin 0,$(OR4);set ylabel 'Photod [a.u.]';set format y '%3.2f';unset key;set xtics ('5' 5,'10' 10, '15' 15, '20' 20, '25' 25, '30' 30);set xlabel 'Time [ms]';set yrange [*:*];plot 'Photod_dp.csv';\
# plot="$plot ;unset obj 1;set size 1,0.55;set origin 0,0;unset x2tics;set y2tics 120;set xtics nomirror;set xlabel 't[ms]';set ylabel 'f_{pd}(t_i) [a.u.]';unset arrow 1;set key left bottom;unset arrow 2;unset title;set xrange[16.5:24.6];set yrange[-10:10];plot '< wget -q -O - http://golem.fjfi.cvut.cz/shots/16690/DAS/0513NIturbo_RT.ON/NiData.txt' u (\$1*1000):(\$5*-1) w l lw 2 title 'f_{pd}', '< wget -q -O - http://golem.fjfi.cvut.cz/shots/16690/DAS/0513NIturbo_RT.ON/NiData.txt' u (\$1*1000):(\$6*-1/0.005) axis x1y2 w l lw 2 title 'I_{VSt}'"
echo $plot | gnuplot -persist
okular $OUT