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

Home » Public Forums » archive » Accessing numbered arrays
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
Accessing numbered arrays [message #93042] Thu, 14 April 2016 04:55 Go to next message
Richard Morton is currently offline  Richard Morton
Messages: 7
Registered: April 2016
Junior Member
Hi,

I have a routine (not mine) that creates numbered arrays as output, i.e., array1 , array2, array3, etc.

I would like to access these arrays sequentially within a for loop.

I am currently using:

FOR i=0,n DO temp=scope_varfetch('array'+strtrim(i,2)) .

This does the job but is this an appropriate way to do it? From my reading about scope_varfetch it appears to be designed for accessing variables at different levels of the code. This is not what I doing, so I wondered if there was another method.

If a similar question has been answered before I apologise, I couldn't find anything.

Cheers,
Richard
Re: Accessing numbered arrays [message #93043 is a reply to message #93042] Thu, 14 April 2016 05:56 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
Traditionally, one would use EXECUTE() for this.

There might be cases where using EXECUTE() would be faster because one doesn't necessarily need to make a copy of the array. For example, if all you need is the maximum of the array then

res = EXECUTE('amax = max(temporary(array' + strtrim(i,2) + '))' )

gets the maximum, and deletes the array without ever having to make a duplicate copy.

But I think for most cases SCOPE_VARFETCH would work just as well. (Also note that EXECUTE() can't be used with the virtual machine, but SCOPE_VARFETCH can).

On Thursday, April 14, 2016 at 7:55:57 AM UTC-4, Richard Morton wrote:
> Hi,
>
> I have a routine (not mine) that creates numbered arrays as output, i.e., array1 , array2, array3, etc.
>
> I would like to access these arrays sequentially within a for loop.
>
> I am currently using:
>
> FOR i=0,n DO temp=scope_varfetch('array'+strtrim(i,2)) .
>
> This does the job but is this an appropriate way to do it? From my reading about scope_varfetch it appears to be designed for accessing variables at different levels of the code. This is not what I doing, so I wondered if there was another method.
>
> If a similar question has been answered before I apologise, I couldn't find anything.
>
> Cheers,
> Richard
Re: Accessing numbered arrays [message #93044 is a reply to message #93042] Thu, 14 April 2016 06:01 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
Sounds a reasonable solution to me. The appropriate way would have been for the author of the routine not to produce output like that.

cheers,
Greg
Re: Accessing numbered arrays [message #93045 is a reply to message #93043] Fri, 15 April 2016 00:46 Go to previous messageGo to next message
Richard Morton is currently offline  Richard Morton
Messages: 7
Registered: April 2016
Junior Member
Great, thanks for the advice. In this case I need the entire array but will bear EXECUTE in mind for other tasks.
Re: Accessing numbered arrays [message #93048 is a reply to message #93045] Fri, 15 April 2016 08:11 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Friday, April 15, 2016 at 3:46:40 AM UTC-4, Richard Morton wrote:
> Great, thanks for the advice. In this case I need the entire array but will bear EXECUTE in mind for other tasks.

Just a quick note that you can get the entire array with EXECUTE(). Instead of

FOR i=0,n DO temp=scope_varfetch('array'+strtrim(i,2))

you would write

FOR i=0,n DO res=execute('temp = array'+strtrim(i,2))
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 3d Interpolation
Next Topic: Walter and Lieth climate digram

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

Current Time: Wed Oct 08 15:33:00 PDT 2025

Total time taken to generate the page: 0.00686 seconds