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

Home » Public Forums » archive » Re: allocating data to different array on each loop step
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
Re: allocating data to different array on each loop step [message #46251] Mon, 14 November 2005 00:49
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
snfinder@naver.com wrote:
> Thank you Coyote~ ^^
>
> But If the number of loop step is so large,
> array1 = *arrays[0]
> array2 = *arrays[1]
> ...
> array24 = *arrays[23]
> this is very unefficient.
Do you really want to have 24 differently named arrays?
You don't need named arrays to access the data stored
in your pointers to arrays, it's enough to write
something like

(*arrays[k])[i]

Ciao,
Paolo

>
> I want to excute this automatically.
>
> And I can't know the number of loop step before end of all steps.
> um...ok can find out it if I excute loop twice......ok..
>
> Thank you ~
>
Re: allocating data to different array on each loop step [message #46257 is a reply to message #46251] Sun, 13 November 2005 20:52 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Richard G. French writes:


> Well, you can use the EXECUTE command if you want to define the variables on
> the fly:
>
>
>
> pro arrays
> for n=1L,10 do begin
> ;create arrays of different sizes
> array=findgen(n)#findgen(10*n)
> ; construct a command to execute, defining the new variable name
> cmd=string(n,format='("array",I0,"=array")')
> print,cmd
> result=execute(cmd)
> endfor
> help
> end
>
>
> IDL> arrays
> array1=array
> array2=array
> array3=array
> array4=array
> array5=array
> array6=array
> array7=array
> array8=array
> array9=array
> array10=array
> % At ARRAYS 8 /Users/rfrench/arrays.pro
> % $MAIN$
> ARRAY FLOAT = Array[10, 100]
> ARRAY1 FLOAT = Array[1, 10]
> ARRAY10 FLOAT = Array[10, 100]
> ARRAY2 FLOAT = Array[2, 20]
> ARRAY3 FLOAT = Array[3, 30]
> ARRAY4 FLOAT = Array[4, 40]
> ARRAY5 FLOAT = Array[5, 50]
> ARRAY6 FLOAT = Array[6, 60]
> ARRAY7 FLOAT = Array[7, 70]
> ARRAY8 FLOAT = Array[8, 80]
> ARRAY9 FLOAT = Array[9, 90]
> CMD STRING = 'array10=array'
> N LONG = 11
> RESULT INT = 1

Humm. I thought he was looking for "efficient". Oh, well,
I guess the old garage sale adage holds for science
concepts, too: What's junk to me, is a treasure for you! :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: allocating data to different array on each loop step [message #46259 is a reply to message #46257] Sun, 13 November 2005 19:31 Go to previous message
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
On 11/13/05 10:25 PM, in article
1131938752.543314.79260@g47g2000cwa.googlegroups.com, "snfinder@naver.com"
<snfinder@naver.com> wrote:

> A thousand thanks~~ !!
> Thank you Thank you very much ^^! Richard G. French~
>
> Ha Ha Ha~~
> It makes me really happy~~~
> It will make my life very well~~ 占쏙옙占쏙옙占쏙옙
>

Well, that is a cheerful message to get just before the start of a long
week! Thanks to you!
DF
Re: allocating data to different array on each loop step [message #46260 is a reply to message #46259] Sun, 13 November 2005 19:25 Go to previous message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
A thousand thanks~~ !!
Thank you Thank you very much ^^! Richard G. French~

Ha Ha Ha~~
It makes me really happy~~~
It will make my life very well~~ ㅋㅋㅋ
Re: allocating data to different array on each loop step [message #46261 is a reply to message #46260] Sun, 13 November 2005 18:02 Go to previous message
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
On 11/13/05 8:50 PM, in article
1131933033.894813.142800@z14g2000cwz.googlegroups.com, "snfinder@naver.com"
<snfinder@naver.com> wrote:

> Thank you Coyote~ ^^
>
> But If the number of loop step is so large,
> array1 = *arrays[0]
> array2 = *arrays[1]
> ...
> array24 = *arrays[23]
> this is very unefficient.
>
> I want to excute this automatically.
>
> And I can't know the number of loop step before end of all steps.
> um...ok can find out it if I excute loop twice......ok..
>
> Thank you ~
>

Well, you can use the EXECUTE command if you want to define the variables on
the fly:



pro arrays
for n=1L,10 do begin
;create arrays of different sizes
array=findgen(n)#findgen(10*n)
; construct a command to execute, defining the new variable name
cmd=string(n,format='("array",I0,"=array")')
print,cmd
result=execute(cmd)
endfor
help
end


IDL> arrays
array1=array
array2=array
array3=array
array4=array
array5=array
array6=array
array7=array
array8=array
array9=array
array10=array
% At ARRAYS 8 /Users/rfrench/arrays.pro
% $MAIN$
ARRAY FLOAT = Array[10, 100]
ARRAY1 FLOAT = Array[1, 10]
ARRAY10 FLOAT = Array[10, 100]
ARRAY2 FLOAT = Array[2, 20]
ARRAY3 FLOAT = Array[3, 30]
ARRAY4 FLOAT = Array[4, 40]
ARRAY5 FLOAT = Array[5, 50]
ARRAY6 FLOAT = Array[6, 60]
ARRAY7 FLOAT = Array[7, 70]
ARRAY8 FLOAT = Array[8, 80]
ARRAY9 FLOAT = Array[9, 90]
CMD STRING = 'array10=array'
N LONG = 11
RESULT INT = 1


Dick French
Re: allocating data to different array on each loop step [message #46262 is a reply to message #46261] Sun, 13 November 2005 17:50 Go to previous message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
Thank you Coyote~ ^^

But If the number of loop step is so large,
array1 = *arrays[0]
array2 = *arrays[1]
...
array24 = *arrays[23]
this is very unefficient.

I want to excute this automatically.

And I can't know the number of loop step before end of all steps.
um...ok can find out it if I excute loop twice......ok..

Thank you ~
Re: allocating data to different array on each loop step [message #46267 is a reply to message #46262] Sat, 12 November 2005 08:25 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
snfinder@naver.com writes:

> Tha data in loop is also array not a single value
> Therefore I will have several arrays after loop operation.

I would do something like this:

arrays = PtrArr(24)
FOR j=0,23 DO BEGIN
...calculation to obtain array of whatever size
arrays[j] = Ptr_New(thisLoopArray, /No_Copy)
ENDFOR

Now you have a pointer array. Each element in the array
is a pointer to another array of variable length.

array1 = *arrays[0]
array2 = *arrays[1]
...
array24 = *arrays[23]

Be sure to free your pointers when you are done with them:

Ptr_Free, arrays

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: allocating data to different array on each loop step [message #46269 is a reply to message #46267] Sat, 12 November 2005 04:10 Go to previous message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
Thank you for replying

But I can't understand what you wrote.
Tha data in loop is also array not a single value
Therefore I will have several arrays after loop operation.

What I exactly want is to save the array(data computed in each step) to
different array ecah loop step.

loop 1
array1=data computed

loop 2
array2=data computed
.
.
.
.

loop 24(end of loop forexample)
array24=data computed



So, finally I have 24 different arrays allocated different data.

Thank you
Can you explain more details again?
Re: allocating data to different array on each loop step [message #46270 is a reply to message #46269] Sat, 12 November 2005 03:08 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
snfinder@naver.com wrote:


> Dear all,
>
> I just want to allocate data(computed in each loop step) to different
> array in each step.
>

if n_elements(arr) eq 0 then arr=value else arr=[arr,value]


later on you probably have to do somewhere result=temporary(arr)

cheers
Reimar

> for example,
> while ...
>
> ..
> ..
> data=...
>
> a0=data
> .
> .
> endwhile
>
>
> in other words
> loop step 1: a1=data
> loop step 2: a2=data
> loop step 3: a3=data
> .
> .
> .
> end of loop
>
>
> I need new array on each step but I can not know the size of array(data
> computed) in advace.
> It would be differnt on each step.
>
>
> To sum up,
> I need the generation of array(different name ex) a0,a1,a2....on each
> loop step.
>
>
> Thank you.
>
> Help me~ You can give a bright to a blind(IDL blind like me ^^;;).
> SOS~~
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Access to title object in IDLgrAxis
Next Topic: subscripting arrays with dim > 1

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

Current Time: Wed Oct 08 11:43:41 PDT 2025

Total time taken to generate the page: 0.00567 seconds