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