IDL Background

This overview of the structure of IDL is from the user perspective. It is intended to give new users an orientation to the environment and the ability to begin using IDL.

One can visualize the IDL computing environment as four interacting components:

  1. Operating system of the computer. The OS provides services such as the windows system, network connectivity, disk access, printing and so on. IDL uses these services. For some work you may want to have multiple applications running in the OS while using IDL.
  2. The IDL system. This contains the IDL commands, functions and procedures, system constants, system variables and the heap. It provides the IDL Development Environment (IDLDE) graphical user interface.
  3. User programs and data files. These are the functions and procedures you have developed as well as the data files that you use.
  4. The user. You are an active participant in using the system to understand algorithms and produce expressions of them in computer code.

All of the actions that are carried out by IDL are done by commands. IDL comes with a set of built-in commands that can be used to build user-defined commands. These can be used to build more commands. A program is essentially an organized collection of commands and control statements. The name of the program becomes a new command in your library. You can use your commands in exactly the same way as you use IDL commands. You can build your own library, and exchange programs with other people. The same programs run on all of the platforms.

A lot of learning IDL is learning what commands are available in the system. The structure of commands is reasonably simple.

IDL also provides a number of constants, such as Pi, and maintains system variables. The constants are for your convenience. The system variables keep track of all sorts of system parameters and settings. Your programs have access to all of the variables and can manipulate them.

The programs use variables to manipulate data. Variables can be scalars, arrays, structures, pointers or objects. The statement A=3.1 creates a scalar variable named A and gives it the value 3.1. The statement B=[0,1,2,3] creates a array variable named B and fills it with the values 0,1,2,3. The IDL command B=INDGEN(4) creates the same array. Three pieces of information are associated with a variable: name, variable-type, data-values.

Some computer languages assign data types to variables at the beginning of the program. Some, such as Java, do not let you use a variable that has not been defined and do not let you change the type. IDL does not use type statements to define variables. They are created and defined as they are used in the program. The variable type are often changed by operations. This is done without complaint or warning. It is convenient to not have to worry about variable types, but it is also possible to introduce very subtle bugs.

You can ask IDL to tell you the name, variable-type and values of any variable. To ask about the variable A, just type HELP,A in the command window.

Listed below are some commands. At the right is the listing displayed in the output window or presented in a graphics window.

 

Construct an array of integers with 3 columns and 4 rows. Print the results.

IDL> B=INDGEN(3,4)
IDL> PRINT,B

0 1 2
3 4 5
6 7 8
9 10 11
Find the properties of the variable B by using the HELP command. IDL> HELP,B
B INT = Array[3, 4]

Construct an array T representing time over the interval 0<T<5 and then compute
Y=EXP(-T)COS(10 T) and plot the results. Make the time steps equal 100 per second.

IDL> T=FINDGEN(501)/100
IDL> Y=EXP(-T)*COS(10*T)
IDL> PLOT,T,Y
Examine the variables T and Y IDL> HELP,T
IDL> HELP,Y
T FLOAT = Array[501]
Y FLOAT = Array[501]

The center column contains commands that were given at the IDL prompt in the command window. These are all system functions and procedures. Let's look at some of them.

B=INDGEN(3,4)is a statement using the function named INDGEN. It generates an array with 3 columns and 4 rows filled with integers. The number put into each cell is the cell index. Note that the index starts at zero. A function returns a value that can be assigned to a variable. In this case, the array is assigned to a variable named B. INDGEN can generate arrays up to eight dimensions.

PRINT,B is a statement using the procedure PRINT. Procedures do not return a value that can be assigned with =. In this case, PRINT writes out the values in the array B.

T=FINDGEN(501)/100 is a statement based on the function FINDGEN and the division operator. As seen in the HELP,T statement below, the array contains 501 floating point values. FINDGEN returns the array [0.0,1.0,...,500.0]. The division operator causes each value to be divided by 100. T contains the values [0.0,0.01,0.02, ..., 4.99, 5.0]. Note that the / operator knows how to divide all of the array elements by 100.

Y=EXP(-T)*COS(10*T)uses two functions and the multiplication operator (twice). In the argument of COS, the array T is multiplied by the scalar 10. This scales the T array up by 10. The COS function then computes the cosines of all of the array elements and returns an array of length 501. The EXP function also returns an array of length 501. The * operator then multiplies the corresponding array values and returns the result as a new array that is then assigned to the variable Y.

PLOT,T,Y produces the graph shown in the table. It is a procedure that uses the first variable as the horizontal values and the second variable as the vertical variables and connects the points with short line segments. PLOT has many more parameters that can be set, and you might want to read about them in IDL Online Help.