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

Home » Public Forums » archive » Q: pointers inside of an array of structures?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Q: pointers inside of an array of structures? [message #21311] Wed, 16 August 2000 00:00
Amara Graps is currently offline  Amara Graps
Messages: 24
Registered: June 1996
Junior Member
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Reverse interpolation?
Next Topic: Re: xplot with overplotting

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

Current Time: Thu Oct 09 07:53:37 PDT 2025

Total time taken to generate the page: 2.55486 seconds