我希望将所有数据组织在一个文件中,以避免有 31 个输入文件,同时生成 31 个单独的输出 svg 文件。此外,我需要输出文件名与输入文件中给出的名称相对应,即输出文件示例名称“1-1.svg”,其中数字可能会发生变化。输入文件的示例如下所示:
"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
至于脚本本身,如下所示。根据我的想象,for 循环部分必须进行调整,并且
myFileIn(i) = sprintf("%d.dat",i)
可能会更改为 myFileIn = sprint("total.dat")
。至于myFileOut(i) = sprintf("%d.svg",i)
我不确定。
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
您的脚本需要进行一些小的更改。 幸运的是,数据由两个空行分隔。这样,您可以简单地通过
index
寻址子块(选中 help index
)。此外,您可以(错误)使用 stats
来提取一些数字或字符串而不绘制任何内容。您将提取限制为第 i 个块 (index i
) 和该块的第一行 (every ::::0
),选中 help every
。指数是从零开始的。
数据:
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
脚本:
### 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 index i u 0:2:(dx):xtic(makebold(strcol(1))) w xerr lc "blue" lw 3 ps 0 ti columnheader(2), \
'' index i u 0:3:(dx) w xerr lc "red" lw 3 ps 0 ti columnheader(3), \
x1=y1=NaN '' 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 '' 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
结果:(只有一个文件:
0-3.svg
)