Menu

#589 Extract metadata from datafiles natively

open
nobody
metadata (1)
5
2025-05-15
2025-05-14
No

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

Discussion

  • Ethan Merritt

    Ethan Merritt - 2025-05-14

    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
    • Ethan Merritt

      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:

      # example of data file containing metadata as comments
      #
      # Collection Date = 14 May 2025
      # Location = back yard
      #
      1 5 6   dandelion
      2 8 90  weed
      3 7 55  rock
      

      Gnuplot session:

      gnuplot> DATAFILE = 'foo.dat'
      gnuplot> QUERY = "grep 'Collection Date = ' " . DATAFILE
      gnuplot> TITLE = system(QUERY)
      gnuplot>
      gnuplot> unset tics; unset border
      gnuplot>
      gnuplot> set title TITLE
      gnuplot> plot DATAFILE using 1:2:4 with labels notitle
      gnuplot> 
      
       
  • Daniel Dan K.

    Daniel Dan K. - 2025-05-15

    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

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.