Skip to content

5. CSV and expressions ​

Many tools write CSV with a header row, run.csv too:

text
$ head -n 3 run.csv
iteration,continuity,momentum,energy,cd,dcd
1, 1.00482E+00, 4.51026E-01, 1.77828E+00, 5.36869E-01, 4.00000E-02
2, 9.88751E-01, 4.03780E-01, 1.58489E+00, 5.18076E-01, 2.82843E-02

Tell foresight the separator, and the header names the columns:

gnuplot
set datafile separator comma
set key autotitle columnhead
gnuplot
plot 'run.csv' using "iteration":(column("cd") * 1e4), \
     ''        using 1:($1 > 60 ? $5 * 1e4 : 1/0) with points pt 6 title 'after the restart'
wheel: zoom · drag: pan · right drag: box · a resetopen page ↗
  • set datafile separator comma (or tab, or any characters ";,"): every separator ends a cell; an empty cell is a gap. unset datafile goes back to whitespace.
  • A quoted name selects a column by its header: using "iteration":..., and column("cd") inside an expression.
  • set key autotitle columnhead titles each item with the header of its y column; an explicit title still wins. Once headers are in use, the first row of each dataset is a header, not a point.
  • A parenthesized field is an expression evaluated on each row: $5 and column(5) are column 5, $0 the point number; gnuplot's operators and functions, its integer division included.
  • 1/0 is undefined: ($1 > 60 ? $5 * 1e4 : 1/0) keeps the points after the restart and drops the others.

What you learned

CSV, columns by name, titles from the header, computed columns and filters. Reference: Data Files, gnuplot Subset, expressions.

Next: 6. Two axes and a model.