Block comments in gnuplot

末鹿安然 提交于 2021-02-07 12:09:49

问题


I have a quite long gnuplot script. For debugging purposes, I would like to be able to block comment parts of this script or use a "goto" statement. Is this possible?

I know I can use an if statement:

if (1 == 2) {
commented-out-code
} else {
non-commented-out code
}

Is this the only solution?


回答1:


Comments in gnuplot start with a #. If you want to comment a whole block, your text editor should be able to do that (e.g. M-; in Emacs with the block selected).




回答2:


Gnuplot doesn't support block comments (as of version 5). But since Gnuplot interprets your script, the solution you gave does the job. But instead of using an expression to be falsified (evaluated to 0), use a maximally obvious notation (for safety add a comment for its purpose). Spare the else block as it's noting but complicating things.

Look on the following example, to see that it's not as easy as one might think.

if (0) { # commented-out block
This block is completely ignored by Gnuplot.
Well, obviously not completely...
# }{
...because Gnuplot is not just looking for the closing curly brace ;-)
}



回答3:


Another solution to the one proposed by @choroba is to separate the parts of the script into different files, then manage a "master" file that calls the ones you haven't commented:

# master script
load "part1.plt"
#load "part2.plt"
load "part3.plt"


来源:https://stackoverflow.com/questions/28050498/block-comments-in-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!