用户定义的命令,如gdb';在gnuplot终端中定义多个命令?
我想我会记录下这个(下面是自我回答): 在终端中使用用户定义的命令,如gdb';在gnuplot终端中定义多个命令?,gnuplot,Gnuplot,我想我会记录下这个(下面是自我回答): 在终端中使用gnuplot时,可以使用键盘上的上下箭头来迭代输入的命令历史记录,就像在gdb中一样 然而,有时可能会有一系列我经常重复的命令——我希望通过发出单个命令来调用这些命令。例如,您可以在gnuplot中使用交互式x11终端,并希望获得png格式的“屏幕截图”。这需要将终端更改为png,设置输出,发布绘图,并将终端恢复为x11;或: set terminal png set output 'gnuplot.png' replot set termi
gnuplot
时,可以使用键盘上的上下箭头来迭代输入的命令历史记录,就像在gdb
中一样
然而,有时可能会有一系列我经常重复的命令——我希望通过发出单个命令来调用这些命令。例如,您可以在gnuplot
中使用交互式x11
终端,并希望获得png
格式的“屏幕截图”。这需要将终端更改为png
,设置输出,发布绘图
,并将终端恢复为x11
;或:
set terminal png
set output 'gnuplot.png'
replot
set terminal x11
我希望使用单个命令调用此序列-尽管我知道这些命令可以放在一行中,使用分号作为分隔符:
set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11
在gdb
中,有一个命令,允许:;只需在gdb
终端中发布:
(gdb) define fn
> finish
> next
> end
。。。从那时起,人们可以在终端中键入fn
,调用finish
和end
的序列
是否有类似于
gnuplot
中的功能?是的,似乎有-在gnuplot
中有一个名为宏(help macros
)的功能,可以通过在其名称前面加上@
(“at”字符)来扩展字符串变量
默认情况下,此功能处于禁用状态,因此需要考虑启用它。这就是为什么最好将该序列保存在一个名为instanceinit.gp的init脚本文件中:
print ""
print "init.gp starting"
set terminal x11
# define capt string variable as sequence
# of commands, semicolon separated
capt = "print 'Saving...' ; set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11"
print "macros state: "
show macros
print "enabling macros state:"
set macros
show macros
print "The @capt command should be available now."
print ""
print "init.gp ending"
print ""
然后可以在gnuplot
中执行这样的终端会话:
$ gnuplot
G N U P L O T
[...]
Terminal type set to 'wxt'
gnuplot> load "init.gp"
init.gp starting
macros state:
command line macros will not be expanded
enabling macros state:
command line macros will be expanded
The @capt command should be available now.
init.gp ending
gnuplot> plot sin(x)
gnuplot> @capt
Saving...
Terminal type set to 'png'
Options are 'nocrop font /usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf 12 size 640,480 '
Terminal type set to 'x11'
Options are ' nopersist'
gnuplot> plot cos(x)
Closing gnuplot.png
gnuplot> exit
$ identify gnuplot.png
gnuplot.png PNG 640x480 640x480+0+0 8-bit PseudoClass 102c 5.58KB 0.000u 0:00.000
好吧,希望这对某人有所帮助,
干杯 是的,似乎有-在gnuplot
中有一个名为macros(help macros
)的工具,其中字符串变量可以通过在其名称前面加上@
(“at”字符)来展开
默认情况下,此功能处于禁用状态,因此需要考虑启用它。这就是为什么最好将该序列保存在一个名为instanceinit.gp的init脚本文件中:
print ""
print "init.gp starting"
set terminal x11
# define capt string variable as sequence
# of commands, semicolon separated
capt = "print 'Saving...' ; set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11"
print "macros state: "
show macros
print "enabling macros state:"
set macros
show macros
print "The @capt command should be available now."
print ""
print "init.gp ending"
print ""
然后可以在gnuplot
中执行这样的终端会话:
$ gnuplot
G N U P L O T
[...]
Terminal type set to 'wxt'
gnuplot> load "init.gp"
init.gp starting
macros state:
command line macros will not be expanded
enabling macros state:
command line macros will be expanded
The @capt command should be available now.
init.gp ending
gnuplot> plot sin(x)
gnuplot> @capt
Saving...
Terminal type set to 'png'
Options are 'nocrop font /usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf 12 size 640,480 '
Terminal type set to 'x11'
Options are ' nopersist'
gnuplot> plot cos(x)
Closing gnuplot.png
gnuplot> exit
$ identify gnuplot.png
gnuplot.png PNG 640x480 640x480+0+0 8-bit PseudoClass 102c 5.58KB 0.000u 0:00.000
好吧,希望这对某人有所帮助,
干杯 作为旁注,当您开始在交互模式下工作时,gnuplot在用户的主目录中查找.gnuplot
(在*NIX上--不确定windows上的文件是什么)。然后将自动加载该脚本。还有一个环境变量GNUPLOT_LIB
,它是一个load
将搜索请求的文件的目录。另外,当您开始在交互模式下工作时,GNUPLOT在用户的主目录中查找.GNUPLOT
(在*NIX上--不确定windows上的文件是什么)。然后将自动加载该脚本。还有一个环境变量GNUPLOT_LIB
,它是一个load
将搜索请求文件的目录。