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

Home » Public Forums » archive » Structure field concatenation
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: Structure field concatenation [message #21716 is a reply to message #21636] Mon, 11 September 2000 04:04 Go to previous messageGo to previous message
Amara Graps is currently offline  Amara Graps
Messages: 24
Registered: June 1996
Junior Member
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!

Amara

;==========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
beforehand.
;Note: tested on IDL Version 5.3 (sunos sparc)
;----------------------------------------------------------- --
;Amara Graps 9 Septempber 2000
;----------------------------------------------------------- --

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

;Create a 1-element array of anonymous structure (we will concatenate
it,
;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'
CASE 1 OF
PTR_VALID(periodcube[0].freq):
*periodcube[0].freq=DINDGEN(100)
ELSE: BEGIN
;Make it a valid pointer and fill it
periodcube[0].freq = PTR_NEW(DINDGEN(100))
END
ENDCASE

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

;STEP 2
;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'
CASE 1 OF
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)
END
ENDCASE

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

;Concatenating
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDLgrROI and normalized coords
Next Topic: Re: taking the widget plunge. help

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

Current Time: Fri Oct 10 06:13:25 PDT 2025

Total time taken to generate the page: 0.80199 seconds