Re: Create new arrays from series of subsequent integers in an existing array [message #48813 is a reply to message #48812] |
Tue, 23 May 2006 15:26   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Jonathan Wolfe wrote:
> Thank you both for your help! In regards to JD's saving the output
> arrays with pointers... I have never used pointers and believe this is
> a case in which they are necessary.
>
> After writing a long, drawn out explanation of where I was stuck with
> pointers I ended up figuring them out. Just in case anyone new to
> pointers wants to know how to get variables from an example such as the
> above threads, use something like this:
>
> x= ptrarr(3)
>
> for i = 1L, n_elements(h) - 1L do begin
> t=ri[ri[i]:ri[i+1]-1]
> x[i] = PTR_NEW( t,/allocate_heap )
> endfor
>
> print,*x(2)
>
> and you will have your varying size arrays of a larger array segmented
> into different subscripts of x.
>
> I'm sure there may be a better way to do this, but it makes sense to me.
Not a big change, but you can also do:
n=n_elements(h)
x=ptrarr(n,/ALLOCATE_HEAP)
for i = 0L, n-1L do begin
t=ri[ri[i]:ri[i+1]-1]
*x[i] = t
endfor
BTW, do you really want
for i = 1L, n_elements(h) - 1L
or
for i = 0L, n_elements(h) - 1L
??
You never use x[0] in your orig code.
paulv
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|