9910

How do I specify a program to automatically run when my IDL session starts up?

QUESTION:

How do I specify a program to automatically run when my IDL session starts up?

ANSWER:

You can set the IDL preference "IDL_STARTUP" to cause an IDL command line or IDL Workbench session to automatically run an IDL batch command file or batch script (a list of IDL commands in the same format that you would enter at an IDL> command prompt) at session startup.  There are various approaches to do this:

1.) Preferences dialog.

From an IDL Workbench session, open the Preferences dialog (Window > Preferences) then on the left pane of the dialog select "IDL".  On the resulting right pane define the text field labeled with "Startup file:" to reflect the fully qualified file path and name to you IDL batch script.  Click Apply and OK to commit the change to be honored in subsequent IDL sessions. The IDL_STARTUP preference setting is saved to your "idl.pref" file.  (See item 5 below for the location of the "idl.pref" file.)

2.) PREF_SET routine.

From an IDL> command prompt, you can set the preference IDL_STARTUP using the IDL routine PREF_SET, for example (Linux):

    PREF_SET, 'IDL_STARTUP', '/home/joeuser/mystartup.pro', /COMMIT

3.) System environment variable.

Define a system environment variable named "IDL_STARTUP" in the environment used to start your IDL session.  For example, on Linux from a Bash shell:

    export IDL_STARTUP=/home/joeuser/mystartup.pro

On Windows, define IDL_STARTUP via a Windows System environment variable or User environment variable via the Advanced System Properties section of your Computer properties dialog.

Note that setting an IDL preference via a system environment variable does not commit the setting to the user's "idl.pref" file.  Additionally, that particular preference cannot be changed during the affected IDL session.

4.) IDL command line switch.

Dynamically set the IDL preference in the command used to start your IDL session.  For example, on Linux:

    idl -IDL_STARTUP /home/joeuser/mystartup.pro

On Windows 7:

    idl -IDL_STARTUP "C:\Users\joeuser\mystartup.pro"

Setting an IDL preference via a command line switch when launching an IDL session does not commit the setting to the user's "idl.pref" file.  Additionally, that particular preference cannot be changed during the affected IDL session.

5.) Edit idl.pref File.

(This approach may be useful if you are distributing a customized IDL Runtime or IDL Virtural Machine distribution created with the MAKE_RT routine, to be used with a specific IDL application save file that you are distributing to users.)

Directly define a custom IDL_STARTUP preference in your "idl.pref" file.  The location of the "idl.pref" file is located under the user's ".idl directory tree (typically in the user's home directory), where the actual subdirectory location depends on the version of IDL being used.

For example, on Linux for IDL 8.2:

     /home/joeuser/.idl/idl/pref-10-idl_8_2-unix/idl.pref

On Windows 7:

     C:\Users\joeuser\.idl\idl\pref-10-idl_8_2-windows\idl.pref

A actual custom preference entry for IDL_STARTUP might look like the following in the idl.pref file on Linux:

     IDL_STARTUP : /home/joeuser/mystartup.pro

On Windows 7, it might look like this:

     IDL_STARTUP : C:\Users\joeuser\mystartup.pro

MISCELLANOUS:

* To see what your current IDL_STARTUP preference definition looks like, you can issue the IDL command:

    HELP, /PREFERENCES, NAME='IDL_STARTUP'

and/or:

    PRINT, PREF_GET('IDL_STARTUP')

* To restore the IDL_STARTUP preference (in the user's "idl.pref" file) back to its default value, you can issue a command like:

    PREF_SET, 'IDL_STARTUP', /DEFAULT, /COMMIT

* An IDL startup program will only automatically execute from IDL sessions where the command prompt is present. For example, an IDL_STARTUP script can be used with an IDL command line session or IDL Workbench session, but not with an IDL Runtime or IDL Virtual Machine (VM) session.

* An IDL batch script is not a defined IDL procedure or function with a "PRO" or "FUNCTION" declaration or a program "END", or even an IDL main level program.  Instead it is composed of a series of IDL command statements or dot commands that can be issued individually at an IDL command prompt.

* To automatically run a user defined procedure or function at IDL startup time, you'll need to create a IDL batch script wrapper which calls the program. That IDL batch script can be referenced by the IDL_STARTUP preference.

* The IDL_STARTUP preference does not need specify a fully qualified path to the startup IDL batch script file as long as the file named with a ".pro" file name extension and is in a directory included in your "IDL_PATH" IDL program search path preference.

+ When customizing your "IDL_PATH" IDL program search path preference, be sure to include the "<IDL_DEFAULT>" token to specify the IDL standard library directories, in addition to specifying your custom directories.  On Linux, separate a list of multiple IDL_PATH items with a ":" character. For example using PREF_SET from an IDL command prompt:

    PREF_SET, 'IDL_PATH', '<IDL_DEFAULT>:/home/joeuser', /COMMIT

On Windows, use a ";" character to separate multiple IDL_PATH items. For example, using PREF_SET:

    PREF_SET, 'IDL_PATH', '<IDL_DEFAULT>;C:\Users\joeuser', /COMMIT

ADDITIONAL RESOURCES:

Additional information about IDL system preferences can be found in the IDL Online Help, and also on the Documentation Center accessed from the Exelis VIS web site:

    http://www.harrisgeospatial.com/docs/About_IDL_System_Prefere.html


Please login or register to post comments.