Presentation is loading. Please wait.

Presentation is loading. Please wait.

IDL Tutorial: Day 2 Angela Des Jardins Goals: 1) Introduce functions and procedures 2) Describe writing the simplest kind.

Similar presentations


Presentation on theme: "IDL Tutorial: Day 2 Angela Des Jardins Goals: 1) Introduce functions and procedures 2) Describe writing the simplest kind."— Presentation transcript:

1 IDL Tutorial: Day 2 Angela Des Jardins (desjardins@physics.montana.edu) Goals: 1) Introduce functions and procedures 2) Describe writing the simplest kind of programs 3) Explain saving and restoring

2 Functions and Procedures  Two basic types of programs  Functions: result=function_name(parameter, Keyword=Set, …) 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

3 Commonly Used Procedures  print: for printing stuff to screen: IDL>print, sin(x)  plot: plot variables to the current graphics device (usually screen): IDL>plot, x, y,[title=‘blah’,…keywords]  set_plot: tells idl where to send plots to. Screen (Xdisplay) is default - IDL>set_plot,”x” ;sends output to the x display - IDL>set_plot, “ps”; sends the output to a postscript file with default name idl.ps. Read ps files with ghostview unix_prompt> gv idl.ps  device: changes properties of the device currently enabled by set_plot. See help menu.

4 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: IDL>save, variable1, variable1, file=‘file.sav’  Restore allows you to restore saved variables to a session Example: restore, ‘file.sav’

5 Commonly Used Functions  Many math operators are functions IDL> y=sin(x) IDL> y=cos(x) IDL>y=exp(x) IDL> y=sin(x) IDL> y=cos(x) IDL>y=exp(x)  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()

6 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 Shortcoming: no loops allowed in macros.

7 “Homework”  Make a macro in which you plot, on a good scale, with labels, y=e x. Also, have it print to the screen, “You did it right!” Make a post script copy of your plot.  Make a file using emacs (or your favorite editor) which contains a row for each student in this class and a column for each of the following: distance (in miles) of the student’s home from Bozeman, year in college, favorite color (in Angstroms), number of books read in the last year, number of trails hiked in the last year, and number of foods disliked. Use ascii_template and read_ascii to make a structure containing your numbers. Using the plot procedure, find out if there are any correlations among yourselves!


Download ppt "IDL Tutorial: Day 2 Angela Des Jardins Goals: 1) Introduce functions and procedures 2) Describe writing the simplest kind."

Similar presentations


Ads by Google