Download 2D Visualization

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Programming
Cheng-Ling Kuo
[email protected]
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
Review- general operator
()
=
+
*
/
^
<
>
#
MOD
[]
?
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
Other Operators
Relation operators: EQ, LE, LT, GT, GE
Flase(0), True(1)
Boolean operators
AND
OR
XOR
TT
T
T
F
TF
F
T
T
FF
F
F
F
How to start a procedure
PRO hello
name = ""
read, "input a name:", name
print, "hello, ", name
END
Save(ctl-S), Compile
IDL>input a name:
IDL> hello, johnny
and Start
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
Executive command
.compile
IDL> .COMPILE "E:\code\IDL\test\hello.pro“
or
IDL> .COMPILE hello
retall
As compiling error.
Batch, procedure, function
PRO P
FUNCTION
f
x=[10,30,90]
x=[10,30,90]
x=[10,30,90]
PRINT, x
PRINT, x
PLOT, x
PRINT, x
PLOT, x
PLOT, x
END
@batchfile
.compile p
P
RETURN, x
END
.compile f
res = f()
Procedure definition
PRO procedure_name, param1, param2, keyword1=keyword1,
statements
END
Statement is required: PRO, END
Parameters are positional or keyword
RETURN is optional
Example
PRO hello, name
print, “hello, ”, name
END
…
Procedure call
PROCEDURE_NAME, p1, p2, ..., pn
Invoke a system or user written
procedure
Example

user written function
IDL>hello, “Ted”

System procedure
IDL>plot, [0, 1]
Function definition
FUNCTION function_name, param1, param2, keyword1=keyword1,
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
…
Function Call
var = FUNCTION_NAME(p1, p2, …)
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
Parameter: positional & keyword
Positional


Input by parameter position
Copy in & out - Call by reference
Keyword


Input by keyword string
Call by reference
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
-1 -1
(variable changed!)
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
Checking parameters
N_params(): return numbers of
paramerters
Keyword_set(): return true or false
Size(): return type and size of
parameters or variables
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
Common block(Example)
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
pro subb
common share, p, q, r, s
print, "p=", p
print, "q=", q
print, "r=", r
pro subc
print, "s=", s
common share, a, b, c, d
p=100
print, "the sum is ", a+b+c+d
end
end
Common share
A, B, C, D
pro main
suba
subb
subc
end
“String” family
String()
Strlen()
Strtrim()
Strcompress()
Strlowcase()
Strupcase()
Strpos()
Strmid()
Strput()
Related documents