Maddening structures [message #50226] |
Mon, 18 September 2006 04:47  |
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 #50286 is a reply to message #50226] |
Tue, 19 September 2006 11:04  |
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
|
|
|