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

Home » Public Forums » archive » Instances of structure array with varying no. of elements
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
Instances of structure array with varying no. of elements [message #87364] Tue, 28 January 2014 07:47 Go to next message
midhunjoyp is currently offline  midhunjoyp
Messages: 5
Registered: January 2014
Junior Member
Hi all,

I have an array of structure arrays of the following simplified form :

results = REPLICATE({domain:REPLICATE({frame :fltarr(1), particles : fltarr(5,6000)}, 10)} , 500)

ie, 'domain' is initialized as a struct array with 10 elements(instances),
'results' is initialized as an array of 'domain' arrays with 500 instances

However during calculations, I would like to change the number of instances of 'domain' array in each instance of the 'results' array

eg: results[0] should contain only 5 instances of 'domain' array
results[1] should contain 7 instances of 'domain' array etc...

I tried doing the following for it :
results[0].domain = results[0].domain[0:4]

But, with:
print, n_elements(results[0].domain) : Returns value 10, which indicates that the size remains unchanged.

Is there any method for doing this operation ?


Best,
Midhun
Re: Instances of structure array with varying no. of elements [message #87366 is a reply to message #87364] Tue, 28 January 2014 08:10 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
> I tried doing the following for it :
>
> results[0].domain = results[0].domain[0:4]

Structures tags have fixed sizes and types. Since results[0].domain is part of a structure and starts as a 10-element array, it will always be a 10.

The best way to do this is to put your "domain" structures into a list. Lists are dynamic and can change sizes/types. They have a weird way of indexing, though. The following example shows you how to put your structure into a list, then change element 0 of the list to have only 5 instances of "domain".

IDL> temp_results = REPLICATE({domain:REPLICATE({frame :fltarr(1), particles : fltarr(5,6000)}, 10)} , 500)
IDL> results = list(temporary(temp_results), /extract)
IDL> iKeep = [0,1,2,3,4]
IDL> results[0] = results[0,iKeep]
IDL> help, results[0]
<Expression> STRUCT = -> <Anonymous> Array[5]

This is a bit slow, so if you can put your domains directly into the list instead of extracting them, you will be better off.
Re: Instances of structure array with varying no. of elements [message #87367 is a reply to message #87364] Tue, 28 January 2014 08:15 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
midhunjoyp@gmail.com writes:

> Is there any method for doing this operation ?

An "array" in IDL contains identical things in each element. You might
be looking for a "list", which often acts like an array, but which can
contain a different kind of thing in each element.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Instances of structure array with varying no. of elements [message #87370 is a reply to message #87364] Tue, 28 January 2014 08:53 Go to previous message
midhunjoyp is currently offline  midhunjoyp
Messages: 5
Registered: January 2014
Junior Member
On Tuesday, January 28, 2014 10:47:40 AM UTC-5, midhu...@gmail.com wrote:
> Hi all,
>
>
>
> I have an array of structure arrays of the following simplified form :
>
>
>
> results = REPLICATE({domain:REPLICATE({frame :fltarr(1), particles : fltarr(5,6000)}, 10)} , 500)
>
>
>
> ie, 'domain' is initialized as a struct array with 10 elements(instances),
>
> 'results' is initialized as an array of 'domain' arrays with 500 instances
>
>
>
> However during calculations, I would like to change the number of instances of 'domain' array in each instance of the 'results' array
>
>
>
> eg: results[0] should contain only 5 instances of 'domain' array
>
> results[1] should contain 7 instances of 'domain' array etc...
>
>
>
> I tried doing the following for it :
>
> results[0].domain = results[0].domain[0:4]
>
>
>
> But, with:
>
> print, n_elements(results[0].domain) : Returns value 10, which indicates that the size remains unchanged.
>
>
>
> Is there any method for doing this operation ?
>
>
>
>
>
> Best,
>
> Midhun

Hi Matthew & David,

I had completely forgotten the concept of lists.
Thanks a lot for the help.

Best,
Midhun
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Deleting specific instances of the structure
Next Topic: skip the corrupted hdf file and continue the for lood for uncorrupted hdfs

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

Current Time: Wed Oct 08 13:40:35 PDT 2025

Total time taken to generate the page: 0.00590 seconds