Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

Running IDL Programs


IDL programs can be executed in the following ways:

Executing a Batch File

To execute a batch file, enter the name of the file, prefaced with the "@" character, at the IDL prompt:

@batchfile 

where batchfile is the name of the file containing IDL statements.

Note
This syntax can also be used within an IDL program file.

For more on batch files, see Executing Batch Jobs in IDL.

Executing a Main-Level Program

To execute a Main-level program, use the .RUN or .RNEW executive command to enter the program at the IDL command line. The program will be executed automatically after you enter the END statement. To run the Main-level program again, use the .GO executive command.

For more on Main-level programs, see Main-Level Programs.

Executing Programs Stored in a Program File

IDL program files, identified with a .pro extension, can be compiled and executed using the following methods:

Using the IDLDE Interface

To run an IDL program using the IDLDE interface, do the following:

  1. Open the file in the IDLDE editor. For example, select:
    File ® Open ® RSI\IDL61\examples\demo\demosrc\d_uscensus.pro
  2. Compile the file by selecting Run ® Compile filename
  3. where filename is the name of the file opened in the IDLDE editor (d_uscensus.pro, in this example).

  4. Execute the file by selecting Run ® run filename
  5. where filename is the name of the file opened in the IDLDE editor (d_uscensus.pro, in this example).

From the IDL Command Line

When a file is specified by typing only the filename at the IDL prompt, IDL searches the current directory for filename.pro (where filename is the file specified) and then for filename.sav. If no file is found in the current directory, IDL searches in the same way in each directory specified by !PATH. If a file is found, IDL automatically compiles the contents and executes any functions or procedures that have the same name as the file specified (excluding the extension). See Automatic Compilation for additional details.

Using the previous example, run the US Census Data demo by entering the following at the command line:

d_uscensus 

Using Executive Commands

When a file is specified using either the .RUN, .RNEW, .COMPILE, or @ command followed by the filename, IDL searches the current directory for filename.pro (where filename is the file specified) and then for filename.sav. If no file is found in the current directory, IDL searches in the same way in each directory specified by !PATH. If a file is found, IDL compiles or runs the file as specified by the executive command used. Executive commands can be entered only at the IDL command prompt and are often used when executing main-level program files. See Executive Commands for more information.

Warning
If the current directory contains a subdirectory with the same name as filename, IDL will consider the file to have been found and stop searching. To avoid this problem, specify the extension (.pro or .sav, usually) when entering the run, compile, or batch file executive command.

The details of how !PATH is initialized and used differ between the various operating systems, although the overall concept is the same. See !PATH for more information.

Executing Programs Stored in a SAVE File

IDL SAVE files (created using the SAVE procedure) can contain one or more routines that have been packaged into a single binary file. (Variables, including system variables, can also be packaged into a SAVE file: see Saving Variables from an IDL Session for a more complete discussion.)

Note
While IDL routines or data can be saved in a file with any extension, it is common to use the extension .sav for SAVE files. Using the .sav extension has two benefits: it makes it clear to another IDL user that the file contains IDL routines or data, and it allows IDL to locate routines with the same base name as the file in SAVE files located in IDL's path.

For an example of creating and restoring a SAVE file, see Restoring Compiled IDL Programs and Data.

Routines stored in SAVE files can be restored and executed in the following ways:

From the IDL Command Line

If the program you wish to run is stored in a SAVE file with the same base name as the program and the extension .sav, and the SAVE file is stored in a directory included in the IDL !PATH system variable, simply entering the name of the routine at the IDL command prompt will restore the program and execute it immediately. For example, if an IDL program named myroutine is stored in myroutine.sav, which is located in a directory included in !PATH, entering the following at the IDL command line will restore the routine and execute it:

myroutine 

See Automatic Compilation for additional details.

Using the RESTORE Procedure

You can use the RESTORE procedure to restore all of the routines contained in a SAVE file without executing them. Once a routine has been restored, you can execute it simply by typing its name at the IDL command prompt. For example, if an IDL program named myroutine is stored in myroutine.sav, which is located in a directory that is not in !PATH, entering the following at the IDL command line will restore the routine and execute it:

RESTORE, 'path/myroutine.sav' 
myroutine 

where path is the full path to the myroutine.sav file. See The RESTORE Procedure for additional details.

Using the IDL_Savefile Object

You can use the IDL_Savefile object class to gain information about the contents of a SAVE file, and to selectively restore items from the save file. Once a routine has been restored via calls the IDL_Savefile object, you can execute it simply by typing its name at the IDL command prompt. For example, if an IDL program named myroutine is stored in myroutine.sav, which is located in a directory that is not in !PATH, entering the following at the IDL command line will restore the routine and execute it:

obj = OBJ_NEW('IDL_Savefile', 'path/myroutine.sav') 
obj->Restore, 'myroutine' 
myroutine 

where path is the full path to the myroutine.sav file. See The IDL_Savefile Object for additional details.


Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]