Issue
I would like to keep all the data organized in one single file to avoid having 31 input files, while generating 31 separate output svg files. Additionally I need the output file names to correspond to the name given in the input file, i.e. output file example name "1-1.svg", where the digits are subject to change. An example of the input file would look like the following:
"0-3" #name of svg file
"Reaction Coordinate" "0 V" "0.79 V"
O_{2} 0 -3.17
O@^*_{2} -0.21 -3.39
OOH^* -1.01 -3.39
O^* -2.60 -4.19
OH^* -4.12 -4.92
H_{2}O -4.92 -4.92
"1-1" #name of svg file
"Reaction Coordinate" "0 V" "0.25 V"
O_{2} 0 -3.17
O@^*_{2} -0.21 -3.39
OOH^* -1.01 -3.39
O^* -2.60 -4.19
OH^* -4.12 -4.92
H_{2}O -4.92 -4.92
"2-5" #name of svg file
"Reaction Coordinate" "0 V" "0.14 V"
O_{2} 0 -3.17
O@^*_{2} -0.21 -3.39
OOH^* -1.01 -3.39
O^* -2.60 -4.19
OH^* -4.12 -4.92
H_{2}O -4.92 -4.92
As for the script itself, this is what it looks like below. From what I imagine, the for loop portion has to be adjusted and the myFileIn(i) = sprintf("%d.dat",i)
can likely be changed to myFileIn = sprint("total.dat")
possibly. As for the myFileOut(i) = sprintf("%d.svg",i)
I am not sure.
myFileIn(i) = sprintf("%d.dat",i)
myFileOut(i) = sprintf("%d.svg",i)
set term svg font "{/:Bold}Sans,25"
makebold(text) = sprintf("{/:Bold %s}", text)
set border 15 front lt black linewidth 3.000 dashtype solid
set xlabel "Reaction Coordinate"
set xrange [-0.2:5.2]
set xtics nomirror scale 0
set ylabel "Free Energy (eV)"
set ylabel offset character 1.3,0,0 font "{/:Bold},25"
set xlabel offset character 0,0.6,0 font "{/:Bold},25"
set yrange[-5:0.1]
set ytics in nomirror font "{/:Bold},25"
set key noautotitle samplen 2
set key enhanced
set errorbars 0
dx = 0.2
do for [i=1:4] {
set output myFileOut(i)
plot myFileIn(i) u 0:2:(dx):xtic(makebold(strcol(1))) w xerr lc "blue" lw 3 ps 0 ti columnheader(2), \
'' u 0:3:(dx) w xerr lc "red" lw 3 ps 0 ti columnheader(3), \
x1=y1=NaN '' u (x0=x1,x1=$0,x0-1+dx):(y0=y1,y1=$2,y0):(1-2*dx):(y1-y0) w vec dt 4 lc "blue" nohead, \
x1=y1=NaN '' u (x0=x1,x1=$0,x0-1+dx):(y0=y1,y1=$3,y0):(1-2*dx):(y1-y0) w vec dt 4 lc "red" nohead
}
set output # close the last file
### end of script
Solution
Some small changes are required to your script.
Luckily, you have the data separated by two empty lines. With this, you can simply address the subblocks via index
(check help index
). Furthermore, you can (mis)use stats
to extract some numbers or strings without plotting anything. You limit the the extraction to the i-th block (index i
) and the first row of that block (every ::::0
), check help every
. Indices are zero-based.
Data: SO77565285.dat
"0-3" #name of svg file
"Reaction Coordinate" "0 V" "0.79 V"
O_{2} 0 -3.17
O@^*_{2} -0.21 -3.39
OOH^* -1.01 -3.39
O^* -2.60 -4.19
OH^* -4.12 -4.92
H_{2}O -4.92 -4.92
"1-1" #name of svg file
"Reaction Coordinate" "0 V" "0.25 V"
O_{2} 0 -3.17
O@^*_{2} -0.21 -3.39
OOH^* -1.01 -3.39
O^* -2.60 -4.19
OH^* -4.12 -4.92
H_{2}O -4.92 -4.92
"2-5" #name of svg file
"Reaction Coordinate" "0 V" "0.14 V"
O_{2} 0 -3.17
O@^*_{2} -0.21 -3.39
OOH^* -1.01 -3.39
O^* -2.60 -4.19
OH^* -4.12 -4.92
H_{2}O -4.92 -4.92
Script:
### create multiple SVG files from multiple subblocks
reset session
FILE = "SO77565285.dat"
set term svg font "{/:Bold}Sans,25"
makebold(text) = sprintf("{/:Bold %s}", text)
set border 15 front lt black linewidth 3.000 dashtype solid
set xlabel "Reaction Coordinate"
set xrange [-0.2:5.2]
set xtics nomirror scale 0
set ylabel "Free Energy (eV)"
set ylabel offset character 1.3,0,0 font "{/:Bold},25"
set xlabel offset character 0,0.6,0 font "{/:Bold},25"
set yrange[-5:0.1]
set ytics in nomirror font "{/:Bold},25"
set key noautotitle samplen 2
set key enhanced
set errorbars 0
dx = 0.2
myFileOut(s) = sprintf("%s.svg",s)
do for [i=0:2] {
stats FILE index i every ::::0 u (s=strcol(1),0) nooutput
set output myFileOut(s)
plot FILE skip 1 index i u 0:2:(dx):xtic(makebold(strcol(1))) w xerr lc "blue" lw 3 ps 0 ti columnheader(2), \
'' skip 1 index i u 0:3:(dx) w xerr lc "red" lw 3 ps 0 ti columnheader(3), \
x1=y1=NaN '' skip 1 index i u (x0=x1,x1=$0,x0-1+dx):(y0=y1,y1=$2,y0):(1-2*dx):(y1-y0) w vec dt 4 lc "blue" nohead, \
x1=y1=NaN '' skip 1 index i u (x0=x1,x1=$0,x0-1+dx):(y0=y1,y1=$3,y0):(1-2*dx):(y1-y0) w vec dt 4 lc "red" nohead
}
set output # close the last file
### end of script
Result: (just one file: 0-3.svg
)
Answered By - theozh Answer Checked By - Robin (WPSolving Admin)