|
From: Teo S B. <teo...@gm...> - 2010-02-13 14:09:42
|
On Fri, Feb 12, 2010 at 7:07 PM, Ethan Merritt <merritt@u.washington.edu> wrote: > > On Friday 12 February 2010 09:58:45 Teo S Bernhard wrote: > > Problem: > > Gnuplot script that set parameter repeatedly in plot command to address the > > data index (within a data file) does not work when using gnuplot version > > 4.4.0-rc1. > > It works in 4.2 version and, from memory, did also work in version 4.3. See > > the below shortened example reproducing the error message: > > > > > > # file: trial.gpl > > f(x)=x > > plot a=1, \ > > f(x)*a title "data from index a=1" w l lw 2 lt a , a=a+1, \ > > f(x)*a title "data from index a=2" w l lw 2 lt a , a=a+1, \ > > a=0 > > Please see Bug #2907028 > https://sourceforge.net/tracker/?func=detail&aid=2907028&group_id=2055&atid=102055 > > So far as I can tell from running old versions of gnuplot (back to 3.7), > it never did work correctly to increment a variable multiple times inside > a plot command. I have looked into the code, plot2d.c, regarding this issue. I have a suggestion for a patch that seems to: 1) solve referred Bug #2907028 2) also allow trailing assignments to the plot command. There are spurious print-outs in the patch, I have assumed the intuitive meaning of END_OF_COMMAND. The purpose of the 'was_definition' flag is not clear to me, I set it to TRUE always since I belive that the result of is_definition(...) would guarantee this. I have tested it on small examples similar to those presented in this thread. Review and comments on the conceptual idea as presented below in a diff-form are appreciated. Teo -------------------------------- Diff agains gnuplot-4.4.0-rc1, 'hg diff' was run in ./src-directory: diff -r 9c57e57e6e92 plot2d.c --- a/plot2d.c Fri Feb 12 22:35:43 2010 +0100 +++ b/plot2d.c Sat Feb 13 14:23:04 2010 +0100 @@ -1457,12 +1457,29 @@ newhist_pattern = fs.fillpattern; } else - if (is_definition(c_token)) { - define(); - if (!equals(c_token,",")) { - was_definition = TRUE; - continue; - } + if (is_definition(c_token)) { /*skip over definitions in first pass*/ + if (1==0){ /*original version that evaluate definitions also in first pass*/ + printf("fp: original: definition for c_token: %i\n", c_token); + define(); + printf("fp: original: done, c_token: %i\n", c_token); + if (!equals(c_token,",")) { + was_definition = TRUE; + continue; + } + } + else { /*modified version that skips definitions in first pass*/ + was_definition = TRUE; + printf("fp: modified: definition for c_token: %i\n", c_token); + while(!END_OF_COMMAND && !equals(c_token,",")){ + c_token++; + } + printf("fp: modified: done, c_token: %i\n", c_token); + if (END_OF_COMMAND){ + printf("fp: END_OF_COMMAND: %i\n", END_OF_COMMAND); + break; + } + } + } else { int specs = 0; @@ -2172,12 +2189,28 @@ if (!in_parametric && !was_definition) start_token = c_token; - if (is_definition(c_token)) { + if (is_definition(c_token)) { /*do definitions on second pass */ + if (1==0){ /*original version*/ + printf("sp: original: definition for c_token: %i\n", c_token); define(); + printf("sp: original: done, c_token: %i\n", c_token); if (!equals(c_token,",")) { was_definition = TRUE; continue; } + } + else { /*modified version does definitions and allows a trailing one*/ + printf("sp: modified: definition for c_token: %i\n", c_token); + define(); + was_definition = TRUE; + printf("sp: modified: done, c_token: %i\n", c_token); + if (END_OF_COMMAND){ + printf("sp: END_OF_COMMAND: %i\n", END_OF_COMMAND); + break; + } + } + + } else { struct at_type *at_ptr; |