After issuing "idlde" from the UNIX command line, you will get a window which looks like the following screen capture. Note the three panes in the window, and the menu and tool bars at the top. The top pane is for entering and editing programs, the middle displays results, and the lowest lists defined variables. Also note the "IDL>" prompt at the very bottom. This is where you enter IDL commands interactively. I've entered "a=467.3" and am about to hit enter.
Important: IDL has extensive online help, including complete manuals. You can get these through the "Help" menu at the upper right corner. Use this!

When I hit return, I get the command echoed in the middle pane, and the variable "a" appears in the lowest pane. Note that upper or lower case does not matter in IDL.

Say I wanted to use IDL as a fancy calculator, using it to compute the exponential of "a/400". I'd have to enter the "print" statement you see echoed below from the IDL prompt line.

Now let's do a simple program, to calculate a tangent (IDL knows how to do this anyway, but it's a good example). Go into the program pane and enter the following. Note that each statement is on a different line. Also note that you should use indentation to improve readability. Save the program either from the menu or by clicking on the highlighted icon in the toolbar.

Now add some comments to the program. Always do this! Help people (very often, your future self) understand what you've done. IDL ignores everything between a semicolon and the end of a line.

Let's run the program. You can hit the compile and run buttons from the toolbar, and that'll do it. The results appear in the middle pane.

It's a nuisance to have to go and edit and recompile the program every time we want to get the tangent of a different x value. So modify the program to ask the user to enter x values:

Here's how it works. Once tangent is run, at the bottom line where interactive commands are issued, the user-supplied prompt appears and a value for the variable can be entered:

Here is what IDL prints in the middle pane after the value for x is entered:

An even better way to handle all this is to write not a program or procedure (hence the "pro"), but a function. Then you can use the new function just like IDL's built-in functions like sin(x). Here's how:

After compiling, you say things like "print, tangent(0.4)" from the IDL command line. In this example, I use "!pi" which is IDL's pre-defined value for pi.

Done.
| Taner Edis | Home |
| Last modified: October 25, 2006 |   |