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

Home » Public Forums » archive » Re: referencing structure arrays
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: referencing structure arrays [message #68007 is a reply to message #68004] Thu, 10 September 2009 09:36 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Sep 10, 1:12 pm, niv <nivedita.raghun...@gmail.com> wrote:
> Sorry, looks like what I typed looks gibberish in places. I hope this
> one is more readable:
>
> Hi All,
>
> I have a problem referencing structure arrays and assigning values to
> them. So here is a snippet of my code:
>
> junk1=update_state(junk)   ;creates a structure called junk1
> statearr=replicate(junk1,3)  ;creates an array of structures
>
> infoptr=ptr_new({statearr:statearr})  ;need this to pass variables
> between programs
>
> align_images,state=state1  ;some program that aligns 2 images and
> stores the alignment results in state1
>
> ;assign values from the state1 structure to infoptr.statearr[0]
> structure
> (*infoptr).statearr[0].resvol_file_ptr=state1.resvol_file_pt r
> (*infoptr).statearr[0].air_file_ptr=state1.air_file_ptr
>
> Now, here is the problem. With the above code, it turns out that...
>
> (*infoptr).statearr[0].resvol_file_ptr, (*infoptr).statearr
> [1].resvol_file_ptr, (*infoptr).statearr[2].resvol_file_ptr
> all have the same values. Similarly with air_file_ptr. Even though I
> haven't assigned anything to the statearr 1 and 2 yet.
>
> Is there a specific way to reference these structure arrays? Any help
> is greatly appreciated!
>
> Thanks
> Niv

If I read it right, it sounds like state1.resvol_file_ptr is not a
scalar, but is an array with 3 elements. Check it with n_elements
(state1.resvol_file_ptr). Put it another way, I think what is
happening is the same as

IDL> a=intarr(3)
IDL> print,a
0 0 0
IDL> b=[1,1,1]
IDL> a[0]=b
IDL> print,a
1 1 1

Which is that way because if you use an array element on the left side
of an assignment, and assign to it an array with N elements, then N
elements are assigned, starting at the one given on the left side.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Readu, Writeu Causing Segmentation Fault
Next Topic: Issue with logrithmic z-axis... fix?

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

Current Time: Wed Oct 08 19:20:55 PDT 2025

Total time taken to generate the page: 0.24312 seconds