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

Home » Public Forums » archive » Help: definition of the structure in COMMON block
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
Help: definition of the structure in COMMON block [message #14809] Sun, 28 March 1999 00:00 Go to next message
VU KHAC Tri is currently offline  VU KHAC Tri
Messages: 25
Registered: March 1999
Junior Member
Hi folks,

I want to define a structured variable as global variable. So I think
about using the COMMON block to share this variable with others
procedures. However, IDL does not enable to use this variable in a
procedure without declaration.

pro A
COMMON SHARE1, X ;how to define x as a structure ?
X.a = 1
X.b = 2
end

pro B
COMMON SHARE1
X.a = 4 ; this is not permitted
X.b = 5
end


Does anyone know how to resolve this problem ?
Thanks for your help.
Best regards,
Tri.

PS. Thanks also all of you for all your precedent responses.
Re: Help: definition of the structure in COMMON block [message #14926 is a reply to message #14809] Tue, 30 March 1999 00:00 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
VU KHAC Tri wrote:

> Hi folks,
>
> I want to define a structured variable as global variable. So I think
> about using the COMMON block to share this variable with others
> procedures. However, IDL does not enable to use this variable in a
> procedure without declaration.
>
> pro A
> COMMON SHARE1, X ;how to define x as a structure ?
> X.a = 1
> X.b = 2
> end
>
> pro B
> COMMON SHARE1
> X.a = 4 ; this is not permitted
> X.b = 5
> end
>
> Does anyone know how to resolve this problem ?
> Thanks for your help.
> Best regards,
> Tri.
>
> PS. Thanks also all of you for all your precedent responses.

You should think about on using an heap variable too. With those kind of
variables you got more flexibility as with a common block.
This heap variable has to be defined only once and you can use it in each
routine without any declaration.

heap=PTR_NEW(CREATE_STRUCT(name='dd','name','a','value',24))

pro test
b=get_pointer('dd')
help,*b,/str
print,(*b).name
; ptr_free,b ;remove pointer
end





; Copyright (c) 1999, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is
not
; sold and this copyright notice is reproduced on each copy made. This
; routine is provided as is without any express or implied warranties
; whatsoever.
;+
; NAME:
; get_pointer
;
; PURPOSE:
; This routine gets a defined pointer over the structure name
;
; CATEGORY:
; PROG_TOOLS
;
; CALLING SEQUENCE:
; a=get_pointer(name)
;
; INPUTS:
; name : the name of the pointer
;
; OUTPUTS:
; the pointer or -1 if it is not defined
;
; EXAMPLE:
; a=PTR_NEW(CREATE_STRUCT(name='dd','name','a','value',24))
; b=get_pointer('dd')
; HELP,*b,/str
; ** Structure DD, 2 tags, length=12:
; NAME STRING 'a'
; VALUE INT 24
;
;
; MODIFICATION HISTORY:
; Idea was given by F.Rohrer ICG-3
; Written by: R.Bauer (ICG-1), 1999-03-15
;-



FUNCTION get_pointer,name
c=PTR_VALID()

errvar=0
catch,errvar
if errvar ne 0 then return,-1

FOR i=0,N_ELEMENTS(c)-1 DO BEGIN
s_name=TAG_NAMES(*c[i],/STRUCTURE_NAME)
IF STRUPCASE(name) EQ s_name THEN RETURN,c[i]
ENDFOR

RETURN,-1
END
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: bold text
Next Topic: Widget_Message on the Mac

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

Current Time: Wed Oct 08 19:23:31 PDT 2025

Total time taken to generate the page: 0.00746 seconds