IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Maria Kazachenko

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

COMP234 Perl Printing Special Quotes File Handling.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Linux+ Guide to Linux Certification, Second Edition
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
IDL Tutorials: Day 1 Michael Hahn
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
IDL Tutorials Day 2 Henry (Trae) Winter
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Introduction to Perl Yupu Liang cbio at MSKCC
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room ,
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Angela Des Jardins
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
8-2 What is a program? What is a “Window Manager” ? What is a “GUI” ? How do you navigate the Unix directory tree? What is a wildcard? Readings: See CCSO’s.
Chapter Three The UNIX Editors.
Introduction to Programming Using C An Introduction to Operating Systems.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Digital Image Processing Introduction to M-function Programming.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Learning basic Unix command It 325 operating system.
IDL Tutorials Day 1 Henry (Trae) Winter Room 235
CS 120 Extra: The CS1 Server Tarik Booker CS 120.
Learning Unix/Linux Based on slides from: Eric Bishop.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
LINGO TUTORIAL.
Introduction to Unix for FreeSurfer Users
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Fundamentals of Programming I Overview of Programming
CIRC Winter Boot Camp 2017 Baowei Liu
Andy Wang Object Oriented Programming in C++ COP 3330
The Command Prompt Commands are the way to “do things” in Unix
Shell Script Assignment 1.
MATLAB DENC 2533 ECADD LAB 9.
LING 408/508: Computational Techniques for Linguists
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Use of Mathematics using Technology (Maltlab)
Web Programming Essentials:
Lecture 2 Introduction to MATLAB
Andy Wang Object Oriented Programming in C++ COP 3330
INTRODUCTION TO MATLAB
Stata Basic Course Lab 2.
Presentation transcript:

IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Maria Kazachenko

What is IDL? 1970 – IDL’s predecessor, Laboratory for Atmospheric and Space Physics, CO 1970 – IDL’s predecessor, Laboratory for Atmospheric and Space Physics, CO 1987 – Unix environment 1987 – Unix environment 1992 – Widgets added 1992 – Widgets added Interactive Data Language (IDL) is a programming language that is a popular data analysis language among scientists. It is has all of the program control options of a standard programming language. It is has all of the program control options of a standard programming language. Syntax includes many constructs from Fortran and some from C Syntax includes many constructs from Fortran and some from C Many useful functions are available in large library Many useful functions are available in large library Used by Used by - NASA - Lockheed-Martin - Medical Imaging Fields

IDL under Unix

Basic Unix Commands >man command-name - looks at the manual page for the command >man command-name - looks at the manual page for the command >pwd - shows current working directory path >pwd - shows current working directory path >cd {dirname} - changes current directory into dirname >cd {dirname} - changes current directory into dirname >cd /home/ >chmod {options} - changes permission modes of a file >chmod {options} - changes permission modes of a file >cp {filename}{path} - copies files from one directory/filename to another >cp {filename}{path} - copies files from one directory/filename to another >cp f1 f2 - makes a file f2 identical to f1 >cp f1 f2 - makes a file f2 identical to f1 >cp –r - copies a folder >emacs {filename} - runs the text editor named EMACS >emacs {filename} - runs the text editor named EMACS >find./ -name ‘’t*’’ –print - searches the named directory and its sub- directories for files starting with ‘t’ >find./ -name ‘’t*’’ –print - searches the named directory and its sub- directories for files starting with ‘t’ >gv {filename.ps} - X PostScript previewer >gv {filename.ps} - X PostScript previewer >ls {directory} - shows directory listing >ls {directory} - shows directory listing >ls - prints the names of the files in the current directory >ls –l - shows long directory listing >mkdir dirname - makes a sub-directory named “dirname” in the current directory >mkdir dirname - makes a sub-directory named “dirname” in the current directory >ssh {machine-name} - secure alternative to telnet. >ssh {machine-name} - secure alternative to telnet.

In this tutorial, IDL> refers to the IDL prompt. And > refers to OS prompt (outside IDL). 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. Note

Starting IDL

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

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

General Strategies IDL> ?; IDL help menu IDL> ?; IDL help menu IDL> xdoc; Sswidl (solar) help IDL> xdoc; Sswidl (solar) help IDL> help, [variable, /str]; Properties of variables IDL> help, [variable, /str]; Properties of variables IDL> z=fltarr(3,7) ; Defines new array (3x7) IDL> z=fltarr(3,7) ; Defines new array (3x7) IDL> help,z; Tells about z IDL> help,z; Tells about z Z FLOAT = Array[3, 7] Z FLOAT = Array[3, 7] IDL> which,’display.pro’; Location of the program ; you’re using IDL> which,’display.pro’; Location of the program ; you’re using/disk/hl2/data/maria/projects/flares/LCT/display.pro Unix text editors - nedit, emacs, pico, vi Unix text editors - nedit, emacs, pico, vi > nedit mypro.pro > nedit mypro.pro 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!!!

Some basic syntax IDL is not case sensitive but Unix is IDL is not case sensitive but Unix is IDL> help, var (=) IDL> HELP, Var IDL> journal, “text_file” (NOT =) journal, “Text_File” The up arrow key recalls the most recent IDL input lines The up arrow key recalls the most recent IDL input lines Ctrl-e, Ctrl-a – moves cursor to the end, beginning of the line Ctrl-e, Ctrl-a – moves cursor to the end, beginning of the line Ctrl-C – interrupts IDL-command Ctrl-C – interrupts IDL-command IDL> ; comments out an IDL line IDL> ; comments out an IDL line Use & to enter more than one command on a line Use & to enter more than one command on a line IDL> a=[1,2,3,4,5,6] & print,a,total(a) Commas separate arguments from one another Commas separate arguments from one another IDL> plot,a,sin(a/5.)/exp(a/50.) ;plots function Use $ at the end of a line that needs to continue Use $ at the end of a line that needs to continue IDL> for i=0,5 do $ IDL> print,i,a[i] “All” programs end with.pro - masha.pro “All” programs end with.pro - masha.pro

Basic Variable Types Integers Integers - 1 byte – byte data type (0..256) - 1 byte – byte data type (0..256) IDL> a=bindgen(1) - 2 bytes – integers data type ( ) - 2 bytes – integers data type ( ) IDL> b=indgen(1) & print,5/ bytes – long integers ( ) - 4 bytes – long integers ( ) IDL> c=lindgen(1) - 8 bytes – 64-bit long integers ( ) - 8 bytes – 64-bit long integers ( ) Floating data types Floating data types - 4 bytes – floats (exponent from-38 to 38) - 4 bytes – floats (exponent from-38 to 38) IDL>print,5./3. & y=float(3)/float(2) IDL> a= IDL> print,a,format=‘(f20.10)’ - 8 bytes – double-precision - 8 bytes – double-precision IDL> print,5d/3d IDL> a= d0 & print,a,format=‘(f20.10)’ IDL> a= d0 & print,a,format=‘(f20.10)’ IDL> xyouts,xloc,yloc,string(a,format=‘f(20.10)’) Strings (Text) Strings (Text) IDL>x=‘Hi there!!!’ IDL>x=‘Hi there!!!’

Assigning a Variable a Value, Algebra Variable_name = value Variable_name = value - will automatically select a variable type - will automatically select a variable type IDL> a=5/ ; float IDL> a=5/ ; float Variable_name = function_name(argument) Variable_name = function_name(argument) IDL> b=exp(a) ; float IDL> b=exp(a) ; float Variable_name = string(value) Variable_name = string(value) IDL> str=string(’10’) ; str=’10’ IDL> str=string(’10’) ; str=’10’ Variable_name = long(value), converts to long integer type. Variable_name = long(value), converts to long integer type. IDL>x=long( ) ; long integer IDL>x=long( ) ; long integer Variable_name = fix(value), convert to integer type. Variable_name = fix(value), convert to integer type. IDL> print,fix(!Pi) 3 ; integer IDL> print,fix(!Pi) 3 ; integer Variable_name = float(value), convert into single precision float Variable_name = float(value), convert into single precision float IDL> help,float(2) ;float IDL> help,float(2) ;float Variable_name = double(value), converts into double precision float Variable_name = double(value), converts into double precision float

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

Organizational structures Scalars Scalars IDL> x=3. Vectors Vectors IDL> a=[0,1,2,3] & print,a[1] 1 Arrays (see IDL help for matrices) (index from zero) Arrays (see IDL help for matrices) (index from zero) intarr(), fltarr(), dblarr(), strarr().indgen() intarr(), fltarr(), dblarr(), strarr().indgen() IDL> q=intarr(2,2) IDL> m=indgen(2,2)01 23 IDL> print,m(0,1)2 IDL> a=findgen(100,100) IDL> print,a[1,0] IDL> b=a[23:25,67:69] IDL> indx=where(a gt 10.) IDL> jndx=where(a[indx] le 100.) IDL> b=a[indx[ jndx]] makes b equal to 1-d array equal to the elements of a that are both larger than 10 and less than or equal to 100 makes b equal to 1-d array equal to the elements of a that are both larger than 10 and less than or equal to 100

Array operations Simple math operations (* by scalar, +, -); A 3-column by 2-row array: Simple math operations (* by scalar, +, -); A 3-column by 2-row array: IDL> A = [ [0, 1, 2],[3, 4, 5],[5,6,7]] IDL> A = [ [0, 1, 2],[3, 4, 5],[5,6,7]] IDL>B=2*A IDL>B=2*A IDL>print,B IDL>print,B More complex math More complex math #, Multiply an array by another IDL> C=A#B#, Multiply an array by another IDL> C=A#B N_elements: Total number of elements in arrayN_elements: Total number of elements in array IDL> n=n_elements(A) Total(array): computes a sum of all elementsTotal(array): computes a sum of all elements Min(array): outputs the min value; also MaxMin(array): outputs the min value; also Max Minmax(array): outputs the min then maxMinmax(array): outputs the min then max Rebin: Resize array IDL> C=Rebin(A,6,6)Rebin: Resize array IDL> C=Rebin(A,6,6) Eigenvec: finds eigenvectorsEigenvec: finds eigenvectors

Structures Structures are variables that contain multiple variables (scalars, arrays, or other structures) Structures are variables that contain multiple variables (scalars, arrays, or other structures) Each variable contained within a structure is called a tag Each variable contained within a structure is called a tag IDL> struct={[struct_name], tag_name1: tag_value1,…} Anonymous structure (may change tags) IDL> A={name:’alpha ori’, ra:5.33, dec:-7.6, red:fltarr(12)} IDL> help,/st NAME STRING 'alpha ori' NAME STRING 'alpha ori' RA FLOAT RA FLOAT DEC FLOAT DEC FLOAT RED FLOAT Array[12] RED FLOAT Array[12] IDL> print,a.dec-7.6 IDL> a.dec=5.5 Named structure. Once a named structure is defined, you cannot change the names of the tags or the number of tags IDL> A={star, name:’alpha ori’, ra:5.33,dec:-7.6,red:fltarr(12)} Array of structures (see Help for replicate function) IDL> cataloga=replicate(a,585)

“Homework” 0) Start with Journal-file 1)Make a vector x=(0,1,2,3,4,5,6,7,8,9)*Pi/9 IDL> x=indgen(10)*!Pi/9 2)Make a vector y=sin(x) IDL> y=sin(x) 3)Plot (x,y) IDL> plot,x,y 3) Find a determinant of the matrix IDL> A = [ [1, 1, 2],[3, 4, 5],[5,6,7]] (first manually and then check the result with Determ(A)) 4) Think about an IDL project

Questions

Loops Programs with vector and array expressions run faster than programs with scalars, loops, and IF statements. Programs with vector and array expressions run faster than programs with scalars, loops, and IF statements. Consider the problem of adding all positive elements of array B to array A. IDL> FOR i = 0, (N-1) DO IF B[i] GT 0 THEN A[i] = A[i] + B[i] Or IDL> A = A + (B > 0) For…do – FOR statement is used to execute one or more statement repeatedly, while incrementing or decrementing a variable with each repetition.11 IDL>FOR i = 1, 4 DO PRINT, i,i^ Or if there are many lines in a loop, then write simple program PRO Test FOR i = 1, 4 DO BEGIN FOR i = 1, 4 DO BEGINPRINT,i,i^2ENDDOEND