|
From: Arun P. <ape...@lb...> - 2011-04-01 01:33:04
|
Hi
not sure if this is a bug or not...
the following works:
gnuplot> set macros
gnuplot> A="a=1"
gnuplot> a=1.0
gnuplot> A=sprintf("a=%f",2)
gnuplot> @A
gnuplot> print a
2.0
but this doesn't:
gnuplot> set macros
gnuplot> A="a=1.111";a=1;A=sprintf("a=%f",2); @A;print a
warning: A is not a string variable
1
I also ran into something similar, here is a short version of it:
set macros
A="2.0"
f(t) = (\
A= sprintf("a=2.0"),\
@A,\
"some text")
print f(1)
that didn't set a to 2.0...
An here a longer: What I wanted to do is having a function that saves
results from a fit to some variables, so that I can reuse them later
after doing more fits... I thought I could use:
CP_FIT(A,A_err,mu,mu_err,sig,sig_err,offset,offset_err,file,type) = ( \
MA = sprintf("%s_%s_A = %f",file,type,A),\
MAe = sprintf("%s_%s_A_err = %f",file,type,A_err),\
Mmu = sprintf("%s_%s_mu = %f",file,type,mu),\
Mmue = sprintf("%s_%s_mu_err = %f",file,type,mu_err),\
Msig = sprintf("%s_%s_sig = %f",file,type,sig),\
Msige = sprintf("%s_%s_sig_err = %f",file,type,sig_err),\
Moff = sprintf("%s_%s_off = %f",file,type,offset),\
Moffe = sprintf("%s_%s_off_err = %f",file,type,offset_err),\
@MA, @Mmu, @Msig, @MAe, @Mmue, @Msige,@Moff,@Moffe,\
sprintf("copying variables for %s %s",file,type))
but the macros never got called ?! It works though, if I take the line
including all the @M... out and call it by hand after I call CP_FIT.
Tested this with 4.4, 4.5 and the latest CVS (Changelog version 1.3682).
Here is the version output from the CVS build:
gnuplot> show version long
G N U P L O T
Version 4.5 patchlevel 0
last modified March 2011
System: Linux 2.6.38-18-desktop
Copyright (C) 1986-1993, 1998, 2004, 2007-2010
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
mailing list: gnu...@li...
faq, bugs, etc: type "help seeking-assistance"
immediate help: type "help"
plot window: hit 'h'
Compile options:
-READLINE +LIBREADLINE +HISTORY
-BACKWARDS_COMPATIBILITY +BINARY_DATA
+GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION
-NOCWDRC +X11 +X11_POLYGON +MULTIBYTE +X11_EXTERNAL +USE_MOUSE
+HIDDEN3D_QUADTREE
+DATASTRINGS +HISTOGRAMS +OBJECTS +STRINGVARS +MACROS +IMAGE
+USER_LINETYPES
GNUPLOT_DRIVER_DIR = "/usr/local/libexec/gnuplot/4.5"
GNUPLOT_PS_DIR = "/usr/local/share/gnuplot/4.5/PostScript"
HELPFILE = "/usr/local/share/gnuplot/4.5/gnuplot.gih"
cheers
ARUN
|
|
From: Daniel J S. <dan...@ie...> - 2011-04-01 02:10:24
|
On 03/31/2011 08:32 PM, Arun Persaud wrote:
> Hi
>
> not sure if this is a bug or not...
>
> the following works:
>
> gnuplot> set macros
> gnuplot> A="a=1"
> gnuplot> a=1.0
> gnuplot> A=sprintf("a=%f",2)
> gnuplot> @A
> gnuplot> print a
> 2.0
>
> but this doesn't:
>
> gnuplot> set macros
> gnuplot> A="a=1.111";a=1;A=sprintf("a=%f",2); @A;print a
> warning: A is not a string variable
That does seem inconsistent.
Did you try the "table" feature for saving results to a file? Look at
the third example of "random.dem" demo to see how a data file of random
numbers is created then used in a plot.
Dan
|
|
From: Arun P. <ape...@lb...> - 2011-04-01 02:34:03
|
Hi On 03/31/2011 07:09 PM, Daniel J Sebald wrote: > On 03/31/2011 08:32 PM, Arun Persaud wrote: >> [...] > That does seem inconsistent. > > Did you try the "table" feature for saving results to a file? Look at > the third example of "random.dem" demo to see how a data file of random > numbers is created then used in a plot. no. I haven't. Guess that could be a nice workaround for saving my fit data for later plotting. However I would lose the parameters themselves and wouldn't be able to include them for e.g. labels. For the moment, I just "unrolled" the function containing the macros and that worked... of course now I have to do edits in many places and not just one ;) Arun |
|
From: sfeam (E. Merritt) <eam...@gm...> - 2011-04-01 02:50:20
|
On Thursday, March 31, 2011, Arun Persaud wrote:
> Hi
>
> not sure if this is a bug or not...
>
> the following works:
>
> gnuplot> set macros
> gnuplot> A="a=1"
> gnuplot> a=1.0
> gnuplot> A=sprintf("a=%f",2)
> gnuplot> @A
> gnuplot> print a
> 2.0
>
> but this doesn't:
>
> gnuplot> set macros
> gnuplot> A="a=1.111";a=1;A=sprintf("a=%f",2); @A;print a
> warning: A is not a string variable
The macro mechanism was a first attempt at string handling.
It didn't really work out all that well.
Proper string handling replaced it for most purposes, and perhaps
the macro stuff should have been removed, but we're such sticklers
for backwards compatibility that it's still there.
Anyhow...
The problem you're seeing is inherent in the way that the macros work.
They are applied line-by-line to the input stream, as the very first
thing before the line is actually interpreted or executed.
But that means if you define a new macro on a particular line,
that line has already been through the macro substitution process
and substitutions involving the new macro cannot take effect until
the next line.
Ethan
> 1
>
>
> I also ran into something similar, here is a short version of it:
>
> set macros
> A="2.0"
> f(t) = (\
> A= sprintf("a=2.0"),\
> @A,\
> "some text")
>
> print f(1)
>
> that didn't set a to 2.0...
>
> An here a longer: What I wanted to do is having a function that saves
> results from a fit to some variables, so that I can reuse them later
> after doing more fits... I thought I could use:
>
> CP_FIT(A,A_err,mu,mu_err,sig,sig_err,offset,offset_err,file,type) = ( \
> MA = sprintf("%s_%s_A = %f",file,type,A),\
> MAe = sprintf("%s_%s_A_err = %f",file,type,A_err),\
> Mmu = sprintf("%s_%s_mu = %f",file,type,mu),\
> Mmue = sprintf("%s_%s_mu_err = %f",file,type,mu_err),\
> Msig = sprintf("%s_%s_sig = %f",file,type,sig),\
> Msige = sprintf("%s_%s_sig_err = %f",file,type,sig_err),\
> Moff = sprintf("%s_%s_off = %f",file,type,offset),\
> Moffe = sprintf("%s_%s_off_err = %f",file,type,offset_err),\
> @MA, @Mmu, @Msig, @MAe, @Mmue, @Msige,@Moff,@Moffe,\
> sprintf("copying variables for %s %s",file,type))
>
> but the macros never got called ?! It works though, if I take the line
> including all the @M... out and call it by hand after I call CP_FIT.
>
> Tested this with 4.4, 4.5 and the latest CVS (Changelog version 1.3682).
> Here is the version output from the CVS build:
> gnuplot> show version long
>
> G N U P L O T
> Version 4.5 patchlevel 0
> last modified March 2011
> System: Linux 2.6.38-18-desktop
>
> Copyright (C) 1986-1993, 1998, 2004, 2007-2010
> Thomas Williams, Colin Kelley and many others
>
> gnuplot home: http://www.gnuplot.info
> mailing list: gnu...@li...
> faq, bugs, etc: type "help seeking-assistance"
> immediate help: type "help"
> plot window: hit 'h'
> Compile options:
> -READLINE +LIBREADLINE +HISTORY
> -BACKWARDS_COMPATIBILITY +BINARY_DATA
> +GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION
> -NOCWDRC +X11 +X11_POLYGON +MULTIBYTE +X11_EXTERNAL +USE_MOUSE
> +HIDDEN3D_QUADTREE
> +DATASTRINGS +HISTOGRAMS +OBJECTS +STRINGVARS +MACROS +IMAGE
> +USER_LINETYPES
>
> GNUPLOT_DRIVER_DIR = "/usr/local/libexec/gnuplot/4.5"
> GNUPLOT_PS_DIR = "/usr/local/share/gnuplot/4.5/PostScript"
> HELPFILE = "/usr/local/share/gnuplot/4.5/gnuplot.gih"
>
> cheers
>
> ARUN
>
> ------------------------------------------------------------------------------
> Create and publish websites with WebMatrix
> Use the most popular FREE web apps or write code yourself;
> WebMatrix provides all the features you need to develop and
> publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
> _______________________________________________
> gnuplot-beta mailing list
> gnu...@li...
> https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
>
|
|
From: Arun P. <ape...@lb...> - 2011-04-01 04:09:25
|
Hi
On 03/31/2011 07:50 PM, sfeam (Ethan Merritt) wrote:
>[...]
> The macro mechanism was a first attempt at string handling.
> It didn't really work out all that well.
> Proper string handling replaced it for most purposes,
is there a way then that I can do things like
set macros
f(s)=sprintf("m=%s_m",s)
g(x)=m*x
t1_m = 1.0
t2_m = 2.0
A=f("t1")
B=f("t2")
plot @A,g(x),@B,g(x)
without using macros?
> and perhaps
> the macro stuff should have been removed, but we're such sticklers
> for backwards compatibility that it's still there.
>
> Anyhow...
> The problem you're seeing is inherent in the way that the macros work.
> They are applied line-by-line to the input stream, as the very first
> thing before the line is actually interpreted or executed.
> But that means if you define a new macro on a particular line,
> that line has already been through the macro substitution process
> and substitutions involving the new macro cannot take effect until
> the next line.
Thanks for the explanation, makes sense...
Here is some addition for the manual (output of cvs diff -u)
-----------------start-------------------------------
RCS file: /cvsroot/gnuplot/gnuplot/docs/gnuplot.doc,v
retrieving revision 1.658
diff -u -r1.658 gnuplot.doc
--- gnuplot.doc 26 Mar 2011 02:39:44 -0000 1.658
+++ gnuplot.doc 1 Apr 2011 04:07:32 -0000
@@ -2584,6 +2584,18 @@
Macro expansion does not occur inside either single or double quotes.
However macro expansion does occur inside backquotes.
+ Macro expansion is also handled as the very first thing the
+ interpreter does when looking at a new line of commands and is only
+ done once. Therefore, code like the following will execute correctly:
+
+ A = "c=1"
+ @A
+
+ but this line will not, since the macro is defined on the same line
+ and can't be expanded in time
+
+ A = "c=1"; @A # will not expand to c=1
+
For execution of complete commands the `evaluate` command may also be
handy.
3 String variables, macros, and command line substitution
?mixing_macros_backquotes
-------------------end----------------------
Thanks for the quick help
Arun
|
|
From: sfeam (E. Merritt) <eam...@gm...> - 2011-04-01 05:05:00
|
On Thursday, March 31, 2011, Arun Persaud wrote:
>
> is there a way then that I can do things like
>
> set macros
> f(s)=sprintf("m=%s_m",s)
> g(x)=m*x
>
> t1_m = 1.0
> t2_m = 2.0
>
> A=f("t1")
> B=f("t2")
>
> plot @A,g(x),@B,g(x)
>
> without using macros?
I'm not clear on the significance of using A and B
as opposed to directly calling f(). Is the variant
below useful?
f(var) = value(var . "_m")
g(x) = m*x
plot m=f("t1"),g(x), m=f("t2"),g(x)
> Here is some addition for the manual (output of cvs diff -u)
Thanks.
> -----------------start-------------------------------
>
> RCS file: /cvsroot/gnuplot/gnuplot/docs/gnuplot.doc,v
> retrieving revision 1.658
> diff -u -r1.658 gnuplot.doc
> --- gnuplot.doc 26 Mar 2011 02:39:44 -0000 1.658
> +++ gnuplot.doc 1 Apr 2011 04:07:32 -0000
> @@ -2584,6 +2584,18 @@
> Macro expansion does not occur inside either single or double quotes.
> However macro expansion does occur inside backquotes.
>
> + Macro expansion is also handled as the very first thing the
> + interpreter does when looking at a new line of commands and is only
> + done once. Therefore, code like the following will execute correctly:
> +
> + A = "c=1"
> + @A
> +
> + but this line will not, since the macro is defined on the same line
> + and can't be expanded in time
> +
> + A = "c=1"; @A # will not expand to c=1
> +
> For execution of complete commands the `evaluate` command may also be
> handy.
> 3 String variables, macros, and command line substitution
> ?mixing_macros_backquotes
>
> -------------------end----------------------
>
> Thanks for the quick help
>
> Arun
>
>
|
|
From: Arun P. <ape...@lb...> - 2011-04-01 07:01:41
|
Hi
On 03/31/2011 10:04 PM, sfeam (Ethan Merritt) wrote:
> On Thursday, March 31, 2011, Arun Persaud wrote:
>> [...]
>> A=f("t1")
>> B=f("t2")
>>
>> plot @A,g(x),@B,g(x)
>>
>> without using macros?
>
> I'm not clear on the significance of using A and B
> as opposed to directly calling f().
hmm, f() is just a string that needs to be evaluated and eval f(...)
didn't work inside the plot commando, so I used the macro...
> Is the variant
> below useful?
>
> f(var) = value(var . "_m")
> g(x) = m*x
>
> plot m=f("t1"),g(x), m=f("t2"),g(x)
yes very useful :) I wasn't aware of the value-function, that's exactly
what I tried to accomplish with the macros.
Again: thanks for the fast response!
Arun
|