Transcript Document

Interactive Data Language
(IDL)
Margit Haberreiter
([email protected])
LASP, room 135
Acknowledgement: Marty Snow
•
•
•
•
•
•
•
Outline
What is IDL?
Basic Syntax
Functions, Procedures, and Library
Reading & Writing
Plotting & Printing
Image Processing
And Stuff….
June 11, 2009
IDL for REU students
Margit Haberreiter
2/72
Pro test
Save it as test.pro
.compile filename
filename
June 11, 2009
IDL for REU students
Margit Haberreiter
3/72
Interactive Data Language
• IDL was born here at LASP
• Very popular among scientists:
– Handles arrays of data easily (spectra, time series,
images, etc.)
– Easy to learn
– Portable
– Large existing user library
• Online Help – type “?” at prompt
• Type help at prompt for contents of
variables
• Interactive or Compiled, your choice!
June 11, 2009
IDL for REU students
Margit Haberreiter
4/72
Data Types
•
•
•
•
•
•
Integer (and Long Integer)
Floating Point (and Double Precision)
String
Structure
Pointer
Also, complex, unsigned integers, etc.
IDL is “dynamically typed” which means a variable can be defined as one
type, and then be changed to another within the same program unit.
June 11, 2009
IDL for REU students
Margit Haberreiter
5/72
Scalars, Vectors, Arrays
Problem 1
• Scalar
– 42
– ‘help!’
a=5 & b=0. & c=0.d
• Vector
– [1,2,3,5]
– [‘red’,’blue’,’happy’,’Burma Shave’]
• Array
– Up to 8 dimensions
June 11, 2009
Definition of arrays
arr1=intarr(3)
arr2=fltarr(2,a)
arr3=dblarr(a,b,c,d…)
arr4=strarr(11)
IDL for REU students
Margit Haberreiter
6/72
Structures - Problem 2
• Can hold mixed data types
– S={day:0,time:0d0,label:’ ‘}
– S.day=5
– S.label=‘happy time’
“tag A, B, C”
• Can make arrays of structures
– S2=replicate({time:0d0,label:’’,values:fltarr(100)},n_obs)
– S2[4].values=findgen(100)
• Names or Numbers
– S2.time is equivalent to S2.(0)
June 11, 2009
IDL for REU students
Margit Haberreiter
7/72
Rules of the Road
•
•
•
•
•
Always start counting at zero.
For help at any time, type help.
Case Insensitive (EXC: filenames).
Odd is true, Even or Zero is false.
An array of length 1 is not the same as a
scalar. But you can reform it.
June 11, 2009
IDL for REU students
Margit Haberreiter
8/72
Squiggly or Square?
• Subscripting variables -- [] square
• Parameters of a function – () round
• Definition of a structure – {} curly
IDL is lax about enforcing these rules, but it is to your benefit to follow them.
Example:
a=exp[5] ;6th element of variable “exp”
a=exp(5) ;e^5
You might have named a variable the same name as a library function!
June 11, 2009
IDL for REU students
Margit Haberreiter
9/72
Subscripting - Problem 3
•
•
•
•
•
•
z=a[5]
z=a[0:2]
z=a[3:*]
mask=[5,6,7,8,9] & z=a[mask]
Range=where(mask gt 2 and mask le 4)
a=indgen(10)
Mask2=mask(range) z=a[5]
z=a[0:2]
z=a[3:*]
mask=[5,6,7,8,9] & z=a[mask]
Range=where((mask gt 6) and (mask
le 8))
Mask2=mask(range)
June 11, 2009
IDL for REU students
Margit Haberreiter
10/72
The Size of Arrays
• Size(x)
• n_elements returns the number of elements
in an array (vector, scalar).
• An undefined variable has zero elements.
• Often takes the place of size().
• Used to check if user has supplied
parameters
• Used to index loops.
June 11, 2009
IDL for REU students
Margit Haberreiter
11/72
Basic IDL Syntax
Problem 4
a=‘Hello World’
print,a
;This is a comment
a=5;dynamic data types
b=4.5*findgen(100)
z=a+$ ;continuation
sqrt(b)
June 11, 2009
IDL for REU students
Margit Haberreiter
12/72
Operators
• Arithmetic
–
–
–
–
–
–
• Boolean Logic
+
*
/
^
mod
• Min/Max
– #
– ##
June 11, 2009
and
not
or
xor
–
–
–
–
–
–
eq (a=b)
ge (ab)
gt (ab)
le (ab)
lt (ab)
ne (ab)
• Relational Operators
– < (a<b is the lesser)
– > (a>b is the greater)
• Matrix Multiply
–
–
–
–
IDL for REU students
Margit Haberreiter
Note that you can’t use any of
these letter combinations as
variable names!
13/72
FOR loop
for variable=init,limit[,increment] do statement
for i=0,100 do print,i,vector[i]
for variable=init,limit[,increment] do begin
statements
endfor
Loops in IDL execute slowly (relatively
speaking), so try to use something
else, like where.
June 11, 2009
IDL for REU students
Margit Haberreiter
14/72
As IF…. Problem 5
if expression then statement
if expression then statement else statement2
if expression then begin
statements
endif else begin
statements
endelse
Good programming style 
avoid hardcoded numbers in
procedures
June 11, 2009
for x=0,5 do begin
if x gt 5 then begin
z=dblarr(10,10)
z=z+.1
z[3,2]=1.
endif else begin
z=dblarr(10)
z[x]=!pi
endelse
endfor
IDL for REU students
Margit Haberreiter
15/72
meanWHILE
while expression do statement
while expression do begin
statements
endwhile
June 11, 2009
IDL for REU students
Margit Haberreiter
16/72
just in CASE
case expression of
expression1: statement
expression2: begin
statements
end
expression3: statement
else: statement
endcase
June 11, 2009
Example:
x=3
CASE x OF
1: PRINT,
2: PRINT,
3: PRINT,
4: PRINT,
'one'
'two'
'three'
'four'
ENDCASE
IDL for REU students
Margit Haberreiter
17/72
Other Flow Control Statements
• STOP – excellent way to debug (.con or .c to continue)
IDL Help: This example illustrates how, unlike CASE,
• GOTO
SWITCH executes the first matching statement and
– goto,label
– label:
•
•
•
•
any following statements in the SWITCH block:
x=2
SWITCH x OF
1: PRINT,
2: PRINT,
3: PRINT,
4: PRINT,
ENDSWITCH
'one'
SWITCH
'two'
'three'
CONTINUE
'four'
BREAK
MESSAGE – stops program and prints message
June 11, 2009
IDL for REU students
Margit Haberreiter
18/72
Procedures and Functions
• A list of IDL statements that could have been
entered at the command prompt.
• Contained in separate file or files.
– Compiled automatically if files are properly named.
Filename matches procedure with a .pro extension.
USE LOWER CASE!
– All procedures compiled from start of file but
stops when procedure name matches file name.
– Environmental variables define directories that
IDL will automatically search. USER LIBRARY
June 11, 2009
IDL for REU students
Margit Haberreiter
19/72
Compile and Run
• Type procedure name at command prompt to
run it. IDL will search for an appropriately
named file and automatically compile and run
the procedure.
• .r or .compile will compile the procedure, but
not run it.
• IDL will compile all procedures in file until it
hits the one matching the file name, then it
will stop. Put the named procedure last in the
file.
June 11, 2009
IDL for REU students
Margit Haberreiter
20/72
Simple Procedure
pro simpleprocedure,a,b,c
c=a+b
end
To run it, type:
simpleprocedure,var1,var2,result
print,result
June 11, 2009
IDL for REU students
Margit Haberreiter
21/72
Simple Function
function eve,number
if number mod 2 eq 0 then return,0
return,1
end
To run it, type:
result=eve(var)
print,eve(var)
print, ‘The result is ‘, result
June 11, 2009
IDL for REU students
Margit Haberreiter
22/72
What’s the difference?
Not much.
Use a function to get a value that you’ll use
right away (like an expression).
EXAMPLE:
simpleprocedure,eve(0),eve(5),result
Use a procedure when you return multiple
results and don’t want to just wrap them
together in a structure or array.
June 11, 2009
IDL for REU students
Margit Haberreiter
23/72
Parameters and Keywords
Problem 7
pro proc2,input1,input2,result,doplot=doplot
if n_elements(doplot) eq 0 then doplot=0
result=input1*sin(input2/!pi)
if doplot gt 0 then begin
set_plot,'win'
!P.CHARSIZE=3.
; system setting
!P.MULTI=[0,1,3]
; system setting
plot,input2,result,psym=-4
plot,input1
Order of Parameters is critical.
plot,sin(input2/!pi)
Order of Keywords is irrelevant.
endif
end
Keywords can normally be abbreviated
xtit instead of xtitle
xs instead of xstyle
June 11, 2009
IDL for REU students
Margit Haberreiter
24/72
Variables: Global or Local?
Problem 8
Variables are local….sort of (Attention!!)
A procedure can modify any of its
parameters, which will change the
variable in the calling procedure.
pro proc1
v=0
print,v
proc3,v
print,v
end
June 11, 2009
pro proc3,var2
var2=var2+1
end
IDL for REU students
Margit Haberreiter
25/72
Error and stop
• If the IDL interpreter hits a STOP or
encounters an error, flow halts at the local
level. You can type ‘help’ to view contents of
variables and which line of code you’re at.
• To return to the top level – retall (return
all the way)
• To clear everything, type .f (full reset) or
.reset -> Attention: all variables deleted
June 11, 2009
IDL for REU students
Margit Haberreiter
26/72
Reading & Writing & Saving
• openr,openw,openu (Read, Write,
Update)
• readf,readu (Formatted, Unformatted)
• close or free_lun
• IDL save files:
– save,file=‘data.idl’,var1,var2
openr,lu,’file.txt’,/get_lun
– restore,’data.idl’
while not eof(lu) do begin
readf,lu,data
endwhile
free_lun,lu
June 11, 2009
IDL for REU students
Margit Haberreiter
27/72
Slight Gotcha…
pro wont_work
openr,lu,’file.txt’,/get_lun
data=fltarr(100)
for i=0,n_elements(data)-1 do begin
readf,lu,data[i]
endfor
free_lun,lu
end
IDL passes by value, not by
reference, so this won’t
work.
June 11, 2009
IDL for REU students
Margit Haberreiter
28/72
Slight Gotcha…
pro will_work
openr,lu,’file.txt’,/get_lun
data=fltarr(100)
i=0
while not eof(lu) do begin
readf,lu,temporary
data[i]=temporary
i=i+1; counter
endwhile
free_lun,lu
data=data[0:i-1]
end
June 11, 2009
IDL for REU students
Margit Haberreiter
IDL passes by value, so this
will make IDL happy.
29/72
Task: Read data from file
Problem 9
pro willwork,filename,data
openr,lu,filename,/get_lun
; get_lun: sets file unit number
data=fltarr(2,1000)
i=0
while not eof(lu) do begin
readf,lu,temporary1,temporary2
data[0,i]=temporary1
data[1,i]=temporary2
i=i+1
; counter
endwhile
free_lun,lu
data=data[*,0:i-1]
set_plot,'win'
!P.MULTI=0
plot,data(0,*),data(1,*),title='Data from file'
end
Run the procedure
Add a plot using a parameter (see slide 22)
June 11, 2009
IDL for REU students
Margit Haberreiter
30/72
Homework 1—LISIRD Data
• Go to http://lasp.colorado.edu/lisird and
retrieve solar Lyman alpha (121.5 nm)
data for at least two missions.
• Save data as text file.
• Write an IDL procedure to read data.
June 11, 2009
IDL for REU students
Margit Haberreiter
31/72
More on plotting…
Basic IDL Plotting Procedures
• Line plots
– plot
– oplot
– histogram
• Contour plots
– contour
• Surface plots
– surface
– shade_surf
June 11, 2009
IDL for REU students
Margit Haberreiter
32/72
Line ‘em up Problem 10
• X=FINDGEN(360)
• Y=SIN(X*!DTOR)
• PLOT, X, Y, XRANGE=[0,360], /XSTYLE, XTIT=‘X’, $
YTIT=‘Y’, TIT=‘Sample Line Plot
• Z=COS(X*!DTOR)
• OPLOT, X, Z, LINESTYLE=2
June 11, 2009
IDL for REU students
Margit Haberreiter
33/72
Adding text to plot
• X=FINDGEN(360)
• Y=SIN(X*!DTOR)
• PLOT, X, Y, XRANGE=[0,360], /XSTYLE, XTIT='X', $
YTIT='Y', TIT='Sample Line Plot'
• Z=COS(X*!DTOR)
• OPLOT, X, Z, LINES=2
• XYOUTS, 100, 0, 'cos(x)'
• XYOUTS, 190, 0, 'sin(x)'
June 11, 2009
IDL for REU students
Margit Haberreiter
34/72
Histograms
• Y=RANDOMN(SEED, 100, /NORMAL)
• H=HISTOGRAM(Y, BINSIZE=0.2, LOCATIONS=L)
• PLOT, L, H, PSYM=10 ; histogram mode
June 11, 2009
IDL for REU students
Margit Haberreiter
35/72
Graphics Keywords
•
•
•
•
•
•
change the style of the data
add a title
manipulate an axis/change tick marks
change the format of text
change coordinate systems
etc.
June 11, 2009
IDL for REU students
Margit Haberreiter
36/72
Styles and Symbols Keywords
• Symbols
• Lines
– LINESTYLE={0,1,2,3,4,5}
– THICK: change the
thickness of the line
(default is 1.0)
Value
Meaning
0
Solid
1
Dotted
2
Dash
3
Dash Dot
4
Dash Dot Dot
5
Long Dashes
June 11, 2009
Value
Meaning
1
Plus sign (+)
2
Asterisk (*)
3
Period (.)
4
Diamond
5
Triangle
6
Square
7
X
8
User defined
9
Undefined
10
Histogram mode
IDL for REU students
Margit Haberreiter
– PSYM={1,2,3,…10}
– SYMSIZE: change the size
of the symbol
– USERSYM: procedure to
define PSYM=8
– PSYM= -{1,2,3,…8}: solid line
connecting the symbols
– N.B.: PSYM=3 (period) does
NOT show up well in
postscript plots and does not
scale nicely with symsize.
Better to use PSYM=1,
SYMSIZE=.3 (or similar)

Negative value of “psym”
creates line+symbols
37/72
Titletown USA Keywords
• TITLE: place a string of text at the top of a plot
– TITLE=‘This is my title’
– TITLE_STRING=‘This is my title’
TITLE=TITLE_STRING
• SUBTITLE: place a title below the x-axis
• [XYZ]title places title on x, y, or z axis
June 11, 2009
IDL for REU students
Margit Haberreiter
38/72
Axes & Tick Mark Keywords
• To manipulate individual axes:
– Set the range:
• [XYZ]RANGE=[min, max]
– Change the axis style
• [XYZ]STYLE=number
• Multiple effects can be achieved by adding values together
– Label an axis:
• [XYZ]TITLE=string
June 11, 2009
Value
Meaning
1
Force exact axis range
2
Extend axis range
4
Suppress entire axis
8
Suppress box style axis
16
Inhibit setting y-axis minimum to
zero
IDL for REU students
Margit Haberreiter
39/72
Axes & Ticks Keywords 2
• To manipulate individual axes (cont.):
– Change the axis thickness
• [XYZ]THICK=number (default is 1.0)
• Use axis procedure to draw axes with different scales
–
–
–
–
X=FINDGEN(360)
Y=SIN(X*!DTOR)
; system variable π/180
PLOT, X, Y, XRANGE=[0,360], XSTYLE=9, XTIT='X (Degrees)'
AXIS, XAXIS=1, XRANGE=[0,2*!PI], XSTYLE=1,
XTITLE='(Radians)'
June 11, 2009
IDL for REU students
Margit Haberreiter
40/72
Clipped title
June 11, 2009
IDL for REU students
Margit Haberreiter
41/72
Fixed clipping…
plot,x,y,xstyle=9,xtit='X (degrees)',ymargin=[4,4]
June 11, 2009
IDL for REU students
Margit Haberreiter
42/72
Text Formatting Keywords
• To change the size of text
– CHARSIZE=number (default is 1.0)
• To change the thickness of the text
– CHARTHICK=number (default is 1.0)
– Or set system variable:
• !P.Charsize=3
June 11, 2009
IDL for REU students
Margit Haberreiter
43/72
Coordinate systems
• IDL has 3 coordinate systems
– DATA (default)
• Uses the range of values of the data
– DEVICE
• Uses the device (X window or Postscript device)
coordinates (i.e. pixels)
– NORMAL
• Normalized coordinates from 0 to 1 over the 3
axes
June 11, 2009
IDL for REU students
Margit Haberreiter
44/72
Adding color
• Color tables
– LOADCT[, number]
– XLOADCT (widget)
• Graphics keywords:
– BACKGROUND=number
– COLOR=number
– Number from 0 to 255, corresponding to the color
table
– color=fsc_color(‘red’) ;using library routine
• On Mac, Windows: DEVICE, DECOMPOSED=0
June 11, 2009
IDL for REU students
Margit Haberreiter
45/72
Contour
• X=FINDGEN(360)
• Z=SIN(X*!DTOR)#COS(2*X*!DTOR)
• CONTOUR, Z, NLEVELS=6, XRANGE=[0, 360], $
YRANGE=[0, 360], /XSTYLE, /YSTYLE, XTIT='X', YTIT='Y', $
TIT=‘Sample Contour Plot’
June 11, 2009
IDL for REU students
Margit Haberreiter
46/72
Surface plots (shaded surf)
• SHADE_SURF, Z, XRANGE=[0, 360], $
YRANGE=[0, 360], /XSTYLE, /YSTYLE, XTIT='X', $
YTIT='Y', TIT='Sample Surface Plot 2'
June 11, 2009
IDL for REU students
Margit Haberreiter
47/72
Colored surface
loadct,3
shade_surf,z,tit='Sample Surface Plot 3',shades=bytscl(z+1)
Bytscl translates the values of the array into a byte array from 0 to 255
June 11, 2009
IDL for REU students
Margit Haberreiter
48/72
Surface plots 2 (wire mesh)
• SURFACE, Z, XRANGE=[0, 360], $
YRANGE=[0, 360], /XSTYLE, /YSTYLE, XTIT='X', $
YTIT='Y', TIT='Sample Surface Plot 2'
June 11, 2009
IDL for REU students
Margit Haberreiter
49/72
Changing appearance of mesh
z2=rebin(z,180,180)
surface,z2
z3=rebin(z,90,90)
surface,z3
The possibilities are endless!
June 11, 2009
IDL for REU students
Margit Haberreiter
50/72
Multiple plots on a page
• !p.multi=[a,b,c]
– a: number of plots left on page
– b: number of columns
– c: number of rows
• Example:
– 6 plots per page (3x2), begin plotting in the top
left
– !p.multi=[0,3,2]
• To return to a single plot per window,
!p.multi=0
June 11, 2009
IDL for REU students
Margit Haberreiter
51/72
Making postscript files
• SET_PLOT, ‘PS’
• DEVICE, FILENAME=‘example.ps’
– , /LANDSCAPE
– , /PORTRAIT, YOFFSET=1, YSIZE=9, XSIZE=6,
/INCHES
– , /COLOR, BITS_PER_PIXEL=8
• Plotting commands
• DEVICE, /CLOSE
• SET_PLOT, ‘X’
• For Windows, SET_PLOT, ‘WIN’
June 11, 2009
IDL for REU students
Margit Haberreiter
52/72
Detailed plotting...
set_plot,'ps'
tek_color
!p.font=1
!p.color=0
!p.background=1
;!p.MULTI=[0,2,4]
!P.MULTI=0
ang = string("305B)
device,filename=fileout+'*.ps',/color,ysize=12, xsize=17,xoffset=1,yoffset=10
;*****************************************************************
plot,x1,y1,linestyle=1,/ylog,thick=6,$
tit='',CHARSIZE=1.5, xtit='!Ml!N (nm)',XCHARSIZE=1.5,$
ytit='intensity (erg s!E-1!Ncm!E-2!NHz!E-1!N)',YCHARSIZE=1.5,$
xrange=[x0,x1],xs=1, $
yrange=[y0,y1],ys=1
;*****************************************************************
; overplot
;*****************************************************************
oplot,x2,y2,linestyle=0,thick=3
legend_mh01,textarr,charsize=charsize,textcolor=colors,colors=colors,$
box=0,position=[.5,.55],/normal
xyouts,0.85,0.85,‘a‘,charsize=1.5
print,'Have a look at the plot :)'
end
June 11, 2009
IDL for REU students
Margit Haberreiter
; Angstrom symbol
; /nodata does not plot the data
; !E ->exponent; !I-> index; !N ->normal font
; !M -> mathfont, e.g. !Ml ->lambda
; label of figure panel, i.e. a, b, c, d....
53/72
Making other types of graphics
files
• Use tvread function from David
Fanning’s library www.dfanning.com
• plot,x,y
• im=tvread(/png,file=‘filename’,/nodialog)
June 11, 2009
IDL for REU students
Margit Haberreiter
54/72
Putting it all together
Homework assignment 2
• Using LISIRD, create a composite Lyman- time
series using SORCE, TIMED SEE, UARS SOLSTICE,
and SME data
– Plot each instrument as a different color
– Label each instrument
– X-axis: year
Y-axis: W/m2/nm
June 11, 2009
IDL for REU students
Margit Haberreiter
55/72
Sample Solution
June 11, 2009
IDL for REU students
Margit Haberreiter
56/72
Imaging basics
• Images in IDL are just arrays. All standard
mathematical operations are available.
• Images are usually saved in FITS format
– Header and array of integers (image)
– Use Goddard IDL Astronomy Library procedures to read
both the header and image
• Raw images must be processed before they can be
used for science. Example:
– Remove the background counts (dark)
– Correct for variations across the CCD (flatfield)
Rawim age darkim age
Correctedim age
Flatim age darkim age
June 11, 2009
IDL for REU students
Margit Haberreiter
57/72
Displaying images
• Basic IDL commands to display an array/image
– TV, image
– TVSCL, image
• Resize an image
– REBIN(image, xsize, ysize)
– xsize and ysize must be integer factors of the
original size of the image
• Add color by loading a color table
– E.g. SOHO EIT has its own color table for each
wavelength
June 11, 2009
IDL for REU students
Margit Haberreiter
58/72
and Stuff
•
•
•
•
•
•
•
•
•
where
size
histogram
string manipulation
file_search
map projections
n_elements
reading file formats (CDF, FITS, PNG, etc.)
pointers
June 11, 2009
IDL for REU students
Margit Haberreiter
59/72
Where
Use WHERE to find data values meeting
some criterion.
– good=where(data gt 0.)
– better=where(data gt 1.5 and $
time gt julday(1,1,2005))
data2=data[good] ;new variable data2
data=data[better] ;redefine variable data
June 11, 2009
IDL for REU students
Margit Haberreiter
60/72
Size
• The size function returns lots of good
information about your variable.
(dimensions, n_elements, data type, etc.)
s=size(data)
An undefined variable is a valid type, so
check for size or n_elements.
June 11, 2009
IDL for REU students
Margit Haberreiter
61/72
Histogram
• There are billions and billions of uses
for histogram.
h=histogram(data,binsize=2.5,omin=omin)
bins=findgen(n_elements(h))+omin
http://www.dfanning.com/tips/histogram_tutorial.html
June 11, 2009
IDL for REU students
Margit Haberreiter
62/72
Strings
• IDL understands regular expressions
• Concatenate strings with +
myname=‘yourname’
result=strpos(myname,‘o',0)
result=strupcase(myname)
result=strlen(myname)
strsplit, strmid, ….
June 11, 2009
IDL for REU students
Margit Haberreiter
63/72
file_search
• Retrieves a list of filenames into a
string array.
list=file_search(path+’*.idl’)
for i=0,n_elements(list)-1 do begin
restore,list[i]
plot,time,irradiance,psym=-4
endfor
All your string manipulation skills can be used to
create the list of files, of course.
dialog_pickfile is an interactive way of selecting files.
June 11, 2009
IDL for REU students
Margit Haberreiter
64/72
Plotting Data on a Map
• set up map projection
– map_set,/continents,/mercator
(mercator: cylindrical map projection)
• plot positional data on it
MAP_SET, /MERCATOR, 0, -75, 90, CENTRAL_AZIMUTH=90, $
/ISOTROPIC, LIMIT= [32,-130, 70,-86, -5,-34, -58, -67], $
/GRID, LATDEL=10, LONDEL=10, /CONTINENTS, $
TITLE = 'Transverse Mercator‘
Other options: /ROBINSON, /ORTHOGRAPHIC, … ?map_set
June 11, 2009
IDL for REU students
Margit Haberreiter
65/72
Standard Data Formats
• IDL save files: restore, filename
• FITS files: d=mrdfits(file,exten,head)
• netCDF: read_netcdf,file,data,status
June 11, 2009
IDL for REU students
Margit Haberreiter
66/72
Pointers
• Variable contains a reference to data in
memory, instead of containing the data.
• Needs to be de-referenced to get the
data.
get_sorce_telemetry,data,info,jd1,jd2,$
externalelement=‘solstice_a’,$
itemname=[‘grat_pos’,’detector_a’,’int_time’]
gp=(*data.(0)).science
June 11, 2009
IDL for REU students
Margit Haberreiter
67/72
User Library Routines
•
•
•
•
•
•
legend
pause
psymdot
which or file_which
fsc_color
rainbow
June 11, 2009
IDL for REU students
Margit Haberreiter
68/72
Coyote’s Guide to IDL
• www.dfanning.com The real source for
tips and tricks
June 11, 2009
IDL for REU students
Margit Haberreiter
69/72
Colors and Plots
• xpalette to show color table
• tvrd (“TV read”)to grab graphics window
and write to file
• add color definitions to startup file
• remember to make plots color-blind
friendly if possible
(linestyles --- and symbols xxx)
June 11, 2009
IDL for REU students
Margit Haberreiter
70/72
File Tips
• help IDL’s automatic compiler by always
naming your files with lower case
• IDL stops compiling when it hits the
routine that matches the filename
June 11, 2009
IDL for REU students
Margit Haberreiter
71/72
IDL 7 Workbench
• New version of IDL uses Eclipse
• Backwards compatible as always
June 11, 2009
IDL for REU students
Margit Haberreiter
72/72
Tips & Tricks for Workbench
• Hover help (and open declaration)
• Redefine key bindings to whatever you’re used
to: ctrl-shift-L
• double click on history entries
• cntrl-i shifts focus to command line
• cntrl-space (or alt-slash) for command
completion
• .edit filename
• search works like grep—search for content in
files
June 11, 2009
IDL for REU students
Margit Haberreiter
73/72
Just the beginning….
• Remember, there’s a lot of IDL
knowledge around here, so feel free to
ask questions.
• Many user library routines might
already do whatever you had in mind.
• Online help manual has lots of examples.
• SolarSoft, Widget programming, Object
Oriented...
June 11, 2009
IDL for REU students
Margit Haberreiter
74/72