2
votes

Is there a way for Gnuplot to read and recognize structured strings? Specifically, I have a few hundred files, all containing measurement data, with measurement conditions defined in the filename.

My files look something like "100d5mK2d0T.txt", which would mean that this data was acquired at 100.5mK temperature and 2.0T magnetic field.

Any chance I could extract the temperature and field strength data from the name, and use them as labels in the plot?

Thanks in advance.

1
How are you running your gnuplot script--interactively or calling a canned script repeatedly? Also, what OS/gnuplot version are you using? - andyras
I would suggest to use external parser. Gnuplot has the c-like sprintf function but not the scanf. Nevertheless some string manipulation is possible. As example name="100d5mK2d0T.txt"; temp = int(name[0:3])+int(name[5:6])/10.0; Bfield = int(name[8:9])+int(name[10:11])/10.0 will do what you want, but this implies the formatting is strictly fixed... It would'n work for strings like 99d5mK2d05T.txt - bibi

1 Answers

2
votes

With gnuplot's internal string processing you could come up with a solution (using substr and strstrt), but thats quite verbose.

Its better to use an external tool for the string processing, like perl:

filename = '100d5mK2d0T.txt'
str = system('echo "'.filename. '" | perl -pe ''s/(\d+)d(\d+)mK(\d+)d(\d+)T.txt/\1.\2 \3.\4/'' ')
temperature = word(str, 1)
magnetic_field = word(str, 2)

set label at graph 0.1,0.9 "Temperature: ".temperature." mK"
set label at graph 0.1,0.8 "Magnetic field: ".magnetic_field." T"