Command Line

While the IDL command line is not a type of program, it is an effective tool for programmers. Using the command line, you can execute IDL statements one at a time. This interactive mode allows you to test code immediately. You can accomplish a variety of tasks from the command line, from printing the result of a computation to displaying a plot.

The command line has access to all variables available in IDL's current scope. For example, once you define variable a, you can use that same variable in the commands you type at the command line, until you manually change the value of a. (See also Scope.)

Note
If a program has stopped running, the current scope of the command line is not necessarily the main scope, but the scope of the program where it stopped. All the variables in that scope are now accessible to the command line. To return control and scope to the main level, enter the RETALL command.

You cannot include loops and other flow control methods on the command line in the same way as in a compiled program. Each line must be an executable IDL statement.

Examples

The following examples range from simple print commands to more complex computations and plots. Just click the blue example code to execute it in IDL. To run your own commands, just type them at the IDL command line and press Enter.

Example 1

To find the sine of 0.5 radians and print the result, enter:

PRINT, SIN(0.5)

IDL prints:

0.479426 

Example 2

A more complicated computation can require several lines of code, including comments. In IDL, code comments start with a semicolon (;).

Note
IDL ignores any text following a semicolon (;). If you are typing these examples into IDL, you can exclude the comment lines.

; Define a variable containing a 15-element vector of sample data:
x = [65, 63, 67, 64, 68, 62, 70, 66, 68, 67, 69, 71, 66, 65, 70]

; Compute the average:
result = MEAN(x)

; Print the result:
PRINT, result

IDL prints:

66.7333  

Example 3

To display a simple plot, use a statement like the following, which uses the FINDGEN function that creates a 200-element floating-point array:

PLOT, FINDGEN(200)

IDL displays the following plot:

plot01.gif

Example 4

Example 5

To display data in the iPlot tool, you can use the same data as the previous example, but substitute the PLOT command with IPLOT:

; Name a variable that defines the data to use.
file = FILEPATH('dirty_sine.dat', $
    SUBDIRECTORY = ['examples', 'data'])

; Create a variable that reads the data as a binary
; and defines the data dimensions.
data = READ_BINARY(file, DATA_DIMS = [256, 1])

; Plot the data
IPLOT, data

IDL displays the data in an iPlot window, where you can manipulate the data display using the graphical interface:

iplot_data.gif

IDL iTools are explained in more detail later in this tutorial (See iTools).