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

Re: Structure field concatenation

Hi folks,

I want to thank all of you for your help on this topic. After 
trying the suggestions, I was successful at performing a flexible 
concatenation of an array of structures with elements  that are 
pointers. I append the following small program that demonstrates 
how to do this, in case anyone else is interested. 

Thanks again!


;==========cut here========================================

;Program testpointer.pro

;PURPOSE: This IDL program is an example of an array of anonymous
;structures of fields including a pointer field. Here we don't know how
;many structures we want in our array of structures, nor do we know the
;data definition of of our pointer. This program is one way to create an 
;array of structures on the fly, with data that is not defined
;Note: tested on IDL Version 5.3 (sunos sparc)
;Amara Graps 9 Septempber 2000

;Create an anonymous structure
thisstruc = {orbit:'',freq:PTR_NEW()}

;Create a 1-element array of anonymous structure  (we will concatenate
;to make a longer array, when we need it).
periodcube = REPLICATE(thisstruc,1)

;Assign the structure values: Gal orbit G2, index array of length 100
periodcube[0].orbit = 'G2'
        ELSE: BEGIN
                ;Make it a valid pointer and fill it
                periodcube[0].freq = PTR_NEW(DINDGEN(100))

;set a variable to the pointer, if we want to play with it
test1 = *periodcube[0].freq
;Take a look
help, test1   

;Update the structure by creating a temporary structure like the
;original, and then concantenating
tempperiod = thisstruc

;Assign the structure values, Gal orbit C3, index array of length 50
tempperiod.orbit = 'C3'
        PTR_VALID(tempperiod.freq): *tempperiod.freq=DINDGEN(50)+50
        ELSE: BEGIN
                ;Make it a valid pointer and fill it
                tempperiod.freq = PTR_NEW(DINDGEN(50)+50)

;Set a variable to the pointer, if we want to play with it
test2 = *tempperiod.freq
;Take a look
help, test2      

new = [periodcube,tempperiod]

;Set variables to the pointers in the structure
;in order to perform more manipulation
freq1 = *new[0].freq
freq2 = *new[1].freq

;Take a look  (These are OK)
help, freq1, freq2   
help, *new[0].freq,*new[1].freq 
help, new[0].orbit, new[1].orbit

;To concantenate indefinitely, rename and repeat STEP 2
periodcube =  new

STOP, 'look at structure periodcube'

END     ;of program testpointer.pro


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