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

Home » Public Forums » archive » Converting a string to variable name
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Converting a string to variable name [message #86329] Mon, 28 October 2013 03:17 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have written the following lines in IDL:

--------------------------------------------------------
week01 = ['2013_04_09', '2013_04_10', '2013_04_11']
w_no=indgen(15)+1
Nw=0
week_no=STRCOMPRESS('week0'+STRING(w_no[Nw]),/REMOVE_ALL)
---------------------------------------------------------

IDL> print,week_no
week01
IDL> help,week_no
WEEK_NO STRING = 'week01'
IDL> print,week01
2013_04_09 2013_04_10 2013_04_11
IDL> help,week01
WEEK01 STRING = Array[3]

I want to call 'week01' array defined above by 'week_no'. Can anyone help me to obtain week_no=week01=[['2013_04_09', '2013_04_10', '2013_04_11']?

Thanks in advance
Re: Converting a string to variable name [message #86330 is a reply to message #86329] Mon, 28 October 2013 03:30 Go to previous messageGo to next message
Moritz Fischer is currently offline  Moritz Fischer
Messages: 32
Registered: June 2013
Member
Take a look at 'scope_varfetch'!

m

Am 28.10.2013 11:17, schrieb Madhavan Bomidi:
> Hello,
>
> I have written the following lines in IDL:
>
> -------------------------------------------------------- week01 =
> ['2013_04_09', '2013_04_10', '2013_04_11'] w_no=indgen(15)+1 Nw=0
> week_no=STRCOMPRESS('week0'+STRING(w_no[Nw]),/REMOVE_ALL)
> ---------------------------------------------------------
>
> IDL> print,week_no week01 IDL> help,week_no WEEK_NO STRING
> = 'week01' IDL> print,week01 2013_04_09 2013_04_10 2013_04_11 IDL>
> help,week01 WEEK01 STRING = Array[3]
>
> I want to call 'week01' array defined above by 'week_no'. Can anyone
> help me to obtain week_no=week01=[['2013_04_09', '2013_04_10',
> '2013_04_11']?
>
> Thanks in advance
>
>
Re: Converting a string to variable name [message #86331 is a reply to message #86329] Mon, 28 October 2013 03:37 Go to previous messageGo to next message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
print,scope_varfetch(week_no)

Cheers, Heinz
Re: Converting a string to variable name [message #86332 is a reply to message #86331] Mon, 28 October 2013 03:39 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Thank you Moritz and Heinz. It works!!!
Re: Converting a string to variable name [message #86385 is a reply to message #86332] Sun, 03 November 2013 12:13 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Monday, October 28, 2013 6:39:09 AM UTC-4, Madhavan Bomidi wrote:
> Thank you Moritz and Heinz. [SCOPE_VARFETCH] works!!!

This is like cutting off your finger in order to fit your hand in a mitten. It will probably work now, but you will be in pain later.

Use proper parameters and/or keyword arguments to transfer data from one calling level to another.

Craig
Re: Converting a string to variable name [message #86386 is a reply to message #86385] Sun, 03 November 2013 12:17 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt writes:

> This is like cutting off your finger in order to fit your hand in a mitten. It will probably work now, but you will be in pain later.

I've been scratching my head for *weeks* for the perfect metaphor to
describe this situation, and here it is! ;-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Converting a string to variable name [message #86395 is a reply to message #86329] Mon, 04 November 2013 11:26 Go to previous message
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
I agree with David and Craig. There have been a very few number of cases where I genuinely needed to do something like this, and I've been an avid IDL fan for 10 years. I highly doubt you need to do this, and I strongly recommend you against it.

If you must, and you don't like scope_varfetch. Also look at execute, but scope_varfetch is WAY better...

Russell
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: mpfitevalexpr not compiled
Next Topic: so long, and thanks for all the fish

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

Current Time: Wed Oct 08 13:47:32 PDT 2025

Total time taken to generate the page: 0.00659 seconds