Presentation is loading. Please wait.

Presentation is loading. Please wait.

IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Angela Des Jardins

Similar presentations


Presentation on theme: "IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Angela Des Jardins"— Presentation transcript:

1 IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Angela Des Jardins (desjardins@physics.montana.edu)

2 What is IDL?  Interactive Data Language (IDL) is a powerful, interactive command language with all of the program control options of a standard programming language.  Many useful functions are available in large library  Used by - Nasa - Lockheed-Martin - Medical Imaging Fields  http://www.rsinc.com/ http://www.rsinc.com/  http://idlastro.gsfc.nasa.gov/homepage.html http://idlastro.gsfc.nasa.gov/homepage.html  http://www.astro.washington.edu/deutsch/idl/htmlhelp/index.html http://www.astro.washington.edu/deutsch/idl/htmlhelp/index.html  http://www.ugastro.berkeley.edu/tutorials/tutorials.html http://www.ugastro.berkeley.edu/tutorials/tutorials.html  http://www.lmsal.com/solarsoft http://www.lmsal.com/solarsoft

3 Note: In this tutorial, IDL> refers to the IDL prompt. Once in IDL, you type the stuff that comes after this. For example to enter the print command, I’ll have IDL>print,a and you would type in “print,a” at the command line. Also, [brackets] in an IDL description indicate an optional item.

4 Starting IDL  In a terminal window, once an IDL “path” is setup (.idl_startup), type idl, idlde, sswidl, or sswidlde  sswidl = IDL solar software, useful for solar physicists  Calling sswidl or sswidlde calls IDL with specified paths which have useful programs for solar physics work. You’ll almost always use sswidl or sswidlde.  To manually set the “paths” needed for your work, talk to your research advisor  Calling sswidlde calls a graphical developer, where sswidl simply works in your terminal window  To use an OS command, enter $ prior to it: IDL>$ls Exceptions: pwd, cd,’/disk…’  To exit out of IDL, type IDL>exit

5 Journal Procedure  Records everything you enter, plus any error or processing messages output by IDL, into a text file  Syntax: IDL> journal,‘text_file’opens the file & starts record IDL> command line statements IDL> journal closes the file  To view, open journal file with any text editor emacs text_file & Journal is also useful for starting a program you want to write, or for creating batch files

6 General Strategies IDL help menu: IDL>? IDL help menu: IDL>? sswidl (solar) help: IDL>xdoc sswidl (solar) help: IDL>xdoc IDL>help, [variable, /str]For properties of variables and status IDL>help, [variable, /str]For properties of variables and status IDL>which,’program.pro’Tells you which program you’re using IDL>which,’program.pro’Tells you which program you’re using  To modify a program you want to call in IDL, many text editors can be used: nedit, emacs, pico, vi Don’t memorize all commands Don’t memorize all commands Keep notes on your work and use the IDL journal Keep notes on your work and use the IDL journal Write programs in steps Write programs in steps Learn by doing - don’t be afraid to make mistakes Learn by doing - don’t be afraid to make mistakes

7 Some basic syntax  IDL is not case sensitive but Unix is IDL> help, var (=) IDL> HELP, Var IDL> journal, “text_file” (NOT =) journal, “Text_File”  Use the up arrow key to recall the most recent IDL input lines  Commas are used to separate arguments from one another  Use & to enter more than one command on a line  Use $ at the end of a line that needs to continue  “All” programs end with.pro  ; comments out an IDL line

8 Basic Variable Types  Strings (Text) - Must be contained within “ “ or ‘ ‘ - Must be contained within “ “ or ‘ ‘ - cannot perform numerical operations - cannot perform numerical operations  Integers - only range from –32,768 to 32,767 - only range from –32,768 to 32,767  Long word Integers - IDL>long(#) for 32 bit integers - IDL>long(#) for 32 bit integers - IDL>long64(#) for 62 bit integers - IDL>long64(#) for 62 bit integers  Float - floating point number with 32 bit word length - floating point number with 32 bit word length - IDL>3./2. Or IDL>float(3)/float(2) - IDL>3./2. Or IDL>float(3)/float(2)  Double - a floating point number with 64 bit word length - a floating point number with 64 bit word length

9 Assigning a Variable a Value, math  Variable_name = value - will automatically select a variable type - will automatically select a variable type  Variable_name = function_name(argument)  Variable_name = string(value)  Variable_name = long(value)  Variable_name = fix(value) for integers  Variable_name = float(value)  Variable_name = double(value) Math works the way you think it would: IDL>try=5./3.+4.1 IDL>print,try5.7667

10 Naming Variables  Assign ‘readable’ variable names that make sense  Variable names must start with a letter - NO: 6a=“gamma” OK: a6=“gamma”  Variables should not have the same name as IDL functions (you’ll probably learn this the hard way; ‘switch’ example’)  -NO: plot=6.0  Variable names may not have spaces in them - NO: A 6=5 OK: A_6=5  Some characters are illegal or have special meanings - NO: a@=5, a.b=5 (used for structures), A+=5, A#=5

11 Arrays  Variables, of any type, that contain multiple values  Array Indexing: IDL arrays start at index zero IDL>A=[1,2,3,4] IDL>print, A[0]1 IDL>print, A[1]2  Multiple ways to create arrays intarr(), fltarr(), dblarr(), strarr() indgen(), findgen(), dindgen() IDL>b=findgen(4) IDL>print,b[0:2]0.00000 1.00000 2.00000

12 Array operations  Simple math operations IDL>D=findgen(3) IDL>D=findgen(3) IDL>A=2*D IDL>A=2*D IDL>print,A0.00000 2.00000 4.00000 IDL>print,A0.00000 2.00000 4.00000  More complex math Manipulating arrays - multiply an array by another, matrix operations: look in help Manipulating arrays - multiply an array by another, matrix operations: look in help  Useful functions Total(array): computes a sum of all elements Total(array): computes a sum of all elements Min(array): outputs the min value; also Max Min(array): outputs the min value; also Max Minmax(array): outputs the min then max Minmax(array): outputs the min then max N_elements(array): gives total # of elements N_elements(array): gives total # of elements

13 Structures  Structures are variables that contain multiple variables (scalars, arrays, or other structures) (scalars, arrays, or other structures)  Each variable contained within a structure is called a tag Syntax: struct={[struct_type], tag_name1: tag_value1,…}  IDL> list={frst:findgen(10),scnd:findgen(10)*2,thrd:findgen(10)+1}  IDL> print,list.frst 0.00000 1.00000 2.00000 3.00000 4.0000 5.00000 6.00000 7.00000 8.00000 9.00000  IDL> print,list.scnd[2]4.00000  IDL> help,list,/str FRSTFLOATArray[10] FRSTFLOATArray[10] SCNDFLOATArray[10] SCNDFLOATArray[10] THRDFLOATArray[10] THRDFLOATArray[10]

14 “Homework” Try these examples (in IDL!) on your own: 1)Print out the answer in double precision of Pi+3*6.2 2)Make an array of 15 floating point numbers that count from 3 to 17. 3) Make a structure with four tags, each tag having 5 values. Print the value of the third element of the second tag. 4)What is the name of the journal file you (should have!) created when practicing the above tasks? 5)What is one question you have about the basics of IDL?


Download ppt "IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Angela Des Jardins"

Similar presentations


Ads by Google