[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Q: pointers inside of an array of structures?
- Subject: Q: pointers inside of an array of structures?
- From: Amara Graps <Amara.Graps(at)mpi-hd.removethis.mpg.de>
- Date: Wed, 16 Aug 2000 10:01:06 +0200
- Newsgroups: comp.lang.idl-pvwave
- Organization: Max-Planck-Institut fuer Kernphysik
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:20870
Hi Folks,
I am trying to create and build a flexible data structure
in IDL for a situation where we have fields of different types
in a structure, and then that structure is made into an array
of structures using "replicate". And I extend the
array of structures by concantenating, because I don't
know how many structures I need.
My question: Can a field inside of the array-of-structures be
a pointer ?
For example --
I know how to flexibly extend a structure,
with each of the fields defined the same way:
-------
Create an array of an anonymous structure
IDL> thisstruc = {orbit:'', len:0,freq:DBLARR(100)}
IDL> periodcube = replicate(thisstruc,1)
;Put values into the structure
IDL> periodcube(0).orbit='G2'
IDL> periodcube(0).len=50 ;to store length of array : freq
IDL> periodcube(0).freq=DINDGEN(50)
;Create a temporary structure like the original
IDL> tempperiod = thisstruc
;Put values into the temporary structure
IDL> tempperiod.orbit='G3'
IDL> tempperiod.len=75
IDL> tempperiod.freq=DINDGEN(75)
;Now extend it by concatenating
IDL> newperiodcube=[periodcube,tempperiod]
;Take a look
IDL> help, newperiodcube, /st
** Structure <89af0>, 3 tags, length=816, refs=4:
ORBIT STRING 'G2'
LEN INT 50
FREQ DOUBLE Array[100]
IDL> print, newperiodcube(0).orbit, ' ', newperiodcube(1).orbit
G2 G3
IDL> print, newperiodcube(0).len, ' ', newperiodcube(1).len
50 75
-------
But what about varying data lengths inside of the array of
structures, for example, if my freq arrays are each a different
length:
IDL> thisstruc = {orbit:'', freq:ptr_new()}
IDL> periodcube = replicate(thisstruc,1)
;Put values into the structure
IDL> periodcube(0).orbit='G2'
IDL> *periodcube(0).freq=DINDGEN(50)
% Unable to dereference NULL pointer: <POINTER (<NullPointer>)>.
% Execution halted at: $MAIN$
What am I doing wrong?
Is it possible to have pointers inside of an array of structures?
My pointer programming experiences were 15 yrs ago in a Pascal
class.. it's quite possible I'm missing something big, with how
the pointers work...
Thanks very much in advance,
Amara
P.S. IDL Version 5.3 (sunos sparc)
--
***************************************************************
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