2. • Interactive tool, but also full programming language on its own:
• structured programming (functions and procedures)
• array oriented:
• operations on arrays faster and easier than doing a loop
• many numeric types; strings
• flow control constructs
• Semi automatically quasi compiled
• garbage collection to reclaim memory
• program structure workarounds: system variables, common blocks
• structures, objects
• Three graphic models in IDL 8.x
• direct graphics: 2d, 3d
• plots (contours, images, surface plots, points, volumes),
• cursor interaction, lots of ways to customize IDL> plot, x, y
• direct graphics plot objects: IDL> p = plot(x,y)
• object graphics (more advanced, not really for individual use)
IDL features
4. IDL command line
• Enter commands directly at the IDL prompt
• Add a $ or &$ at the end of each line of text for multi-line command.
Batch files
• Can run a text file containing a list of commands
• Execute by entering @filename at the IDL prompt
Script files
• Very similar to a batch file
• A text file containing a list of commands
• Execute by entering .run filename
• Script file must end with the end command on its last line
• Handles multi-line commands without entering $
• Procedures and Functions
IDL Interface
5. Constants, variables, math
● Number types
– a = 1 integer: 16 bits, 32767 to +32767
– a = 1L long: 32 bits, 2147483647L to 2147483647L
– a = 1.0 float: 32 bits, sig decimal digits, magnitude 1e38 to 1e38
– a = 1.d double: 64 bits, ~16 decimal digits, magnitude 1d308
● Math operators + * / ^ mod < >
– Watch out for integer arithmetic: 2 / 3 is zero
● Math functions exp alog alog10 ...
● IDL's variables are dynamic
– IDL> a = 30
– IDL> b = a
– IDL> a = “Al Capone”
6. IDL as a calculator
Some examples:
IDL> print, 13 * 15
IDL> print, 23. / 2
IDL> print, 6.626e27 * 3.29e15
IDL> print, exp(10.)
IDL> print, alog10(30.0)
A couple ways to do a sum:
IDL> print, 1 + 2 + 3 + 4 + 5
IDL> print, total( [ 1, 2, 3, 4, 5 ] )
7. Arrays
● Array = bunch of numbers treated as single expression
● To make arrays:
x = [0,3,7,2]
intarr or indgen for integer
fltarr or findgen for float
intarr form gives array filled with zeros;
indgen form gives [0,1,2,3...]
● Can use operators on arrays
a = [1,3,5] b = [4,6,8] c = a + b
● Important: first element is a[0] not a[1]
● Many useful array related routines: min max where sort
● Multidimensional arrays too
8. More on arrays
● Basic subscripting
– print, a[0:2] first three elements
– print, a[3:*] fourth to end
– print, a[*,0] all elements of a's first row
– print, a[1,*] all elements of a's second column
● Subscripting with variables
– a = findgen(10)+10
– set = [3,4,5]
– print, a[set]
● The all important “where” function
– set = where(a gt 4.5)
9. ● Basic plot: given arrays x, y
plot, x, y
● Many aspects of plots customized by keywords
plot, sin(d/10), psym=4, ytitle='Response (keV)'
● Shorthand for log/linear axes:
plot_io, x, y
plot_oi, x, y
plot_oo, x, y
● Shorthand for overplotting
oplot, x, y or oplot, x, y, psym=5, col=!blue
● Plots written to “devices”
– X for screen plot
– PS for postscript file
– help, /device tells which device we're in
– many device details customizable: color options, paper size...
2D plotting
10. Functions and Procedures
● Many functions and procedures built in but you can add your own
● Using these promotes code reuse,helps debugging, saves sanity of
yourself and others
● Functions:
– Declare this way: function circumference, radius
– Invoke this way: c = circumference(radius)
– Must return a value return, 2.*!dpi*radius
● Procedures:
– Declare this way: pro dostuff, a
– Invoke this way: dostuff, a
– Don't return a value (but can return things through argument list)
● Either one can modify any variables you send as arguments
11. Statement Description/Usage
IF If a statement is true – execute a statement
FOR Repeat statements for a specified number of times
WHILE Repeat statements while a condition is true
RETURN Return a variable from a function or procedure
CASE Select an option (case) form a list depending on the input
SWITCH Return to a case in a list of cases
REPEAT Repeat statements until a condition is true
GOTO Go to a certain label
BREAK Break out of the loop or statement
CONTINUE Continue the program and allow the next iteration of the loop
IDL few statements