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

Home » Public Forums » archive » Maddening structures
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
Maddening structures [message #50226] Mon, 18 September 2006 04:47 Go to next message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
OK, I've got some data read in so that I have a structure that looks
like

data.foo[600]
.bar[600]
.baz[600]

and I want
data[600].foo
.bar
.baz

In other words I want an array of structures rather than a structure
of arrays.

Does anyone have any magic that works for the case when foo, bar and
baz are not previously known?

--
Edd
Re: Maddening structures [message #50274 is a reply to message #50226] Wed, 20 September 2006 02:55 Go to previous message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
JD Smith <jdsmith@as.arizona.edu> wrote:
> st=create_struct(fields[0],*vals[0])
> for i=1,nfields-1 do $
> st=create_struct(st,fields[i],*vals[i])
> st=replicate(st,ndata)

That loop is particularly cunning. Thank you!
--
Edd
Re: Maddening structures [message #50286 is a reply to message #50226] Tue, 19 September 2006 11:04 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Mon, 18 Sep 2006 11:47:23 +0000, Edd wrote:

> OK, I've got some data read in so that I have a structure that looks
> like
>
> data.foo[600]
> .bar[600]
> .baz[600]
>
> and I want
> data[600].foo
> .bar
> .baz
>
> In other words I want an array of structures rather than a structure
> of arrays.
>
> Does anyone have any magic that works for the case when foo, bar and
> baz are not previously known?

Read in the field names (from your file) into a string array "fields",
and the first set of values into a pointer array "vals", and then create
an array of structures like this:

st=create_struct(fields[0],*vals[0])
for i=1,nfields-1 do $
st=create_struct(st,fields[i],*vals[i])
st=replicate(st,ndata)

If your file format describes the type of each field (float, int,
string, etc.), you can parse that and make an appropriate vals pointer
array from it, rather than divining it from the data themselves (which
is more likely to give trouble).

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: spawn and 'ls *.out'
Next Topic: plot: Messed-up coordinates when switching devices

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

Current Time: Wed Oct 08 19:34:58 PDT 2025

Total time taken to generate the page: 0.00617 seconds