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

Home » Public Forums » archive » Re: 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
Re: Maddening structures [message #50209] Mon, 18 September 2006 09:40
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> Fine, unless there might be further tags (which you can then solve
> with a bit of looping and executing), and complicated when they aren't
> all floats but a mix of floats, ints, longs and strings. See my other
> post...

What about using an array of pointers? drop the structure and work on
the array! ... it could be of any size!

Jean
Re: Maddening structures [message #50218 is a reply to message #50209] Mon, 18 September 2006 07:16 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Edd writes:

> Think I'm getting there though. Whether anyone will be able to manage
> this code later is another question.

Just leave all the comments out. Then, whoever has to
deal with it later will have to rewrite it the way
it SHOULD have been written in the first place. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Maddening structures [message #50219 is a reply to message #50218] Mon, 18 September 2006 06:55 Go to previous message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
David Fanning <davidf@dfanning.com> wrote:
> Edd writes:

>> 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?

> names = ['foo','bar', 'baz']
> struct = Create_Struct(names[0], 0.0, names[1], 0.0, names[2], 0.0)
> data = Replicate(struct, 600)

Fine, unless there might be further tags (which you can then solve
with a bit of looping and executing), and complicated when they aren't
all floats but a mix of floats, ints, longs and strings. See my other
post...

Think I'm getting there though. Whether anyone will be able to manage
this code later is another question.

--
Edd
Re: Maddening structures [message #50220 is a reply to message #50219] Mon, 18 September 2006 06:54 Go to previous message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
Edd <eddedmondson@hotmail.com> wrote:

> That's where I was looking too. I wasn't sure how to handle the
> structure creation neatly though. Once you have the tag names you can
> loop over them in a for loop (there won't be that many tags anyway) so
> it's not too bad. Just a bit hairy. It'd be nice if there was a
> reform-alike. :-)

Saying it's not too bad is an exaggeration. All this is happening
inside an execute(), so I'm entering it in one set of ''s. I need to
put it all in another execute() inside that to make it
on-the-fly-enough, which uses up a "" inside the '', leaving me using
STRING(39B) to get a third tier. I've managed to build up a string
that looks like

'mystructure=create_struct('foo',0.1,'bar',1242999,'baz',som estring)'
which means I get my float in foo, my long in bar, but baz complains
because the string is coming out without the ''s it needs, only I
can't put those ''s in in general or the floats and longs turn into
strings too, breaking other stuff.

It's the ugliest code I've written (well, since that bit of Perl I did
last week) and I'm about to throw a brick at the screen. All this just
to rejig a structure a bit. Surely this can be done with histogram()
or something ;-)

--
Edd
Re: Maddening structures [message #50221 is a reply to message #50220] Mon, 18 September 2006 06:52 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Edd writes:

> 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?

names = ['foo','bar', 'baz']
struct = Create_Struct(names[0], 0.0, names[1], 0.0, names[2], 0.0)
data = Replicate(struct, 600)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Maddening structures [message #50222 is a reply to message #50221] Mon, 18 September 2006 05:24 Go to previous message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
Maarten <maarten.sneep@knmi.nl> wrote:

> 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?

> Perhaps my reading comprehension isn't quite awake yet, but:

> 1) do you mean the names themselves, or the number of fields (there may
> also be a fuu around, in addition to the foo, bar and baz)?

I'd basically like the most general method I can find (so I don't have
to go recoding stuff when another field gets added a week or two down
the line). So number and naming of fields should be considered flexible.

> Get the names with tag_names(data), obtain the length with
> size(data.(0), /dim), create a base struct with base =
> CREATE_STRUCT(...) and replicate() the base to the right size. At least
> that is where I would look. Copying is another matter, perhaps others
> can comment on how to do this efficiently. At least you have the right
> structure to store the stuff.

That's where I was looking too. I wasn't sure how to handle the
structure creation neatly though. Once you have the tag names you can
loop over them in a for loop (there won't be that many tags anyway) so
it's not too bad. Just a bit hairy. It'd be nice if there was a
reform-alike. :-)

I may try for an alternative workaround, as rejigging the other bits
probably involves less recoding than doing the jigging with this.

--
Edd
Re: Maddening structures [message #50223 is a reply to message #50222] Mon, 18 September 2006 05:23 Go to previous message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
Maarten <maarten.sneep@knmi.nl> wrote:

> 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?

> Perhaps my reading comprehension isn't quite awake yet, but:

> 1) do you mean the names themselves, or the number of fields (there may
> also be a fuu around, in addition to the foo, bar and baz)?

I'd basically like the most general method I can find (so I don't have
to go recoding stuff when another field gets added a week or two down
the line). So number and naming of fields should be considered flexible.

> Get the names with tag_names(data), obtain the length with
> size(data.(0), /dim), create a base struct with base =
> CREATE_STRUCT(...) and replicate() the base to the right size. At least
> that is where I would look. Copying is another matter, perhaps others
> can comment on how to do this efficiently. At least you have the right
> structure to store the stuff.

That's where I was looking too. I wasn't sure how to handle the
structure creation nearly though. Once you have the tag names you can
loop over them in a for loop (there won't be that many tags anyway) so
it's not too bad. Just a bit hairy. It'd be nice if there was a
reform-alike. :-)

I may try for an alternative workaround, as rejigging the other bits
probably involves less recoding than doing the jigging with this.

--
Edd
Re: Maddening structures [message #50224 is a reply to message #50223] Mon, 18 September 2006 05:13 Go to previous message
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
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?

Perhaps my reading comprehension isn't quite awake yet, but:

1) do you mean the names themselves, or the number of fields (there may
also be a fuu around, in addition to the foo, bar and baz)?

Get the names with tag_names(data), obtain the length with
size(data.(0), /dim), create a base struct with base =
CREATE_STRUCT(...) and replicate() the base to the right size. At least
that is where I would look. Copying is another matter, perhaps others
can comment on how to do this efficiently. At least you have the right
structure to store the stuff.

Maarten
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: calculating rotations from a transformation matrix
Next Topic: IMSL coming to IDL

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

Current Time: Wed Oct 08 15:39:56 PDT 2025

Total time taken to generate the page: 0.00690 seconds