comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Is it possible to set a string to a veriable name?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Is it possible to set a string to a veriable name? [message #67939] Fri, 04 September 2009 07:15 Go to previous message
rtk is currently offline  rtk
Messages: 22
Registered: September 2008
Junior Member
On Sep 4, 5:36 am, "dux...@gmail.com" <dux...@gmail.com> wrote:
> I have an array of string and want to use its elements as veriable
> names in a function.
> How can I do?
>
> Is there any simple code to replace the ones below?
>
> For example:
> STR = ['a', 'b', 'c', 'd', 'e']
> for i=0, 4 do begin
> case i of
> 0: data=a
> 1: data=b
> 2: data=c
> 3: data=d
> 4: data=e
> endcase
> ..............
> ..............
> ..............
> endfor

Use scope_varfetch:

IDL> str = ['a','b','c','d']
IDL> for i=0,3 do (scope_varfetch(str[i],/ENTER,LEVEL=1)) = i
IDL> print, b
1
IDL> print, a
0
IDL> print, d
3

Setting LEVEL to 1 creates the new variables in the main level, not
specifying LEVEL or setting it to 0 will create them in the current
routine.

Ron
[Message index]
 
Read Message
Read Message
Previous Topic: IDL set_plot
Next Topic: Re: IDL set_plot

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Nov 29 12:55:29 PST 2025

Total time taken to generate the page: 0.48238 seconds