Re: convert string into the name of a variable [message #28377] |
Thu, 06 December 2001 08:41 |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
Frederic Raison wrote:
> Is there anybody who could tell me if there is an IDL instruction, like
> in Matlab, able to convert a string into the name of a variable and
> vice-versa?
Runtime variable name definition. The history repeats itself for sure.
I was told by RSI developers when I started in IDL that once you find
yourself wanting this, it means that your progamming needs serious
phylosophy readjustment.
One side effect is that any time you save and restore a runtime-named
variable you need to again find out what the name of it is. And it is
not the only flaw.
I came to IDL from IGOR Pro, where meaningful names are the cornerstone
of it all and programming holds together by explicit naming conventions.
But in IGOR it is so because you have all your variables at the global
(*main*) level. IDL allows a lot more flexible approach because it is a
*reuseable* development environment.
Cheers,
Pavel
|
|
|
|
Re: convert string into the name of a variable [message #28397 is a reply to message #28387] |
Wed, 05 December 2001 15:31  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
Frederic Raison <frederic_raison@hotmai.com> writes:
> Hi!
> Is there anybody who could tell me if there is an IDL instruction, like
> in Matlab, able to convert a string into the name of a variable and
> vice-versa? I mean if I have defined :
> a=1
> b=2
> list=['a','b']
> I would like to write:
> print,somme_instruction(list[0])
> and to get:
> 1
> Thank you
> Frederic
The easiest way I can think of to do this would be
test=execute('print,'+list[0])
William Thompson
|
|
|
Re: convert string into the name of a variable [message #28400 is a reply to message #28397] |
Wed, 05 December 2001 14:47  |
Paul van Delst
Messages: 364 Registered: March 1997
|
Senior Member |
|
|
Frederic Raison wrote:
>
> Hi!
>
> Is there anybody who could tell me if there is an IDL instruction, like
> in Matlab, able to convert a string into the name of a variable and
> vice-versa? I mean if I have defined :
>
> a=1
> b=2
> list=['a','b']
>
> I would like to write:
>
> print,somme_instruction(list[0])
>
> and to get:
>
> 1
>
> Thank you
>
> Frederic
this'll get yer started
IDL> a=149
IDL> b=273
IDL> list=['a','b']
IDL> result=execute('print,'+list[0])
149
IDL> result=execute('print,'+list[1])
273
if the execute works, result = 1.
--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
|
|
|