Title: Basic IDL Commands
1Basic IDL Commands
2Objective
- Quick Tour of IDL
- Writing IDL Programs
3Before we start
- source rvrpci/.simg726.rc
- typescript
- set history100
- AT THE END OF THE UNIX SESSION,
- DONT FORGET TO TYPE
- D
4Before we END
- AT THE END OF THE UNIX SESSION,
- DONT FORGET TO TYPE
- D
- You now have file called typescript which
contains a log of your UNIX session
5Starting IDL in UNIX
- To start command line interface IDL environment
- idl
- To start graphical interface IDL environment
- idlde
6IDL Help
- MOST IMPORTANT IDL COMMAND OF ALL
- IDLgt ?
-
7IDL Help Window
8Other IDL Help Facilities
- IDLgt doc_library,moment
- Allows specially formatted code comments to be
viewed without having to view the source code
9General IDL Information
- N.B. Platform specific limitation
- UNIX
- File name conflict between lower and upper case
characters - e.g. addnum.pro vs. AddNum.pro
- Recommend use of strictly lowercase file names
10IDL Character Set
- IDL is not case sensitive
- Commands and arguments are delimited by comas.
- e.g. IDLgt print, a
- Comments are started by a semicolon ()
- e.g. IDLgt This is a comment
- Command options are set using a backslash (/)
- e.g. IDLgt tv, a, /order
11Other IDL Characters
- System variables are started with an exclamation
point (!) - e.g. IDLgt print, !PI
- e.g. IDLgt y sin( x!DTOR )
- Command line continuation with
- e.g. IDLgt print, 180 /
- !PI
12Other IDL Characters
- Multiple IDL commands can be separated by the
symbol - e.g. IDLgt a0.0 b1.0
- UNIX Command execution
- e.g. IDLgt ls -la
13Journal Facility of IDL
- The journal command allows you to record all IDL
activity during a particular session - IDLgt journal, sequence.pro
- IDLgt print, 35
- IDLgt journal
14sequence.pro
IDL Version 3.6.1a (MacOS Macintosh) Journal
File for Rolando Raqueño_at_green Working
directory Raqueño's Hard DriveApplicationsENVI
Date Tue Sep 17 005618 1996 print,35
15
15Sample Commands
- Some sample command
- IDLgt print,35
- IDLgt print,SysTime()
- IDLgt num 512
- IDLgt help,num
- NUM INT 60
- IDLgt print,num
- 60
16Creating an Array
- Some sample command
- IDLgt num fltarr(40)
- IDLgt help,num
- NUM FLOAT Array(40)
- IDLgt print,num
- 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 - 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 - 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 - 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 - 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 - 0.00000 0.00000 0.00000 0.00000
0.00000
17Creating an Indexed Array
- Some sample command
- IDLgt for i0,39 do num(i)i
- IDLgt help,num
- NUM FLOAT Array(40)
- IDLgt print,num
- 0.00000 1.00000 2.00000 3.00000
4.00000 5.00000 6.00000 - 7.00000 8.00000 9.00000 10.0000
11.0000 12.0000 13.0000 - 14.0000 15.0000 16.0000 17.0000
18.0000 19.0000 20.0000 - 21.0000 22.0000 23.0000 24.0000
25.0000 26.0000 27.0000 - 28.0000 29.0000 30.0000 31.0000
32.0000 33.0000 34.0000 - 35.0000 36.0000 37.0000 38.0000
39.0000
18Shortcut Creating Indexed Array
- Some sample command
- IDLgt num findgen(40)
- IDLgt help,num
- NUM FLOAT Array(40)
- IDLgt print,num
- 0.00000 1.00000 2.00000 3.00000
4.00000 5.00000 6.00000 - 7.00000 8.00000 9.00000 10.0000
11.0000 12.0000 13.0000 - 14.0000 15.0000 16.0000 17.0000
18.0000 19.0000 20.0000 - 21.0000 22.0000 23.0000 24.0000
25.0000 26.0000 27.0000 - 28.0000 29.0000 30.0000 31.0000
32.0000 33.0000 34.0000 - 35.0000 36.0000 37.0000 38.0000
39.0000
19Indexed Array Example
- Some sample command
- IDLgt num findgen(40)10
- IDLgt print,num
- 0.00000 10.0000 20.0000 30.0000
40.0000 50.0000 60.0000 - 70.0000 80.0000 90.0000 100.000
110.000 120.000 130.000 - 140.000 150.000 160.000 170.000
180.000 190.000 200.000 - 210.000 220.000 230.000 240.000
250.000 260.000 270.000 - 280.000 290.000 300.000 310.000
320.000 330.000 340.000 - 350.000 360.000 370.000 380.000
390.000
20Indexed Array Example
- Some sample command
- IDLgt num findgen(40)10-195
- IDLgt print,num
- -195.000 -185.000 -175.000 -165.000
-155.000 -145.000 -135.000 - -125.000 -115.000 -105.000 -95.0000
-85.0000 -75.0000 -65.0000 - -55.0000 -45.0000 -35.0000 -25.0000
-15.0000 -5.00000 5.00000 - 15.0000 25.0000 35.0000 45.0000
55.0000 65.0000 75.0000 - 85.0000 95.0000 105.000 115.000
125.000 135.000 145.000 - 155.000 165.000 175.000 185.000
195.000 - In general you will be using a linear form
- ymxb
21Extracting Array Subset
- Some sample command
- IDLgt num1 num(036)
- IDLgt print,num1
- -195.000 -185.000 -175.000 -165.000
-155.000 -145.000 -135.000 - -125.000 -115.000 -105.000 -95.0000
-85.0000 -75.0000 -65.0000 - -55.0000 -45.0000 -35.0000 -25.0000
-15.0000 -5.00000 5.00000 - 15.0000 25.0000 35.0000 45.0000
55.0000 65.0000 75.0000 - 85.0000 95.0000 105.000 115.000
125.000 135.000 145.000 - 155.000 165.000
- IDLgt help,num1
- NUM1 FLOAT Array(37)
22Scalar Operation on Arrays
- Some sample commands
- IDLgt num findgen(37)10
- IDLgt print,num
- 0.00000 10.0000 20.0000 30.0000
40.0000 50.0000 60.0000 - 70.0000 80.0000 90.0000 100.000
110.000 120.000 130.000 - 140.000 150.000 160.000 170.000
180.000 190.000 200.000 - 210.000 220.000 230.000 240.000
250.000 260.000 270.000 - 280.000 290.000 300.000 310.000
320.000 330.000 340.000 - 350.000 360.000
- IDLgt help,num
- NUM FLOAT Array(37)
23Two-Dimensional Plotting
- Displaying Two-Dimensional Graphics
- IDLgt line Sin(num !DtoR)
- IDLgt plot,line
24Two-Dimensional Plotting
- Displaying Two-Dimensional Graphics
- IDLgt plot,line IDLgt plot,num,line
25Two-Dimensional Plotting Options
- IDLgt plot,num,line,/Psym
26Two-Dimensional Plotting Options
- IDLgt plot,num,line,Psym1
27Other Plotting Options
- IDLgt plot,num,line,linestyle1
28Labeling IDL Plots
- IDLgt plot,num,line,xrange0,360,
- ytitle'Sin(x)',Title'Sine Plot'
29Other Plot Facilities
- IDLgt plot,num,line,xrange0,360,
- ytitle'Sin(x)',Title'Sine Plot'
- IDLgt plots,0,360,0,0
30Polygon Filling
- IDLgt loadct, 5
- IDLgt polyfill,num(018),line(018),color120
- IDLgt polyfill,num(1836),line(1836),color50
31Data File Inputs
- Copy the following files from
- rvrpci/pub/IDL/training
- surface.dat
- ctscan.dat
32Three-Dimensional Plotting
- Displaying Three-Dimensional Graphics
- To get the data into IDL, you will need to open a
file and read it into an array using the
following commands (N.B. this is specific for
this particular data set) - IDLgt filesurface.dat
- IDLgt openr,lun,file,/get_lun
- IDLgt peakfltarr(40,40)
- IDLgt readf,lun,peak
- IDLgt free_lun, lun
33Surface Plots
- Displaying Three-Dimensional Graphics
- IDLgt print, max(peak), min(peak)
- IDLgt surface,peak
34Surface Plots
- IDLgt x findgen(40)2.5 yfindgen(40)50
- IDLgt surface,peak,x,y
35Color Look-up Tables
- The following command lets you view the current
colors loaded into the color look-up tables - IDLgt cindex
36Background/Foreground Colors
- The following surface command lets you manipulate
the background and foreground colors - IDLgtsurface,peak,background200,color45,
- title'Surface Projection',charsize2.0
37Shaded Surface Plotting
38Draping Data Over a Surface
- We can drape a given surface over another one by
the following command (we read in the data snow
the same manner as peak) - IDLgtshade_surf,peak,
- shadesnow
39Surface Plot Colored by Altitude
- We can generate a simple elevation color map.
- IDLgt shade_surf, peak, shadebytscl(peak)
40Simple Contour Plots
- We can generate a simple contour map.
- IDLgt contour,peak
41Contour Plots Spacing
- We can generate a simple contour map and adjust
spacing. - IDLgt contour, peak, nlevels10
42Contour Plots Labelling
- We can generate a simple contour map and label
them - IDLgt contour, peak, nlevels10, /follow
43Contour Plots Spacing Adjustment
- We can generate a simple contour map and adjust
spacing along with line styles. - IDLgt contour, peak, nlevels10, c_linestyle
indgen(5)
44Colored Contour Plots
- We can generate a simple contour map and adjust
spacing along with line color. - IDLgt contour, peak, nlevels10, c_colors
indgen(5)2080
45Images Data
- Displaying Image Data
- You can read in image data in a manner similar to
other forms of two-dimensional data. You will
need to ascertain whether the data is an ASCII
file or a binary file - IDLgt openr, lun,ctscan.dat,/get_lun
- IDLgt scanbytarr(256,256)
- IDLgt readu, lun, scan
- IDLgt free_lun, lun
46Image Data
- Displaying Image Data
- IDLgt window, /free, xsize256, ysize256
- IDLgt tvscl, scan
47Image Data
- Displaying Image Data
- IDLgt window, /free, xsize256, ysize256
- IDLgt tvscl, scan IDLgt tvscl,hist_equal(scan)
48Image Processing
- Displaying Image Data
- IDLgt window, /free, xsize256, ysize256
- IDLgt tvscl, scan IDLgt tvscl, sobel(scan)
49XLOADCT Routine
- Displaying Image Data
- IDLgt xloadct
- IDLgt tvscl, scan
50Writing IDL Programs
51General Form of an IDL Program
- Parts of an IDL program
- pro program_name , arg1, arg2, ..., argn
- IDL statement 1
- IDL statement 2
- .
- .
- .
- IDL statement n
- end
52Compiling an IDL Program
- Create a program to take celsius arguments and
print out fahrenheit values - pro celsius_to_fahrenheit, celsius
- print, 9/5celsius32
- end
- To compile
- IDLgt .compile celsius_to_fahrenheit.pro
53Executing an IDL Program
- To use the program in scalar mode
- IDLgt c 100.0
- IDLgt celsius_to_fahrenheit, c
- To use the program in array mode
- IDLgt c findgen(201)/2
- IDLgt celsius_to_fahrenheit, c
54General Form of an IDL Function
- Parts of an IDL function
- function program_name , arg1, arg2, ..., argn
- IDL statement 1
- IDL statement 2
- .
- .
- .
- IDL statement n
- return, answer
- end
55Compiling an IDL Function
- Create a function to take celsius arguments and
print out fahrenheit values - function celsius_to_fahrenheit, celsius
- answer9/5celsius32
- return, answer
- end
- To compile
- IDLgt .compile celsius_to_fahrenheit.pro
56Executing an IDL Function
- To use the program
- IDLgt c findgen(201)/2
- IDLgt f celsius_to_fahrenheit(c)
- IDLgt print, f
- IDLgt plot, c, f
- Equivalently
- IDLgt print, celsius_to_fahrenheit(c)
- IDLgt plot, c, celsius_to_fahrenheit(c)
57Program Designprogram file vs. function file
- Use functions in case of mathematical functions
to allow composition of functions - IDLgt kcelsius_to_kelvin(fahrenheit_to_celsius(f))
- Use program file in case of process not requiring
the return of data - IDLgt write_to_file,temperature.dat,k
58Parameter Passing in IDL
- IDL passes parameters into functions and programs
by reference - This means parameters can be modified through
side effect - pro celsius_to_fahrenheit, celsius
- celsius 9/5celsius32
- end
59Problems with Side Effect Parameter Passing
- IDLgt a32.0
- IDLgt celsius_to_fahrenheit,a
- Compiled module CELSIUS_TO_FAHRENHEIT.
- IDLgt print,a
- 64.0000
60A Debugging Exercise
- The IDL function and program examples
celsius_to_fahrenheit all compile, but generate
incorrect answers in some cases. - This is left as a debugging exercise
61Hints for Statistics Problem
- Study the IDL functions
- n_elements()
- size()
- Try to reuse as many of the functions as
possible. - Do not be concerned with efficiency at this point.