Re: printing variable and variable name [message #67660] |
Tue, 18 August 2009 09:06 |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On Aug 18, 11:39 am, Daniel Bruynooghe
<daniel.bruynoo...@googlemail.com> wrote:
> Hi guys,
>
> I wanted to write a tiny procedure which prints a variable name and
> the value and a newline, the c equivalent would be a macro along the
> lines - #define PRINT_DOUBLE(x) printf(#x "= %f\n", x)
> but I don't know how to overcome pass - by - value.
>
> Ideal functionality:
>
> testVar = 1
> my_print, testVar
>
> testVar = 10
> IDL>
>
> Any suggestions?
>
> Many thanks,
>
> Daniel
This should work - even though it doesn't look
very pretty when it's called with a value instead
of a variable :)
PRO my_print,x
print,scope_varname(x,level=-1)+' = '+string(x)
END
IDL> q=2
IDL> my_print,q
Q = 2
Ciao,
Paolo
|
|
|