【问题标题】:How do I check if a terminal is available through my gnuplot script?如何通过我的 gnuplot 脚本检查终端是否可用?
【发布时间】:2013-12-18 21:18:22
【问题描述】:

每当 pngcairo 终端可用时,我想将终端设置为 pngcairo 而不是 png, 而且我不想手动检查它的可用性并每次都更新我的脚本。

当 pngcairo 终端不可用时,我的脚本中出现以下错误:

set terminal pngcairo
             ^
"./script.gnuplot", line 7: unknown or ambiguous terminal type; type just 'set terminal' for a list

如何在我的 gnuplot 脚本中测试 pngcairo 的可用性,以便在它不存在时将终端设置为 png?

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    所有可用的终端都可以通过变量GPVAL_TERMINALS 获得,参见show variables all。使用strstrt 函数,您可以检查pngcairo 是否可用:

    if (strstrt(GPVAL_TERMINALS, 'pngcairo') > 0) {
        set terminal pngcairo
    } else {
        set terminal png
    }
    

    【讨论】:

    • 没看懂,能不能详细说一下这个strstrt
    • strstrt("string","key") 在“string”中搜索字符串“key”,返回“key”第一个字符的索引。如果未找到“key”,则返回 0。类似于 C 库函数 strstr,不同之处在于它返回索引而不是字符串指针。 strstrt("hayneedlestack","needle") = 4.
    猜你喜欢
    • 2011-10-20
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-02
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多