E3. What foresight adds
Goal: foresight's extensions in a script that still runs in gnuplot.
gnuplot
# foresight's extensions, kept out of gnuplot's way: gnuplot reads the else branches
$P << EOD
1 3.00
2 2.61
3 2.43
4 2.37
5 2.35
EOD
set title 'pressure'
set xlabel 'iteration'
if (strstrt(GPVAL_TERMINALS, 'html') > 0) {
set terminal svg size 600,320 theme vfd # a theme: the colors of a 1980s car dashboard
set output 'pe03.svg'
set caption 'The pressure of the run.' # for a report (save's info), not drawn
set readout vertical top right
unset key
plot $P using 1:2 with lines title 'p', '' using 2 with readout format '%5.2f' title 'P'
} else {
set terminal pngcairo size 600,320
set output 'pe03.png'
plot $P using 1:2 with lines title 'p'
}Why it works
- foresight's own words are few and named:
themeon the terminals (classic,washi,night,vfd,lcd,paper), the stylesreadoutandgauge,set readout,set caption,set table ... markdown, thehtmlterminal and its viewer. gnuplot stops on each of them, so they go in the branch only foresight reads. if (...) { ... } else { ... }is gnuplot's blockif: both programs parse the whole block and run one branch.- Everything else in the script is gnuplot's: a script that keeps its extensions in such branches runs in both.
Try this
theme washiandtheme night: the light and dark colors of these pages.with gaugeinstead ofwith readout: a dial.set table 'p.md' markdownandplot $P with table: the data as a Markdown table (F2).
Pitfalls
- Inline data (
'-') cannot be read inside a{ }block: use a datablock ($P << EOD) as above. GPVAL_VERSIONis 6.0 in both programs: test the terminals, not the version.
Reference: themes, readouts. Next: E4. What foresight does not do.