[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global variables and IDL

Walter Roberson (roberson@ibd.nrc.ca) 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
> changes.

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: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155