Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geog 820.03 Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax.

Similar presentations


Presentation on theme: "Geog 820.03 Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax."— Presentation transcript:

1 Geog 820.03 Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax

2 Syllabus

3 Overview of IDL The Interactive Data Language (IDL) is an array-oriented data analysis and visualization environment developed and marketed by Research Systems, Inc. of Boulder, Colorado (first version released in 1981) It is available for Windows, MacOS, UNIX (including Linux). Requires no (or little) change of code when transfer to a new platform Now widely used in research, educational, and commercial settings (e.g. astronomy, space, physics, earth, medical, and engineering)

4 Strength of IDL comparing with other languages (e.g. C and Fortran) IDL offers both interactive and compiled programming modes (C and Fortran offer only compiled mode) IDL is optimized to perform array operations (C and Fortran is is optimized to perform scalar operations) IDL variables may be created or redefined with a new type, size, or value at any time (in C and Fortran the variable type is fixed at run-time) IDL includes many built-in and user-developed routines for visualization and numerical analysis (C and Fortran require external libraries)

5 Open and run IDL Open IDL Simple code print, ‘This is an IDL program’ end Note: Every program should end with an “ end ” statement Run IDL Interactive mode Compiled mode.r filename.pro Online help: >?

6 Variables and Data types String type: x=‘a’, y=‘This is a string’ To check about data type: help, variable_name

7 Type conversions Note: Conversion from float to integer will loose all the decimals fix(5.001)=5 fix(5.999)=5

8 Variable names You can use any names other than the reserved words

9 Operators and operator precedence ( ) has the highest level of precedence! Arithmetical operators have higher level of precedence than relational operators Integer divided by integer returns an integer : 3/4 = 0 Relational operators return “1” if true or “0” if false 3 le 5 returns 1 8 eq 11 returns 0

10 Simplest arrays Integer x = [1, 2, 3, 5, 6] Floating point y = [1.2, 3.5, 8.8, 11.3, 20.5] String Month = [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’]

11 Creating arrays Functions for creating arrays (1-8 dimensions) zeroed arrays: intarr( ), fltarr( ), strarr( ) index arrays: indgen( ), findgen( ), sindgen( ) Note in IDL, index starts from 0 instead of 1 Use index array to create a evenly-spaced array n=10 x0=5 dx=10 arr=x0+findgen(n)*dx print, arr Please try to create all the arrays at the beginning of your program

12 Plotting overview Plotting procedures: Line plots: plot, oplot, plots, axis Map plots: contour 3-D plots: surface, shade_surf (Putting labels over the plot: xyouts ) When a plotting procedure is called, the default behavior is as follows: 1. Erase the contents of the current window (a new window is created if none exits) 2. Establish appropriate data coordinates for the input data 3. Draw axes (including labels and tick marks) 4. Draw the data lines

13 Line plots — Plot Syntax: plot, x, y plot, y (the data points are plotted against corresponding array indices) plot, x, y, max=dmax, min=dmin (limit the maximum and minimum data values to be plotted) Overplotting oplot, x, y Scatter plots plot, x, y, psym=symbol_code

14 Line plot customization Keywords General: title, charsize, charthick For data lines: linestyle, thick, psym, symsize, color, /nodata, /noerase, /noclip For axis: /ynozero, /xlog, /ylog, [xyz]title, range, style, thick [xyz]ticks, tickv, tickname, ticklen

15 Example x=findgen(10) y=x^2.0 plot, x, y, title=‘Google stock value’, xtitle=‘Time (month)’, ytitle=‘Dollar’, charsize=2.0, $ thick=4, $ xrange=[0,9], xstyle=1, yrange=[0,85], ystyle=1, $ xticklen=0.01,yticklen=0.01, $ xticks=9, yticks=4, ytickv=[0,10,20,40,60], ytickname=[‘0’,’10’,’20’,’40’,’60’]

16 Summary Overview of IDL Strength of IDL: (1) Interactive/compiled modes; (2) Array-oriented; (3) Variables easily redefined; (4) Many built-in subroutines Open and run IDL Variables and data types Operators Line plots: basics and cosmetics

17 In-class assignment I Design a picture using characters on the keyboard. Write an IDL program to print it out using multiple lines of ‘print’ statement Assume x=3, y=4, z=8, write an IDL program to calculate z 2 -x 2 +y 2.8 and print out the result Assume x=[1, 3, 5, 6, 7], plot (1) y=x 2, (2) y=e x. Please adjust the titles and axes to make the plots look good. Assume x=findgen(101)/100.0*2*!pi, plot (1) y=sin(x), (2) y=cos(5x), and (3) y=5sin(3x)+2cos(9x). Please adjust the titles and axes to make the plots look good. (In IDL, !pi gives the value of  )


Download ppt "Geog 820.03 Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax."

Similar presentations


Ads by Google