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

Home » Public Forums » archive » Re: resizing an array of structures (uugh)
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: resizing an array of structures (uugh) [message #25233 is a reply to message #25229] Mon, 04 June 2001 06:43 Go to previous messageGo to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Randall Skelton (rhskelto@atm.ox.ac.uk) writes:

> I have an ascii file containing a few thousand lines with each individual
> dataset comprising 10 lines of floats, ints, strings, etc. It seems
> logical to read this in as an array of structures as each dataset contains
> the same information, just different numbers.
>
> My problem is that I don't know what the dimension of the array should be
> before I start. Initially I just defined a large array and counted the
> number of datasets for subsequent processing. However, as time progresses
> and this code gets more use, I have to say that I really hate all the
> excess array elements... I figured there would be an easy way to resize
> the array of structures, but the best I can come up with is a double for
> loop that is rather slow.
>
> ; loop over the number of array elements
> for i, n_elements(array) do begin
> ; loop over the number of tags
> for j, n_tags(structure) do begin
> resized_array[i].(j) = array[i].(j)
> endfor
> endfor
>
> Is there a *faster* or more elegant way to do this? Does IDL have a
> *fast* resize command that can handle any type of array to simply adjust
> the number of elements in the array without rebinning, or otherwise
> changing the numbers?

I've read your article several times, and I still can't
convince myself I'm not missing something. (Is that
a double negative!?) But I don't see any reason you
can't treat an array of structures in the same way
you treat an array of anything. Since you are counting
the structures as you fill them into the array, don't
you just want this:

array = array[0:count-1]

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: using SPAWN to work with Windows NT network directories
Next Topic: trouble compiling AIM routines (mac files on windows?)

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

Current Time: Wed Oct 08 15:43:51 PDT 2025

Total time taken to generate the page: 0.00487 seconds