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 Types of computer programming languag es High-level languages –Algebra formula-type (FORTRAN, ALGOL, BASIC, PASCAL, APL, PL/I) –Business data processing (COBOL, RPG) –String and list processing (LISP, Prolog) –Object-oriented (C++, JAVA, Python, Perl) –Visual (Visual Basic, Visual JAVA, Visual C) System languages Assembly languages Machine languages

4 History of computer languages FORTRAN 1954 LISP 1958 ALGOL 1958 COBOL 1959 BASIC 1964 PASCAL 1970 C 1971, C++ 1983

5 Structure of a computer program 1.Define variables, arrays, constants 2.Read in data 3.Pre-processing: quality control, filling missing data, interpolation, re-gridding 4.Data analysis or other calculation 5.Plot the results 6.Output the results

6 A good programming style Clear (have a clear structure) Simple (try to use less lines) General (try to use variables) Accumulate subroutines

7 Overview of the Interactive Data Language (IDL) Developed and marketed by Research Systems, Inc. of Boulder, Colorado (first version released in 1981) It is basically FORTRAN + strong visualization, array operation, and object-oriented functions 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)

8 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)

9 Open and run IDL Open IDL Interactive mode: print, “Hello world!” Edit a program file Compile and run a program file In unix version:.r filename.pro Online help: >?

10 The simplest IDL program print, ‘This is my first IDL program’ end Note: Every IDL program should end with an “ end ” statement

11 Structure of a computer program 1.Define variables, arrays, constants 2.Read in data 3.Pre-processing: quality control, filling missing data, interpolation, re-gridding 4.Data analysis or other calculation 5.Plot the results 6.Output the results

12 Variables and Data types Three basic data types: –Integer: i=1, j=12, k=123 –Floating-point: x=1.5, y=3.8 –String: a=‘This is a string’, b=‘123’ To check about data type: help, variable_name Other data types (not often used)

13 Data type conversions IDL allows conversion of one data type to another –From float to integer i=fix(2.8) –From integer to float x=float(3) –From integer to string a=string(45) Note: Conversion from float to integer will loose all the decimals fix(5.001)=5 fix(5.999)=5

14 Define variable names You can use any names other than the reserved words Traditionally (e.g. in FORTRAN), people use: i, j, k, l, m, n for integers other letters (a-h, o-z) for floating-point

15 Simple calculation Arithmetical operators: +, -, *, /, ^ (x+y*2-z^3)/4.0 Note: Integer divided by integer returns an integer 5/4 = 1, 3/4 = 0 Relational operators: eq, ne, lt, gt, le, ge return “1” if true or “0” if false 3 le 5 returns 1 8 eq 11 returns 0

16 Operators and operator precedence ( ) has the highest level of precedence! Arithmetical operators have higher level of precedence than relational operators

17 Example: Currency exchange ; Define variables and constants dollar=0.0 euro=0.0 rate= 0.92 ; 1 dollar equals to 0.92 euros ; Input data dollar=200.0 ; Do calculation euro=dollar*rate ; Output result print, euro end

18 Simple data input/output (I/O) Data input from keyboard: read, x read, x, y, z Data output to screen: print, x print, x, y, z We’ll discuss about file I/O in the future

19 Example: Currency exchange ; Define variables and constants dollar=0.0 euro=0.0 rate= 0.92 ; 1 dollar equals to 0.92 euros ; Input data print, “Input dollar amount” read, dollar ; Do calculation euro=dollar*rate ; Output result print, “The amount of Euro is”, euro end

20 Summary Overview of computer languages Overview of IDL Strength of IDL: (1) Interactive/compiled modes; (2) Array-oriented; (3) Variables easily redefined; (4) Many built-in subroutines Open, edit, and run IDL Variables and data types Operators Simple data I/O

21 A good programming style Clear (have a clear structure) Simple (try to use less lines) General (try to use variables) Accumulate subroutines

22 Structure of a computer program 1.Define variables, arrays, constants 2.Read in data 3.Pre-processing: quality control, filling missing data, interpolation, re-gridding 4.Data analysis or other calculation 5.Plot the results 6.Output the results

23 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 w=3z 2 -5x 1.5 +2y 2.8 and print out the result Please write a program for a supermarket cashier. Assume the price is $0.99/lb for apples, $1.29/lb for watermelons, $2.99/lb for strawberries, and $3.49/lb for blueberries. Assume the sales tax is 7%. Please write a program to read in the weight of each product, and then calculate and print out the receipt. Try to make the receipt look similar to what you get from a supermarket.


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

Similar presentations


Ads by Google