idl tutorial: day 2

8
IDL Tutorial: Day 2 Michael Hahn ([email protected] na.edu)

Upload: tacita

Post on 05-Jan-2016

24 views

Category:

Documents


0 download

DESCRIPTION

IDL Tutorial: Day 2. Michael Hahn ([email protected]). Today’s Topics. Using Functions and Procedures already written - e.g. plotting Xdoc Writing Scripts (Macros) Save and Restore Structures. Functions and Procedures. Two basic types of programs Functions: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: IDL Tutorial: Day 2

IDL Tutorial: Day 2

Michael Hahn

([email protected])

Page 2: IDL Tutorial: Day 2

Today’s Topics• Using Functions and Procedures already written

- e.g. plotting

• Xdoc

• Writing Scripts (Macros)

• Save and Restore

• Structures

Page 3: IDL Tutorial: Day 2

Functions and Procedures• Two basic types of programs

• Functions: result=function_name(parameter, Keyword=Set, …)

Examples: size, n_elements, sin, cos, reverse, where- Functions can be placed anywhere you can put a value

• Procedures: procedure_name, param1, param2, Keyword=Set…Examples: help, print, open, printf, plot, set_plot, device, save- Procedures do stuff, but don’t need to return a value

• Exact syntax for particular Procedures or Functions can be found using the help menu, xdoc, or the doc_library procedure

Page 4: IDL Tutorial: Day 2

xdoc• Xdoc allows you to graphically brose the lbirary of Solarsoft

routines

• Type in xdoc at IDL command prompt

• Can search for the name of a procedure/function

• Usually you don’t know the name, xdoc makes it ‘easy’ for you to search for it

Page 5: IDL Tutorial: Day 2

Commonly Used Procedures• print: for printing stuff (to screen)

e.g. > print, sin(x)• plot: plot variables to the current graphics device (usually screen)

> plot, x, sin(x), Title=“sin Plot”, xtitle=“x”, $ytitle=“sine of x”

• set_plot: tells idl where to send plots to. Screen (Xdisplay) is default

- set_plot,”x” ;sends output to the x display- set_plot, “ps”; sends the output to a postscript file with

default name idl.ps. Read ps files with ghostviewunix_prompt> gv idl.ps

• device: changes properties of the device currently enabled by set_plot. See help menu.

Page 6: IDL Tutorial: Day 2

Commonly Used Functions• Many math operators are functions

> y=sin(x) > y=cos(x) >y=exp(x); exponential function

• Where allows you to pick out the index of an array that meets some criterion

> index=where(new_array eq 15)

(more on boolean operators later)

• Replicate makes copies of variables, arrays, structures, etc...

> stars=replicate(stars,15)

• dialog_pickfile allows you to graphically pick out file names

> file_name=dialog_pickfile()

Page 7: IDL Tutorial: Day 2

Macros (Scripts)• Simplest form of Program

• In the editor window write commands just like you would at command prompt

• At the end type END so IDL knows when program is over

• Save the program with a unique name (I.e. save the text file)

• At the command prompt type either:

> .run program_name

> .rnew program_name

Page 8: IDL Tutorial: Day 2

Save and Restore• Programs are saved by saving the text file you write them in

• Save, the procedure, allows you to save variables to a file

Example:

save, variable1, variable1, file=‘file.sav’

• Restore allows you to restore saved variables to a session

Example:

restore, ‘file.sav’