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

Home » Public Forums » archive » Re: [Q] structure definition with variable array size
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: [Q] structure definition with variable array size [message #12098 is a reply to message #12097] Thu, 25 June 1998 00:00 Go to previous message
Matthew J. Sheats is currently offline  Matthew J. Sheats
Messages: 19
Registered: September 1997
Junior Member
> I wish to create a structure for holding a slice from a 3d volume along
> with domain info, e.g.,
>
> pro slice__define
> tmp = {slice, data:fltarr(100,100), x:fltarr(100), y:fltarr(100), z:0.0}
end
>
> This definition is fine if the data dimensions are known. However, what
> if the array sizes are only known at runtime when the data file is opened
> and brought into IDL. Is it possible to have structures with arbitrary
> length arraysa la F90, C, or Pascal?
>
> Cheers,
> Darran.

Unfortunately, the only way I have found to defeat this limitation is
to use pointers. For example:

tmp = { slice, data:PTR_NEW(0), x:PTR_NEW(0), ... } etc for all dynamic
arrays.

Then in run time...

data = PTR_NEW(FLTARR(100,100))

Now that just actually allocates the pointer, you haven't actually
allocated the array yet, you need one more call like this:

(*data) = FLTARR(100,100)

Now you have a dynamically set array in a structure. Bit of a pain,
but it works. And it works great with IDL's OOP. Just remember you
have to use the pointer dereference whenever you access the array:

(*data)[10,15] = 5.0

or whatever.

Hope this help,

Matthew Sheats
Los Alamos National Laboratory
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Keyword_Set vs N_Elements Re: Problems with CW_FSLIDER
Next Topic: Re: [Q] IDL 5.1, passing keyword params to subprocedures

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

Current Time: Sun Apr 26 15:11:52 PDT 2026

Total time taken to generate the page: 1.11706 seconds