[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Global variables and IDL
- Subject: Re: Global variables and IDL
- From: davidf(at)dfanning.com (David Fanning)
- Date: Tue, 13 Apr 1999 07:11:55 -0600
- Newsgroups: comp.lang.idl-pvwave
- Organization: Fanning Software Consulting
- References: <Pine.SOL.3.91.990412155703.3085C-100000@galileo> <email@example.com> <firstname.lastname@example.org>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:14330
Walter Roberson (email@example.com) writes:
> Jim Russell wrote:
> :I'm certain that IDL has a global variable (I remember it being mentioned in
> :Fanning's book), but don't remember how to invoke it. Maybe someone else can
> :provide that for you.
> Use a common block. That requires adding only one extra statement to each
> routine that uses an element of the common, and requires no other code
I'm quite sure you didn't find a common block recommendation in
Fanning's book. :-(
What I may have recommended was to create your own *system
variable*, which is the IDL equivalent of a global variable.
For example, if I were building a large application that I
wanted to run in both a Windows and UNIX environment, and that
application has a lot of sub-directories, etc. then I can have
a great deal of trouble with filenames. For example, the
"data" directory might be E:\secret\data on the PC and
/usr/people/bob/secret/data on the UNIX machine. In fact,
every installation may have their own data directory.
Writing code that can actually find the application's
data directory could be a nightmare.
So I might write a "preferences" file for the application
that each person who installs the application has to modify
for their site. One item might be the location of the
"data directory". On the PC, this might look like this:
DEFSYSV, '!Data_Directory', 'E:\secret\data'
The UNIX user would modify this line to this:
DEFSYSV, '!Data_Directory', '/usr/people/bob/secret/data'
But now it is easy for me to write code to look in this
directory. I simply construct my filenames like this:
datafile = Filepath(Root_Dir=!Data_Directory, $
SubDir=['experiment', 'daytwo'], 'exper12a.dat')
In the past 7-8 years I've found more use for GOTOs than
I have for common blocks, and I NEVER use a GOTO if I
can avoid it. :-)
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: firstname.lastname@example.org
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155