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

Home » Public Forums » archive » Evaluating a variable
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
Evaluating a variable [message #37726] Thu, 22 January 2004 09:18 Go to next message
Richard is currently offline  Richard
Messages: 6
Registered: June 1994
Junior Member
I want to evaluate a (string) variable to then perform an operation on
(another) variable whose name is the result of that evaluation.

Let me clarify...

I have a number of 1-D floating-point arrays. I want to take each array
in
turn and do stuff with it, something like this:

PRO blah

array1=[1,4,3,5.3,42,234,32,..(etc)]
array2=[1,6,4.65]
array3=[9.1,4,2.02,5,6]

arrays=['array1','array2','array3']
arrayno=-1

REPEAT BEGIN
arrayno=arrayno+1

; Pick which array I want to operate on, in order
; **************************************
thisarray=arrays(arrayno)
; **************************************

; Do stuff on the selected array
ROUTINE_DOSTUFF,thisarray

; Loop through all the arrays.
ENDREP UNTIL arrayno=2

END

Except, of course, that this doesn't work, because (in the highlighted
line) the variable 'thisarray' is set to be the string value 'array1'
(etc), instead of having the actual array1 copied into it.

If I try this instead...

arrays=[array1,array2,array3]

thisarray=arrays(start,stop)

...this works, except I have to fiddle around calculating start and stop
by finding the sizes of the array and all the preceding arrays, which
isn't very nice.

Ahah, I think, I'll put them into one big 2-D array so I /know/ where
each
one starts. But, alas, their lengths are very variable, so I'd end up
with a
huge array, much of which would be 0, which seems a bit wasteful).

The same problem comes if I set up pointers to a structure:

arraystruct={array1:PTR_NEW(array1),array2:PTR_NEW(array2).. .}

thisarray=arraystruct.arrayX ???

I'm having a brainfade here. What's the best way of doing this in IDL?
All I want to do is evaluate a string variable to read the value of the
variable that it evaluates to (say that three times quickly)

Thanks in advance,
Richard
Re: Evaluating a variable [message #37815 is a reply to message #37726] Fri, 23 January 2004 01:24 Go to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
> All I want to do is evaluate a string variable to read the value of the
> variable that it evaluates to (say that three times quickly) Thanks in
> advance,
> Richard

Hi,

I think what you want is what David suggests, but if you really want to
evaluate a string and use the variable named therein...

array1=[1,4,3,5.3,42,234,32,..(etc)]
array2=[1,6,4.65]
array3=[9.1,4,2.02,5,6]
arrays=['array1','array2','array3']
for i=0, 2 do begin
string="thisarray = ", arrays[i]
test=execute(string)
;you should check test for success and do something with it.
routine_dostuff, thisarray
endfor

Chris.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Limiting the number of VM instances
Next Topic: Re: Evaluating a variable

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

Current Time: Fri Oct 10 11:31:13 PDT 2025

Total time taken to generate the page: 0.95768 seconds