IDL Tutorials: Day 4 - PowerPoint PPT Presentation

About This Presentation
Title:

IDL Tutorials: Day 4

Description:

IDL Tutorials: Day 4 Michael Hahn (hahn_at_solar.physics.montana.edu) Today s Topics Relational Operators Conditional statements and boolean operators Loops Relational ... – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 11
Provided by: solarPhys
Category:
Tags: idl | array | day | tutorials

less

Transcript and Presenter's Notes

Title: IDL Tutorials: Day 4


1
IDL Tutorials Day 4
  • Michael Hahn
  • (hahn_at_solar.physics.montana.edu)

2
Todays Topics
  • Relational Operators
  • Conditional statements and boolean operators
  • Loops

3
Relational Operators
  • Relation operators test the relationships between
    two arguments
  • Relation operators return 1 if they are true, 0
    if false
  • Can be used on strings also there are special
    functions for comparing strings
  • Common R.Os
  • - eq equal to
  • - ne not equal to
  • - lt less than
  • - gt greater than
  • - ge greater than or equal to
  • - le less than or equal to
  • Syntax Arg1 R.O. Arg2
  • - e.g gt print, 1 gt 1 gt print, array_1 le
    array_2

4
If Statements
  • One type of statement that allows program to make
    decisions
  • If statements use R.O.s as a condition if the
    R.O returns 1 (true)
  • then the statement executes
  • An optional else statement can be included,
    giving an option to do something if the R.O.
    returns 0 (false)
  • Syntax
  • IF condition THEN something
  • Examples
  • If x ge y then print, x
  • If x gt y then biggest x else biggesty
  • IF n_params() lt 1 then print, you need a
    parameter
  • See also Case Statements

5
Loops
  • Loops allow for actions to occur repeatedly
  • Usual syntax is
  • conditional_statement BEGIN
  • do something
  • do_something_else
  • endstatement
  • Many types of loops
  • -For loops
  • -while loops
  • -repeat loops
  • If youre not careful your loop might not end.
    If you make an infinite loop CTRLC can be used
    to break out of it.

6
Blocks
  • Blocks allow a number of statements to be
    contained within another kind of statement
  • Blocks and Common Blocks are different things
  • Blocks usually begin with the word BEGIN and end
    with a particular end-statement depending on what
    statement the block is contained in.
  • - e.g. IF (R.O) then BEGIN
  • . Statements
  • ENDIF
  • or
  • - FOR index 0, n_elements(array) DO BEGIN
  • statements
  • ENDFOR

7
For Loop Syntax and Examples
  • For statements repeat a statement until a counter
    reaches an assigned value
  • The the counter is automatically advanced by one
    after each step
  • Syntax
  • gt FOR countervalue, number DO statement
  • or
  • gt FOR countervalue, number DO BEGIN
  • statements
  • gt ENDFOR
  • Examples
  • gt FOR counter0,10 DO print, cos(((2!pi)/10)cou
    nter)
  • gt FOR index0, n_elements(array)-1 DO BEGIN
  • gt array,indexcos(array_3index,)
  • gt ENDFOR

8
While Loop Syntax and Examples
  • While loops repeat until some conditional
    statement is met
  • Syntax
  • gt WHILE condition DO statement
  • or
  • gt WHILE condition DO BEGIN
  • statements
  • gt ENDWHILE
  • Examples
  • gt WHILE x ge y DO xx-5
  • gt WHILE x lt y DO BEGIN
  • gt xx5
  • gt print, x
  • gt ENDWHILE

9
Repeat Loop Syntax and Examples
  • Repeat loops repeat until some conditional
    statement is met
  • Difference between repeat and while loops is the
    location of the conditional statement
  • Syntax
  • gt REPEAT statement UNTIL condition
  • or
  • gt REPEAT BEGIN
  • gt statements
  • gt ENDREP UNTIL condition
  • Examples
  • gt REPEAT xx-5 UNTIL x lt y
  • gt REPEAT BEGIN
  • gt xx5
  • gt print, x
  • gt ENDREP UNTIL x gt y

10
Boolean Operators
  • Boolean operators can be used to make complex
    groupings of conditional statements
  • e.g. if (x lt y) and (x lt z) then print, x is
    small
  • There are four basic boolean operators
  • - and returns true when both of its operands
    are true
  • gt print, (1 lt 2) and (1 lt 3) IDL prints 1
  • gt print, (1 lt 2) and (1 gt3) IDL prints 0
  • - or Returns true when either of its operands
    are true
  • gt print, (1 lt 2) or (1 gt 3) IDL prints 1
  • gt print, (1 gt 2) or (1 gt 3) IDL prints 0
  • - not Boolean inverse operator
  • - xor boolean exclusive or function. Only good
    for certain data types.
  • Just about any logic making steps you need can
    be made with ifs ors and ands.
Write a Comment
User Comments (0)
About PowerShow.com