Monitoring Variable Values

When execution halts, there are several ways to see the values of program variables. These include:

Showing Variable Values During Execution

When execution stops you can query the values of current variables in the program scope using the PRINT and HELP routines. For instance, suppose you have created the following program:

FUNCTION hello_who, who

RETURN, 'Hello ' + who

END

 

PRO hello_main

name = ''

READ, name, PROMPT='Enter Name: '

str = HELLO_WHO(name)

PRINT, str

END

Place a breakpoint on the PRINT, str line and then compile and run the program. Enter a name at the IDL command line when prompted. When execution halts, return the value of the name variable by entering,

PRINT, name

The Console view shows the name you have entered.

Return information about the str variable by entering:

HELP, str

The Console view shows the variable name, data type and value. This information is also available in the Variables view, described in the following section.

Tip: You can also place PRINT and HELP statements in your program to see variable values without pausing program execution. As these statements are encountered, values are printed to the Console.

The Variables View

The Variables view window displays the values of variables in the current execution context. If the calling context changes during execution (as when stepping into a procedure or function) the variable table is replaced with a table appropriate to the new context.

Disappearing Variables

IDL users may find that all their variables have seemingly disappeared after an error occurs inside a procedure or function. The misunderstood subtlety is that after the error occurs, IDL’s context is inside the called procedure, not in the main level. All variables in procedures and functions, with the exception of parameters and common variables, are local in scope. Typing RETURN or RETALL will make the lost variables reappear.

RETALL is best suited for use when an error is detected in a procedure and it is desired to return immediately to the main program level despite nested procedure calls. RETALL issues RETURN commands until the main program level is reached.

The HELP command can be used to see the current call stack (i.e., which program unit IDL is in and which program unit called it). For more information, see HELP.