IDL Basics


The Official Introduction To (PDF)

*

The first thing to be aware of is that there are three different 'types' of data, i.e.
integers: 0, 1 2, 1000, 99920
real (or 'floating-point') numbers:    1.2332,   2.0
character (or 'string'):    'a', 'December', '1.2'

We set variables to equal numbers or characters
x=2    (integer)
x=2.0   (real)
x='June'   (character)

Scientific notation
    1e6 = 1,000,000
    Stefan_Boltzmann_Constant = 5.67e-8

Trig functions
x=sin(y)    ; angles default to radians

Raise something to a power
x = y^2
x = y^4.5
F = 5.6e-8*T^4

Exponential functions
    y=exp(x)    ; i.e. y=ex
    Expressing Beer’s Law: s_in_z=s0*exp(-1.*k*z)


Arrays

Arrays contain data, usually more than one value. We can define arrays of different 'type'
    x=intarr(n), where n is how many elements, in this case, in a 1-dimensional integer array
    x=fltarr(n), where n is how many elements, in this case, in a 1-dimensional real array
    x=strarr(n), where n is how many elements, in this case, in a 1-dimensional string array

Arrays can have more than 1 dimension

    x=fltarr(10,20)


Subscripts

IDL counts from zero, not one. When refering to an array subsrcipt, the first element is the zeroth element. e.g. print,x(0) to print the first value stored in an array called x.

Procedures

if using procedures, the main program body needs to be named after the IDL file name, e.g. convert.pro needs 'pro convert' at the top of the program in the editor

Running programs

Edit the code using the text editor in IDL. To execute the program, use the following, which can be done using “shortcut keys”, i.e. ‘save’ (CNTL-s), ‘compile’ (SHIFT-F5), then ‘run’ (F5) are the 3 things to do each time you modify the code. If you encounter a runtime error, it may help to reset using: CNTL-R.


return to main page