问题
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