Re: resizing an array of structures (uugh) [message #25229 is a reply to message #25228] |
Mon, 04 June 2001 11:22   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Randall Skelton wrote:
>
> Hi all,
>
> 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?
>
> Cheers,
> Randall
Dear Randall,
IDL is an array orientated language. You should not use FOR statements
for the incrementation of array indices.
Here is a short summary of the syntax
array=sin(findgen(100))
array[*] all indices of array
array[10:*] index 10 to end of array
array[[0,2,4]] index 0 and 2 and 4 of array
array[0:counter-1] index 0 to counter-1 of array
array=[1,2]
array=[array,3,4] concatination of array
array=reform(array,[5,20]) reforms the vector to a 2-dim array
hope this helps a bit.
regards
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg1/
=============================================
a IDL library at ForschungsZentrum J�lich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
http://www.fz-juelich.de/zb/text/publikation/juel3786.html
|
|
|