IDL Language Elements

The basic language elements of IDL are a bit different from other programming languages such as FORTRAN, C, and C++. These elements include dynamic data types, array operations, positional parameters (arguments), keywords, and automatic compilation. The following sections introduce the basics of these IDL language elements, along with how to avoid naming conflicts.

Variables and Data Types

IDL is different from other languages that require programmers to specifically designate a particular data type for each variable. IDL interprets variable types by their usage. This "loose" or dynamic data typing gives IDL flexibility and the ability to redefine variable data types at the command line or within programs. With this flexibility comes the need to keep track of the data types. IDL's built-in HELP procedure is an easy tool to use to return the data type of any variable, as shown in the following command-line example:

IDL> varvalue = 7.99 
IDL> help, varvalue 
VARVALUE        FLOAT     =       7.99000 

Another example shows how the same variable is redefined as another data type:

IDL> varvalue = '7.99' 
IDL> help, varvalue 
VARVALUE        STRING    = '7.99' 

Notice that since the variable value is within single quotes, IDL interprets it as a string. IDL does not hold the previous value of the variable in memory, so it can be changed at any time.

The three valid IDL variable organizations are scalars, arrays, and structures:

There are 16 variable types in IDL, which are shown in the following table:

IDL Variable Types

Undefined

Structure

Unsigned byte

Double precision complex

16-bit integer

Pointer heap variable

32-bit integer

Object reference heap variable

Single precision floating

Unsigned 16-bit integer

Double precision floating

Unsigned 32-bit integer

Single precision complex

64-bit integer

String

Unsigned 64-bit integer

Arguments

Arguments in IDL are positional parameters that pass information to a routine. In other words, each argument must be given in the order specified by the syntax of the routine. Some arguments are required, while others are optional, depending on the routine.

For example, the IDL system routine PLOT has two arguments: x and y. The arguments must be given in the correct order or the resulting plot's axes will be incorrect. If the y argument is not given, the routine plots y as a function of x, as shown in the following example:

IPLOT, EXP(FINDGEN(10))

The result of this command is the following plot:

program_plot.gif

Keywords

Keywords are optional parameters that consist of keyword-value pairs. They can be passed to a routine in any order. If a keyword is not specified, the default value of that keyword is passed to the routine. A routine may have many available keywords to choose from. You can use as many or as few as you need.

Continuing with the PLOT example, we adds keywords to label the x and y axes:

IPLOT, EXP(FINDGEN(10)), XTITLE='Time', YTITLE='Velocity'


program_plot2.gif

Automatic Compilation

IDL compiles routines any time it encounters a routine name, whether it is typed at the command line or called from another routine. If the routine is already in IDL's memory, IDL runs it. If the routine is not in memory, IDL searches each directory in the path definition for (filename.pro) and automatically compiles it. (For more on the IDL path, see IDL_PATH.)

Note
IDL routines all have specific names, which can conflict with user-written routines if those routines have the same name. When IDL encounters this conflict, the automatic compilation mechanism ignores the user-written routine. For more information, see Advice for Library Authors.

Code Written in Other Programming Languages

IDL allows you to incorporate routines written in other programming languages using the following methods: