Download presentation
Presentation is loading. Please wait.
1
Programming Cheng-Ling Kuo johnny@phys.ncku.edu.tw
2
Review - programming Interpreted and Interactive language, which is Similar to C or Fortran language Character: comment(;) delimiter(,) linking multi-lines(&) Avoid IF and use GT, >, or WHERE Use IDL ’ s function and procedure(TOTAL, WHERE) Use array operation rather than loops
3
Review- general operator Grouping of expressions Assignment Addition & string concatenation Subtraction & unary negation Multiplication Division Exponentiation Minimum of (Careful!) Maximum of (Careful!) Matrix multiplication Modulus (remainder) Array concatenation Conditional expression ( ) = + - * / ^ < > # MOD [ ] ?
4
Other Operators Relation operators: EQ, LE, LT, GT, GE Flase(0), True(1) Boolean operators
5
How to start a procedure PRO hello name = "" read, "input a name:", name print, "hello, ", name END Save(ctl-S), Compile and Start IDL> input a name: IDL> hello, johnny
6
Create your own command PRO hello, name ;name = "" ;read, "input a name:", name print, "hello, ", name END Use your command 1. Compile: or IDL>.compile hello 2. start IDL>hello, “ johnny ” hello, johnny
7
Executive command.compile IDL>.COMPILE "E:\code\IDL\test\hello.pro“ or IDL>.COMPILE hello retall As compiling error.
8
Batch, procedure, function x=[10,30,90] PRINT, x PLOT, x @batchfile END FUNCTION f x=[10,30,90] PRINT, x PLOT, x RETURN, x.compile f res = f() PRO P END x=[10,30,90] PRINT, x PLOT, x.compile p P
9
Procedure definition PRO procedure_name, param 1, param 2, keyword 1 =keyword 1, … statements END Statement is required: PRO, END Parameters are positional or keyword RETURN is optional Example PRO hello, name print, “hello, ”, name END
10
Procedure call PROCEDURE_NAME, p 1, p 2,..., p n Invoke a system or user written procedure Example user written function IDL>hello, “ Ted ” System procedure IDL>plot, [0, 1]
11
Function definition FUNCTION function_name, param 1, param 2, keyword 1 =keyword 1, … statements return, value_expression END Statement is required: FUNCTION, END Parameters are positional or keyword RETURN is required A function has no data type Example function myadd, a, b return, a+b END
12
Function Call var = FUNCTION_NAME(p 1, p 2, …) Invoke a system or user written function Example user written function IDL> v = myadd, 1, 2 IDL> print, v System function IDL> v = TOTAL([1,2,3]) IDL> print, v
13
Parameter: positional & keyword Positional Input by parameter position Copy in & out - Call by reference Keyword Input by keyword string Call by reference
14
Parameter: Call by reference Positional Input by parameter position Copy in & out - Call by reference PRO test, a, b=b a=-1 b=-1 END IDL>r=100 & s=100 IDL>test, r, b=s IDL>print, r, s (variable changed!)
15
Parameter passing By value Expression: a+0 Constants: 100.25 Subscripted variables: m(10) Structure tag refercnce: s.tag By reference Regular variables: a, b, c
16
Checking parameters N_params(): return numbers of paramerters Keyword_set(): return true or false Size(): return type and size of parameters or variables
17
Common block COMMON Block_Name, Variable1, Variable2,..., Variablen Def: creates a common block with the designated name and places the variables whose names follow into that block. Example PRO ADD, A COMMON SHARE1, X, Y, Z, Q, R A = X + Y + Z + Q + R PRINT, X, Y, Z, Q, R, A RETURN END PRO SUB, T COMMON SHARE1, A, B, C, D T = A - B - C - D PRINT, A, B, C, D, T RETURN END
18
pro suba common share, a, b, c, d a=1 b=2 c=3 d=4 print, "the sum is ", a+b+c+d end Common block(Example) pro main suba subb subc end Common share A, B, C, D pro subb common share, p, q, r, s print, "p=", p print, "q=", q print, "r=", r print, "s=", s p=100 end pro subc common share, a, b, c, d print, "the sum is ", a+b+c+d end
19
“ String ” family String() Strlen() Strtrim() Strcompress() Strlowcase() Strupcase() Strpos() Strmid() Strput()
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.