|
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; |
|
From: Teo S B. <teo...@gm...> - 2010-02-13 15:48:23
|
Some test cases:
#testcase: try01
set grid
set key left
set samples 10
set title "try01: parameter definition both in front and trailing"
plot [0:1] [-1:10] k=0, \
k*x t '0x' w lp lt 3, k=k+1, \
k*x t '1x' w lp lt 4, k=k+1, \
k*x t '2x' w lp lt 5, k=k+1
pause -1 "Continue?"
print "k=3?", " k=", k
#testcase: try02
set grid
set key left
set samples 10
set title "try02: parameter definiton, notice recalculation on zoom/replot"
k=0
plot [0:1] [-1:10] \
k*x t '0x' w lp lt 3, k=k+1, \
k*x t '1x' w lp lt 4, k=k+1, \
k*x t '2x' w lp lt 5, k=k+1
pause -1 "Continue?"
print "k=", k
#testcase: try03
set grid
set title "try03: parameter and function definitions, notice enhanced labels"
plot [-10:10] [-200:200] k=10, k*x , \
a=10,b=2,f(x)=a*b*x, f(x)
pause -1 "Continue?"
print "k=", k, " a=", a, " b=",b
#testcase: try04
set grid
set title "try04: mix of parameter definiton and iteration"
plot [-10:10] [-30:30] a=3, a*x, for [k=1:2] k*x
pause -1 "Continue?"
print "a=", a
exit
#testcase: try05 (causes unresponsive gnuplot)
set grid
set title "try05: infinite loop?"
plot [-10:10] [-30:30] a=3, a*x, a=7, for [k=1:2] k*x
pause -1 "Continue?"
print "a=", a
|
|
From: Ethan M. <merritt@u.washington.edu> - 2010-02-13 19:08:11
|
On Saturday 13 February 2010, Teo S Bernhard wrote: > 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. The first pass is used for plotting data, the second pass is used for evaluating functions. If you disable definitions in the first pass, you break plotting from a file. Consider plot col=2, 'data' using 1:col with lines If you want to pursue this, you will need to use test cases that mix both function plots and data plots. Ethan > > 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; > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > gnuplot-beta mailing list > gnu...@li... > https://lists.sourceforge.net/lists/listinfo/gnuplot-beta > |
|
From: Teo S B. <teo...@gm...> - 2010-02-13 22:46:51
|
On Sat, Feb 13, 2010 at 8:06 PM, Ethan Merritt <merritt@u.washington.edu> wrote: > On Saturday 13 February 2010, Teo S Bernhard wrote: >> 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: >> 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. >> 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. > > The first pass is used for plotting data, > the second pass is used for evaluating functions. > If you disable definitions in the first pass, > you break plotting from a file. Consider > > plot col=2, 'data' using 1:col with lines > > If you want to pursue this, you will need to use test cases > that mix both function plots and data plots. > I see , thanks for pointing this out. Out of curiosity - is there any way that an approach as the following could succeed? a) at start of first pass, copy the the original "namespace(s)" into temporary one(s) b) use the temporary "namespace(s)" during the first pass c) change back to the original "namespace(s)" in the second pass By "namespace" I mean the structures that hold the variables and functions that are changed when parsing the plot command, Particularily, or perhaps only, those changed by the call to define(). Since these structures are not an argument to define(), am I right in assuming that these are global structures - of unknown name(s) to me, but structures defined in eval.h and eval.c? Thanks for your help. |
|
From: sfeam (E. Merritt) <eam...@gm...> - 2010-02-14 02:10:06
|
On Saturday 13 February 2010, Teo S Bernhard wrote: > On Sat, Feb 13, 2010 at 8:06 PM, Ethan Merritt <merritt@u.washington.edu> wrote: > > On Saturday 13 February 2010, Teo S Bernhard wrote: > >> 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: > > >> 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. > > >> 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. > > > > The first pass is used for plotting data, > > the second pass is used for evaluating functions. > > If you disable definitions in the first pass, > > you break plotting from a file. Consider > > > > plot col=2, 'data' using 1:col with lines > > > > If you want to pursue this, you will need to use test cases > > that mix both function plots and data plots. > > > > I see , thanks for pointing this out. > > Out of curiosity - is there any way that an approach as the following > could succeed? > a) at start of first pass, copy the the original "namespace(s)" into > temporary one(s) > b) use the temporary "namespace(s)" during the first pass > c) change back to the original "namespace(s)" in the second pass It could work, yes. The iteration code already does this for the iteration variables. Is there some reason you cannot use the iteration syntax rather than using a self-modifying definition? I can think of obscure scenarios that would break your save/restore procedure. For example, it is possible although convoluted to modify a variable based on data read during the first pass. You would lose the new value after the restore operation. I don't claim this is a common thing to do, but we may have to make a decision whether the gain from re-working the mechanism of handling definitions inside a plot statement is worth the loss of admittedly rare options for loading program variables from a data file. > Since these structures are not an argument to define(), am I right in > assuming that these are global structures - of unknown name(s) to me, > but structures defined in eval.h and eval.c? User-defined variables are kept in a linked list of structures. The structure type is udvt_entry. The head of the list is (struct udvt_entry *)first_udv. These are defined in eval.h. |