[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Structure field concatenation




Your technique is not incorrect.  IDL doesn't make it easy to fiddle
with structures so you're not going to get too much better than what
you have now.

A few things from my experience.  First, creating and recreating
structures appears to be a fairly expensive operation.  If you do it
once in a while that's fine, but if you do it with huge arrays, or
many times repetitively then you may start to feel the burn.  

Second, you should be aware that IDL has some peculiar behaviors when
extracting arrays with trailing dimensions of 1.  Basically, those
trailing dimensions disappear.  For arrays with only one element, you
get a scalar out, which is entirely a bug.  Is this fixed in IDL 5.4?
My function TAGSIZES attempts to get around these problems but it's
not easy.  If you always have 1D arrays you should be okay.

Finally, be prepared for people to tell you to use pointers.  They
actually are a very natural way to have structures with elements that
vary in size.  However along with that comes the extra baggage of
allocating and then freeing the heap memory.

Good luck,
Craig

The bug I mentioned can be exercised via the following:
x = {a:reform(intarr(1,1),1,1)}
help, x.a    ;; Result will be a scalar, not a 1x1 array

TAGSIZES available from http://cow.physics.wisc.edu/~craigm/idl/idl.html

Ben Tupper <pemaquidriver@tidewater.net> writes:

> Hello,
> 
> I know that this has been a subject of some discussion recently... but
> I'm still not on firm footing on the best method of changing the size of
> an anonymous structure's fields (i.e. I want to increase or decrease the
> size of a field).   The code below shows an example of how I do it now:
> creating a new structure with the appropriately sized fields.  Is there
> a better method?
> 
> ;++++++++++++ START
> PRO Concatenate_Str_Fields
> 
> D = {A:Indgen(12), B:Indgen(12)}            ;define a dummy structure
> 
> Help, D, /STR
> 
> Tags = Tag_Names(D)
> 
> NewD = Create_Struct(Tags[0], [D.(0), Indgen(10)])    ;define the new
> structure with amended field
> 
> For i = 1, N_ELEMENTS(Tags) -1 Do $            ;for each tag recreate
> the structure
>  NewD = Create_Struct( NewD, Tags[i],[D.(i), Indgen(10)] )
> 
> Help, NewD, /STR
> 
> END
> 
> ;--------------------END
> 
> Thanks,
> 
> Ben
> 
> BTW:   I don't want to steer the discourse toward a scandalous sidebar
> discussion, but...  I'm wrestling with this because a shrimp starts out
> as a male and then ends up as a female a few years later.   I'm working
> with a database that has the shrimp broken down into records by sex...
> but I need to add new records for aggregate sex (that is the sum of
> males, transitionals, females,...)   I never thought IDL programming
> could be so titillating.
> 
> --
> Ben Tupper
> 248 Lower Round Pond Road
> POB 106
> Bristol, ME 04539
> 
> Tel: (207) 563-1048
> Email: PemaquidRiver@tidewater.net
> 
> 

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------