[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: forcing variable definition in IDL?
- Subject: Re: forcing variable definition in IDL?
- From: davidf(at)dfanning.com (David Fanning)
- Date: Tue, 1 May 2001 06:32:13 -0600
- Newsgroups: comp.lang.idl-pvwave
- Organization: Fanning Software Consulting
- References: <3AEE557E.126C92E8@kurasc.kyoto-u.ac.jp>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:24760
Gernot Hassenpflug (gernot-nospam@kurasc.kyoto-u.ac.jp) writes:
> So, my question: is it possible in IDL 5.4 to force definition of
> variables, or at least to automate a variable-check in IDL.
It is certainly possible to "force" a variable to
have a certain definition. That's not the problem.
The problem is making it *stay* a certain definition.
That, in general, is not possible in IDL, since IDL
has dynamic typing capability.
>
> Alternatively, maybe I need to write a function that automatically
> checks the first use of a variable in a program. I have used the
> routine_info and routine_names functions to obtain information
> about variables in scope at the time.
You can check. But like recalcitrant children, they
will be doing something else the minute you turn
your back. :-)
> Does anyone know of either how to get IDL to check variables'
> definition,
> or how to write a function to do that?
IDL> theType = Size(variable, /Type)
Or, if you prefer the type "name":
IDL> theTypeName = Size(variable, /TName)
> I have also toyed with the idea of using each variable as a single-
> element array (eg. b(0) = 1), but that is most inelegant and lengthy.
Don't bother. IDL scalars *are* single element arrays:
IDL> a=5
IDL> a[0] = 6 & Print, a
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155