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

Home » Public Forums » archive » Merits of different ways of 'extending' arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Merits of different ways of 'extending' arrays [message #85805 is a reply to message #85798] Tue, 10 September 2013 13:08 Go to previous messageGo to previous message
suicidaleggroll is currently offline  suicidaleggroll
Messages: 14
Registered: September 2013
Junior Member
On Monday, September 9, 2013 4:41:10 PM UTC-6, suicida...@gmail.com wrote:
> Another option is to set up a pointer array nfiles long before the loop, inside the loop load the file and find the valid points, then put that array into that file's pointer, while incrementing a counter to keep track of the total number of points. When you're done, you have all of your data saved in pointers (one per file), and a count of the total number of valid points. Then you allocate your array, loop back through the elements of the pointer array, and fill the array as necessary. Something like:
>
>
>
> f = file_search(path, count=nfiles)
>
> ptrs = ptrarr(nfiles)
>
> num = 0l
>
> for i=0l,nfiles-1 do begin
>
> ;; load contents of file
>
> is_valid = where(stuff, n_valid)
>
> if n_valid gt 0 then begin
>
> num += n_valid
>
> ptrs[i] = ptr_new(f.var_1[is_valid])
>
> endif
>
> endfor
>
>
>
> data = fltarr(num)
>
> idx = 0l
>
> for i=0l,nfiles-1 do begin
>
> if ptr_valid(ptrs[i]) then begin
>
> num = n_elements(*ptrs[i])
>
> data[idx:idx+num-1] = *ptrs[i]
>
> ptr_free, ptrs[i]
>
> endif
>
> endfor

Wish I could edit my post...

There should be an "idx += num" next to the ptr_free at the end of the second loop.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL X11 forwarding segmentation fault
Next Topic: defining structure after ascii template

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

Current Time: Fri Oct 10 03:37:24 PDT 2025

Total time taken to generate the page: 0.89643 seconds