Hello,
I usually generate datafiles for gnuplot using an automated test station.
For documentation purposes, metadata about a test run are stored inside the datafile as comments.
This metadata can be as simple as the time when the test started. Or it contains parameters that change from test run to test run (e.g., voltage, temperature, ...). Or any important information that pertains to a test and should be stored along with the data. This metadata can be used when creating diagrams for a test report, e.g., to give a diagram an appropriate title.
Currently, gnuplot does not provide a command to specifically access metadata.
Thus, I have to use a "hack" as described here: https://stackoverflow.com/a/72306388/2987152
This "hack" uses the stats
command to extract metadata from a datafile.
I'd like to suggest a feature that allows gnuplot to extract metadata (for example JSON or simple key=value pairs) from datafiles into gnuplot variables.
Please let me have your comments.
Thank you.
Dan
I suggest that you use gnuplot's plugin mechanism to load a function that retrieves the desired information by calling an external library or custom-written program that knows how to interpret JSON or whatever other custom format you like. There is sample code and a README in the
demo/plugin
directory of the gnuplot distribution. The examples there are for wrapping numerical routines from an external math library and returning a numerical value, but the same mechanism should work for wrapping a query to a text-handling library and returning a string value.Last edit: Ethan Merritt 2025-05-14
For a simpler case you could just invoke a shell command. For instance if your data file will somewhere contain a line that begins with the comment character and contains the string
Measurement date = <some date>
you could retrieve that line from inside gnuplot like this:Data file:
Gnuplot session:
Thanks, Ethan, for your suggestions. 👍 Those are surely viable solutions. Clearly, I could run gnuplot using WSL and an xserver to be able to use "grep" and I've done that before. However, I was hoping for a genuine gnuplot solution for all users, i.e., a solution that would also work in Windows cmd.exe where "grep" is not available and without having to compile gnuplot.
Last edit: Daniel Dan K. 2025-05-15