Re: Passing a structured variable as an argument of procedure [message #14703] |
Mon, 22 March 1999 00:00 |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
VU KHAC Tri wrote:
>
> Hi folks,
>
> I'm very new in IDL programming.
> My question is can I pass a structured variable as an argument of a
> procedure ?
> How to define this ?
(A) if you create a structure outside of your procedure, you can pass it
like any other variable either as parameter or keyword:
a = { test:'my name', value=100 }
my_proc,a
or my_proc,structure=a
(you may find my little chkstru function helpful to test whether
what you passed really is a structure and [optionally] if it contains
the fields ("tags") that you need. You can get it from my webpage (see
below)).
(B) same thing holds if you create your structure within your procedure.
Example:
pro my_proc,newstru
newstru = { dummy:1.0, truevalue:1 }
end
(and in "main"):
my_proc,test
print,test
Hope this helps,
Martin.
--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Engineering&Applied Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA
phone: (617)-496-8318
fax : (617)-495-4551
e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------
|
|
|
Re: Passing a structured variable as an argument of procedure [message #14705 is a reply to message #14703] |
Mon, 22 March 1999 00:00  |
Ivan Zimine
Messages: 40 Registered: February 1999
|
Member |
|
|
VU KHAC Tri wrote:
>
> Hi folks,
>
> I'm very new in IDL programming.
> My question is can I pass a structured variable as an argument of a
> procedure ?
yes
> How to define this ?
PRO test, struct
; check if variable is a structure
IF Size(struct, /type) NE 8 THEN BEGIN
Message, "Parameter must be a structure", /continue
Return
ENDIF
; to get an array of strings with field names
fields=Tag_Names(struct)
.
.
.
END
--
Ivan Zimine
Dpt. of Radiology (MRI), Geneva University Hospitals
email: ivan.zimine@physics.unige.ch
tel. : (+41 22) 372 70 70
|
|
|