[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Structure field concatenation
Ben Tupper wrote:
>
> Hello and thanks to all,
>
> I guess I'm headed toward pointers as fields.
There's alot of discussions here about structures and pointers
as fields inside of the structures. I'm learning alot, but still
having some trouble. I have made my best attempt to getting a
structure-with-pointer array concatenation to work properly,
and I've not been successful yet.
Everything works fine up to the point that I concatenate the array,
then I lose the previous definition of the pointer. Is there a
pointer cleanup that I should be doing?
My test code is the following:
;-------begin test code
;Create an anonymous structure
thisstruc = {orbit:'',freq:ptr_new(/allocate_heap)}
;Create an array of anonymous structure
periodcube = replicate(thisstruc,1)
;Assign the structure values
periodcube(0).orbit = 'G2'
*periodcube(0).freq=DINDGEN(100) ;first pointer array is len 100
;set a variable to the pointer
test1 = *periodcube[0].freq
;Take a look
help, test1 ;(it's len 100, and OK)
;Update the structure by creating a temporary structure like the
;original, and then concantenating
tempperiod = thisstruc
;Assign values to the structure
tempperiod.orbit='C3'
*tempperiod.freq = DINDGEN(50)+50 ;this pointer array is len 50
;Set a variable to the pointer
test2 = *tempperiod.freq
;Take a look
help, test2 ;(it's len 50, and OK)
;Concatenating (here is where the problem begins)
new = [periodcube,tempperiod]
;Set variables to the pointers in the structure
freq1 = *new[0].freq
freq2 = *new[1].freq
;Take a look
help, freq1, freq2 ;WHY ARE FREQ1 FREQ2 THE SAME?
help, *new[0].freq,*new[1].freq ;BOTH LENGTH 50.. WHY?
help, new[0].orbit, new[1].orbit ;THESE STRINGS ARE OK THOUGH
END
;---end test code
Can anyone give me a hint about why the second pointer is overwriting
the definition of the first pointer?
Thanks very much, in advance,
Amara
--
***************************************************************
Amara Graps | Max-Planck-Institut fuer Kernphysik
Interplanetary Dust Group | Saupfercheckweg 1
+49-6221-516-543 | 69117 Heidelberg, GERMANY
* http://galileo.mpi-hd.mpg.de/~graps
***************************************************************
"Never fight an inanimate object." - P. J. O'Rourke